-1

我对c语言比较熟悉,但是我们如何将下面的c语言编码写成汇编语言呢?我试过但总是失败。

if(a==4)
{
   routine1();
}
else if(a==5)
{
    routine2();
}
else if(a==6)
{
    routine3();
}
4

2 回答 2

2

一种可能性是使用 重写它goto,然后它应该直接移植到您使用的任何 asm 语言。

if (a != 4) goto not4;
routine1();
goto end;

not4: if (a != 5) goto not5;
routine2();
goto end;

not5: if (a != 6) goto not6;
routine3();
end:
于 2012-11-08T14:19:46.140 回答
0

在 x86 中,它会是这样的,还请查看链接以深入描述命令 http://www.gabrielececchetti.it/Teaching/CalcolatoriElettronici/Docs/i8086_instruction_set.pdf

a100 
mov al, 0500;move whats in memory location 0500 to al register
mov bl,4; mov 4 into bl register
cmp al,bl;this compares them basically subtracting them so 0 is equal
jz label1;the label is another memory location that you would jump to if they are equal
mov bl,5; if it doesnt jump then the code will continue to run
cmp al,bl
jz label2
mov bl,6
cmp al,bl
jz label3
int 3; to end program or you can use ret 

...

label1 call 0200;call instruction runs the code that is at the memory location stated
label2 call 0300
label3 call 0400

希望这会有所帮助并记住这是 x86 !编码快乐!!

于 2012-11-08T15:07:25.020 回答