尝试将 if 语句转换为程序集

发布于 2024-08-30 21:56:31 字数 994 浏览 3 评论 0原文

我做错了什么?

这是我写的汇编:

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;
}

它似乎将不是 y,z,Y,Z 的每个字符转换为等价的加 2,而不仅仅是A-Xa-x。有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陪你到最终 2024-09-06 21:56:31

jl 是有符号比较。

jl is a signed comparison.

谎言月老 2024-09-06 21:56:31

我认为应该

sub cl, '6'

sub cl, 6

相反的,你说有“6”-> 0x36-> “Z”和“a”之间有 54 个字符。

I think that

sub cl, '6'

should be

sub cl, 6

otherwise, you are stating that there are '6' -> 0x36 -> 54 characters between 'Z' and 'a'.

却一份温柔 2024-09-06 21:56:31

对于无符号比较,您需要“jb”而不是“jl”。

For an unsigned comparison, you need 'jb' instead of 'jl'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文