2016-05-22 1 views
1

私は愚かな構文の質問に私を許してくださいが、私は2つの変数(四角形と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

ありがとう!なぜ私はそんなに苦労していたのか分かりません –

関連する問題