- 论坛徽章:
- 0
|
小弟最近在学linux下汇编语言,可是在汇编中调用C库函数确出现了问题。gdb调试后,发现是在进入第10行的jmp done语句中的printf时,输出是死循环,不断的输出数字。小弟百思不得其解,望大虾能不吝赐教,万分感激。
1 .section .data
2 output:
3 .asciz "%d "
4 .section .text
5 .globl main
6 main:
7 nop
8 movl $28 , %ecx
9 movl $1 , %ebx
10 jmp done
11 movl $1 , %eax
12 jmp done
13 done:
14 pushl %ebx
15 pushl $output
16 call printf
17 loop1:
18 movl %ebx , %edx
19 addl %eax , %ebx
20 movl %edx , %eax
21 jmp done
22 loop loop1
23 movl $1 , %eax
24 movl $2 , %ebx
25 int $0x80
调试过程如下:
(gdb) b * main+1
Breakpoint 1 at 0x80483c5: file fibonacci.s, line 8.
(gdb) run
Starting program: /home/chunlun/Test/s/fibonacci
Breakpoint 1, main () at fibonacci.s:8
8 movl $28 , %ecx
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.7.el6.i686
(gdb) s
9 movl $1 , %ebx
(gdb) p $ecx
$1 = 28
(gdb) s
10 jmp done
(gdb) p $ecx
$2 = 28
(gdb) s
done () at fibonacci.s:14
14 pushl %ebx
(gdb) p $ecx
$3 = 28
(gdb) s
15 pushl $output
(gdb) p ecx
No symbol "ecx" in current context.
(gdb) p $ecx
$4 = 28
(gdb) s
done () at fibonacci.s:16
16 call printf
(gdb) p $ecx
$5 = 28
(gdb) s
1 4 7 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 107 112 117 122 127 132 137 142 147 152 157 162 167 172 177 182 187 192 197 202 207 212 217 222 227 232 237 242 247 252 257 262 267 272 277 282 287 292 297 302 307 312 317 322 327 332 337 342 347 352 357 362 367 372 377 382 387 392 397 402 407 412 …………
从调试结果看,%ecx并没有被覆写。 |
|