Assembly - changing housing

I write AT & T syntax. This loop should be checked if the register is in the range 61-7A ASCII (this means that it is a small letter) - if not, then convert it to space '.

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

This is my cycle. ESI is my string pointer.

My problem is simple - it does not work, and I have no idea why.

+4
source share
1 answer

The first conditional jump is incorrect!

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
+4
source

All Articles