我用來編譯(在WinXP)我用TASM彙編代碼,但我有一些麻煩所以現在我使用NASM(在Linux上)。該片段展示了我想要做的事:大會(或NASM)惱人的問題
(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的選擇嗎? BTW我
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>
我是否需要了解意大利語(大概)以瞭解您的變量名? – 2011-03-06 19:53:55
@Armen Tsirunyan:ups,我完全忘了那個。 :)編輯 – BlackBear 2011-03-06 19:57:49
請注意,gdb顯示指令__before__執行它們,所以你需要'stepi'或'next'來執行顯示的指令。但是,bl的價值應該已經改變了。 – BatchyX 2011-03-06 20:47:33