Attempting to convert an if statement to assembly
- by Malfist
What am I doing wrong?
This is the assmebly I've written:
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
}
}
and this is the C code it's supposed to replace, but doesn't
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;
}
It seems to convert every character that isn't an y,z,Y,Z into a plus 2 equivalent instead of just A-Xa-x. Any ideas why?