我在做什麼錯了?試圖將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。任何想法爲什麼?
僅供參考 - 您的原始C代碼重複檢查'y',但缺少'Z'檢查。 – 2010-04-27 03:25:59