【发布时间】:2014-02-14 03:41:14
【问题描述】:
我正在尝试编写一个简短的汇编程序来比较 2 个字符串。我正在使用 AT&T 语法 并用 gcc 和 -m32 标志组装我的程序。
当我运行代码时,我总是在提示时输入“矩形”。
我编写了以下代码。使用有问题的代码块(包含在 cmets 中) 激活,如果我在提示时输入“矩形”,程序不会打印“您输入了矩形”。 事实上,程序在第一次迭代时就跳出了循环。 如果我注释掉所述代码块,程序确实打印“你输入了矩形”。从此 代码块只打印%eax和%ebx中的值,为什么会影响跳转条件?
.section .data
format:
.asciz "%s"
test_str:
.asciz "\n%c%c"
equal_str:
.asciz "You entered rectangle"
rectangle:
.asciz "rectangle"
.section .bss
.lcomm element, 100
.section .text
.globl main
main:
pushl $element
pushl $format
call scanf
addl $8, %esp
movl $0, %edi
loop:
movb element(,%edi,1), %al
movb rectangle(,%edi,1), %bl
#BEGIN QUESTIONABLE BLOCK
pushl %eax
pushl %ebx
pushl $test_str
call printf
addl $8, %esp
#END QUESTIONABLE BLOCK
cmpb %al, %bl
jne end
incl %edi
cmpb $0, %al
jne loop
pushl $equal_str
call printf
addl $4, %esp
jmp end
end:
call exit
我想以下信息都不重要,但我真的不知道什么会或不会影响组装,所以我的 CPU 是 Intel Xeon E5-2650,我使用的是 CentOS 6.5。提前致谢!
【问题讨论】:
标签: string assembly compare att