2016-05-22 34 views
1

請原諒我一個愚蠢的語法問題,但我有兩個變量(正方形和horizCharsPerSquare),我試圖設置ecx等於square/horizCharsPerSquare。我已經試過:你如何在組件中劃分一個註冊表?

mov ecx, squares/horizCharsPerSquare 

mov ecx squares 
    div horizCharsPerSquare 

mov ecx, squares 
    shr ecx, horizCharsPerSquare ;//(I know there are other issues with this, I was just giving it a shot 

而且不管是什麼,我得到一個錯誤?我得到的構建錯誤都是「不變的」。任何建議我應該如何做到這一點?

+0

https://www.youtube.com/watch?v=ieuUHIWaIqM&index=19&list=PL0C5C980A28FEE68D 7:15 – ABuckau

+2

'mov ecx,squares/horizCharsPerSquare'如果這些都是組裝時間常數,它們將會起作用。右移是正確的選擇,如果'horizCharsPerSquare'是2的冪。'mov ecx squares'會組裝,但這是[不怎麼'div'工作](http://www.felixcloutier.com/x86/DIV的.html)。另請參閱[x86標記wiki](http://stackoverflow.com/tags/x86/info)。 –

回答

2

由於兩個廣場horizCharsPerSquare是變量,通常你會在他們進行算術運算之前將其移動到寄存器。 這裏只有第一變量需要被移動到一個寄存器,因爲div指令確實允許一個存儲器操作數:

mov eax, squares 
xor edx, edx 
div horizCharsPerSquare ;Divide EDX:EAX by the dword variable 
mov ecx, eax    ;Put quotient in ECX 
+0

謝謝!我不知道爲什麼我會遇到那麼多麻煩 –