4

I'm writing in AT&T syntax. This loop should check, if case is in range 61-7A ASCII (it means is this small letter) - if no, then convert it into 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 loop. ESI is my pointer to string.

My problem is simple - this is not working, and I have no idea why.

fuz
  • 88,405
  • 25
  • 200
  • 352
DzikiChrzan
  • 2,747
  • 2
  • 15
  • 22
  • Where's your `nic` label defined? You can also just say `inc %esi` instead of `addl $1, %esi`. Saves a few instruction bytes/cycles. :) – lurker Apr 19 '15 at 18:28
  • My mistake, sorry - nic means 'nothing', I translated this from Polish and forgot to change. – DzikiChrzan Apr 19 '15 at 18:30

1 Answers1

4

The first conditional jump is wrong!

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
Sep Roland
  • 33,889
  • 7
  • 43
  • 76