2012-11-08 118 views
-1

我對c語言更加熟悉,但我們如何將以下c語言編碼寫入彙編語言?我試過但總是失敗。關於彙編語言條件選擇

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

哪種彙編語言? – harold

回答

2

一種可能性是使用goto重寫它,那麼它應該是直截了當地移植到你使用任何語言彙編。

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: 
0

在86它會是這樣的命令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! 快樂編碼!