Attempting to convert an if statement to assembly

Posted by Malfist on Stack Overflow See other posts from Stack Overflow or by Malfist
Published on 2010-04-27T01:02:07Z Indexed on 2010/04/27 1:03 UTC
Read the original article Hit count: 362

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about masm

Related posts about assembly