2013-03-05 50 views
1

我試圖在NASM裝配小乒乓遊戲(這就是我的語言學習:)的方式) ,但我有一個問題,我不能訪問列表大會:訪問二維數組

的任何項目

我的代碼

mov eax,counter     ;counter=2 double checked 
mov esi,bitmap_data+eax*4  ;copy the 2nd item of the array in to esi 

位圖數據是in.bss部分

bitmap_data: resd 100 

試圖

mov eax,2       
mov esi,[bitmap_data+eax*4]  ;copy the 2nd item of the array in to esi 

這不是在ESI保存列表的正確(下篇)元素,而以下是這樣做的權利

mov esi,[bitmap_data+2*4]  

,但我需要能夠改變的項目是我被利用可變

+1

「這不是在esi中保存正確的(第2個)元素」那麼它保存哪個元素呢?啓動一個調試器(Ollydbg,gdb,Visual Studio調試器,或任何您喜歡的)並逐步執行代碼可能是一個好主意。 – Michael 2013-03-05 17:43:23

回答

0

獲得包含在方括號的內存訪問,像這樣:

mov esi,[bitmap_data+eax*4] 

這應該使彙編程序感到高興。

更新,根據您的更新: 嘗試打破你的指示了一下。試試:

mov eax, counter 
shl eax, 2 
add eax, bitmap_data 
mov esi, [eax] 

有沒有變化?

+0

好吧,錯誤停止了,但它仍然沒有將數組的正確元素保存到esi – SteveL 2013-03-05 17:33:59

0

什麼是counter?很有可能你想:

mov eax, [counter] 
mov esi, [bitmap_data + eax * 4] 

「第一」(零)數組中的項目將顯示當eax = 0時eax = 2,你會得到數組中的「第三」項目。你在找哪一個?