【发布时间】:2013-05-25 14:47:53
【问题描述】:
我需要使用 gasm 计算字符串中的空格数。所以,我用简单的程序写了,但是比较不起作用。
.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
所以,这个字符串cmpl $32,str(,%ecx,1) 的问题在那里我尝试将空间(ASCII 中的 32)与 str 的 1 个字节(我使用 %ecx 作为位移计数器,并占用 1 个字节)进行比较。不幸的是,我在 Internet 上没有找到任何关于 Gasm 中符号比较的示例。我尝试使用 gcc 生成的代码,但我无法理解和使用它。
【问题讨论】: