装配 - 改变案例

时间:2015-04-19 18:22:57

标签: assembly att i386

我正在用AT& T语法编写。 这个循环应检查,如果大小写在61-7A范围内(这意味着这是一个小写字母) - 如果不是,则将其转换为空格''。

change:
    movb (%esi), %bh        #move case temporary to bh register
    cmp $0x61,%bh           #compare 'a' ASCII and case from bh register
    jge nothing             #if ascii from bh is greater than 'a', jump to nothing
    cmp $0x7A,%bh
    jle nothing             #same, if is in range 61-7A jump to nothing
    movb $0x20,%bh          #if wasn't in range, change to 20 ASCII (space)
nothing:
    movb %bh, (%esi)        #put case back into string
    addl $1,%esi            #move pointer to the next case
    loop change

这是我的循环。 ESI是我指向字符串的指针。

我的问题很简单 - 这不起作用,我不明白为什么。

1 个答案:

答案 0 :(得分:4)

第一次条件跳转是错误的!

change:
    movb (%esi), %bh        #move case temporary to bh register
    cmp $0x61,%bh           #compare 'a' ASCII and case from bh register
    jl space             #if ascii from bh is greater than 'a', jump to nothing
    cmp $0x7A,%bh
    jle nothing             #same, if is in range 61-7A jump to nothing
space: 
   movb $0x20,%bh          #if wasn't in range, change to 20 ASCII (space)
nothing:
    movb %bh, (%esi)        #put case back into string
    addl $1,%esi            #move pointer to the next case
    loop change