【发布时间】:2011-07-09 22:26:47
【问题描述】:
我以前用 TASM(在 winXP 上)编译我的 asm 代码,但我遇到了一些麻烦,所以现在我使用 NASM(在 linux 上)。这个 sn-p 显示了我正在尝试做的事情:
(gdb) list 35
30 xor ecx,ecx # ecx is a counter
31 mov bl, ' ' # this is what I'm looking for
32 count_spaces:
33 mov al,[esi] # grab a char
34 jz spaces_counted # is this the end?
35 inc esi # next char
36 cmp al,bl # found one?
37 jne count_spaces # nope, loop
38 inc ecx # yep, inc counter
39 jmp count_spaces # and loop
这在我看来是正确的,但是:
Breakpoint 1, main () at project1.asm:30
30 xor ecx,ecx
(gdb) display (char) $al
1: (char) $al = 0 '\000'
(gdb) display (char) $bl
2: (char) $bl = 0 '\000'
(gdb) next
31 mov bl, ' '
2: (char) $bl = 0 '\000'
1: (char) $al = 0 '\000'
(gdb)
count_spaces () at project1.asm:33
33 mov al,[esi]
2: (char) $bl = 0 '\000'
1: (char) $al = 0 '\000'
(gdb)
我不明白为什么 al 和 bl 没有改变。
我确定我的代码是正确的,但是.. 我想我错过了一些 NASM 的选项?
顺便说一句,我用
nasm -f elf -l project1.lst -o project1.o -i../include/ -g project1.asm
编译后反汇编输出得到:
80483ec: 31 c9 xor %ecx,%ecx
80483ee: bb 20 00 00 00 mov $0x20,%ebx
080483f3 <count_spaces>:
80483f3: 8b 06 mov (%esi),%eax
80483f5: 3d 00 00 00 00 cmp $0x0,%eax
80483fa: 74 0b je 8048407 <spaces_counted>
80483fc: 46 inc %esi
80483fd: 39 d8 cmp %ebx,%eax
80483ff: 75 f2 jne 80483f3 <count_spaces>
8048401: 41 inc %ecx
8048402: e9 ec ff ff ff jmp 80483f3 <count_spaces>
【问题讨论】:
-
我需要懂意大利语(大概)才能理解你的变量名吗?
-
@Armen Tsirunyan: ups,我完全忘记了。 :) 已编辑
-
请注意,gdb 会在执行它们之前显示指令,因此您需要“stepi”或“next”来执行显示的指令。不过,bl 的值应该已经改变了。