2

I need to count amount of spaces in string using gasm. So, I have written with simple program, but comparison doesn't work.

.section .data
  str:
    .string " TEst   string wit h spaces   \n"

.section .text
.globl _start
_start:

movl $0,%eax # %eax - amount of spaces
movl $0,%ecx # Starting our counter with zero

loop_start:
  cmpl $32,str(,%ecx,1)  # Comparison (this is never true)
  jne sp
  incl %eax # Programm never goes there
  incl %ecx
  jmp loop_start
sp:
  cmpl $0X0A,str(,%ecx,1) #Comparison for the end of string
  je loop_end #Leaving loop if it is the end of string
  incl %ecx
  jmp loop_start
loop_end:
  movl (%eax),%ecx  # Writing amount of spaces to %ecx
  movl $4,%eax
  movl $1,%ebx
  movl $2,%edx
  int $0x80

  movl $1,%eax
  movl $0,%ebx
  int $0x80

So, problem in this string cmpl $32,str(,%ecx,1) There I try to compare space (32 in ASCII) with 1 byte of str (I use %ecx as a counter for displacement, and took 1 byte). Unfortunately, I haven't found any example in Internet about symbol comparison in Gasm. I've tried to use gcc generated code, but I can't understand and use it.

4

1 に答える 1