2010-04-27 60 views
1

我在做什麼錯了?試圖將if語句轉換爲程序集

這是我寫的assmebly:

char encode(char plain){ 
__asm{ 
    mov al, plain 

    ;check for y or z status 
    cmp al, 'y' 
    je YorZ 
    cmp al, 'z' 
    je YorZ 
    cmp al, 'Y' 
    je YorZ 
    cmp al, 'Z' 
    je YorZ 

    ;check to make sure it is in the alphabet now 
    mov cl, al 
    sub cl, 'A' 

    cmp cl, 24 
    jl Other 

    sub cl, '6' ;there are six characters between 'Z' and 'a' 

    cmp cl, 24 
    jl Other 
    jmp done ;means it is not in the alphabet 



YorZ: 
    sub al, 24 
    jmp done 

Other: 
    add al, 2 
    jmp done 

done: 
    leave 
    ret 
} 
} 

,這是C代碼它應該更換,但不

char encode(char plain){ 
char code; 
if((plain>='a' && plain<='x') || (plain>='A' && plain <='X')){ 
    code = plain+2; 
}else if(plain == 'y' || plain=='z' || plain=='Y' || plain == 'y'){ 
    code = plain - 24; 
}else{ 
    code = plain; 
} 

return code; 
} 

這似乎是每一個ISN字符轉換將y,z,Y,Z變成加2等價物而不僅僅是A-Xa-x。任何想法爲什麼?

+0

僅供參考 - 您的原始C代碼重複檢查'y',但缺少'Z'檢查。 – 2010-04-27 03:25:59

回答

2

jl是簽名比較。

+0

那我應該用什麼? – Malfist 2010-04-27 01:27:58

+0

ah-ha,jb是無符號的 – Malfist 2010-04-27 01:30:19

0

我認爲

sub cl, '6' 

應該

sub cl, 6 

否則,就表示有 '6' - > 0x36 - > 'Z' 和 'a' 之間的54個字符。

0

對於無符號比較,您需要'jb'而不是'jl'。