[英]MUL and XOR Assembly Instructions
inb4:是的,我之前看到過類似的問題,但分配的任務相同,但是我的略有不同。 好的,這是編碼任務,創建一個基本的計算器。 除了兩個:MUL和XOR,我已經完成了大多數功能。 實現了MUL,但是要獲得全部信用,我們需要在不使用實際MUL操作的情況下實現它。 環? 對於XOR函數,我只是略微降低了輸出。 寄存器未清除? 這是我第二周在intel匯編中進行編程,所以到此為止我幾乎一無所知。 不知道如何實現循環,因此一些可靠的幫助將非常有用。 謝謝這是C函數中的匯編代碼,需要一個運算符和兩個整數。
__asm
{
mov eax, 0; zero out the result
mov ebx, opcode; move opcode to ebx for comparison
cmp ebx, 0x01; check for ADD
jne sub_2;
mov eax, op1;
add eax, op2;
jmp done;
sub_2:
cmp ebx, 0x02;
jne mul_3;
mov eax, op1;
sub eax, op2;
jmp done;
mul_3:
cmp ebx, 0x03;
jne div_4;
mov eax, op1;
mul op2; //NOT supposed to use MUL
jmp done;
div_4:
cmp ebx, 0x04;
jne mod_5;
mov eax, op1;
cdq; //32bit number turns into 64bit for eax
idiv op2;
jmp done;
mod_5:
cmp ebx, 0x05;
jne and_6;
xor edx, edx; //Clear edx;
mov eax, op1;
cdq; //32bit to 64 for eax;
idiv op2;
mov eax, edx;
jmp done;
and_6:
cmp ebx, 0x06;
jne or_7;
xor edx, edx; //Clear edx
mov eax, op1;
and eax, op2;
jmp done;
or_7:
cmp ebx, 0x07;
jne xor_8;
xor edx, edx; //Clear edx
mov eax, op1;
xor eax, op2;
jmp done;
xor_8:
cmp ebx, 0x08;
jne fac_9;
xor edx, edx; //Clear edx
mov edx, op1;
xor eax, op2;
jmp done;
fac_9:
cmp ebx, 0x09;
jne done;
xor edx, edx; zero out the register
mov eax, op1;
cmp eax, 0;
mov ecx, op1;
DEC ecx;
mov ebx, 1;
L1:
mul ebx;
INC ebx;
LOOP L1;
jmp done;
done:
}
UL
mul_3:
cmp ebx, 0x03;
jne div_4;
mov edx, op1;
mov eax, 0;
mov ecx, op2;
test ecx, ecx;
jz done;
jns mul_add;
neg ecx;
neg edx;
mul_add:
add eax, edx;
loop mul_add;
jmp done;
異或
xor_8:
cmp ebx, 0x08;
jne fac_9;
xor edx, edx; //Clear edx
mov edx, op1;
mov eax, op2;
xor eax, edx;
jmp done;
PS自從我真正編寫了asm以來已經過去了幾十年,所以這可能不是最好的解決方案,但是您要求的是一些簡單的方法
編輯:固定MUL與帶符號的整數一起使用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.