do yeon
2010-07-21 02:43:02 UTC
hello. I am learning assembly. but I have a problem in linux
i wrote code.
--------------------------
.section .data
.section .text
.globl _start
_start:
pushl $6
call factorial
movl %eax, %ebx
movl $1, %eax
int $0x80
.type factorial, @function
factorial:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %ebx
movl 8(%ebp), %ecx
start_loop:
cmpl $1, %ebx
je end_loop
decl %ebx
imull %ebx, %ecx
jmp start_loop
end_loop:
movl %ecx, %eax
movl %ebp, %esp
popl %ebp
ret
-----------------------
and I do 'echo $?' in shell.
i expected the out number is 720. but 208! so, i use debug program.
I traced the program and at the end of the program the result is this.
(gdb) info registers
eax 0x1 1
ecx 0x2d0 720
edx 0x0 0
ebx 0x2d0 720
esp 0xbffff54c 0xbffff54c
ebp 0x0 0x0
esi 0x0 0
edi 0x0 0
eip 0x8048062 0x8048062 <_start+14>
eflags 0x246 [ PF ZF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x0 0
(gdb) stepi
Program exited with code 0320.
(gdb) info registers
The program has no registers now.
(gdb) quit
-----------------------------------
as you see
==============
ebx 0x2d0 720
==============
ebx is 720
so, if {(%eax = 1 ) and int $0x80, `echo $?` == %ebx}, why the output
is 208??
i wrote code.
--------------------------
.section .data
.section .text
.globl _start
_start:
pushl $6
call factorial
movl %eax, %ebx
movl $1, %eax
int $0x80
.type factorial, @function
factorial:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %ebx
movl 8(%ebp), %ecx
start_loop:
cmpl $1, %ebx
je end_loop
decl %ebx
imull %ebx, %ecx
jmp start_loop
end_loop:
movl %ecx, %eax
movl %ebp, %esp
popl %ebp
ret
-----------------------
and I do 'echo $?' in shell.
i expected the out number is 720. but 208! so, i use debug program.
I traced the program and at the end of the program the result is this.
(gdb) info registers
eax 0x1 1
ecx 0x2d0 720
edx 0x0 0
ebx 0x2d0 720
esp 0xbffff54c 0xbffff54c
ebp 0x0 0x0
esi 0x0 0
edi 0x0 0
eip 0x8048062 0x8048062 <_start+14>
eflags 0x246 [ PF ZF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x0 0
(gdb) stepi
Program exited with code 0320.
(gdb) info registers
The program has no registers now.
(gdb) quit
-----------------------------------
as you see
==============
ebx 0x2d0 720
==============
ebx is 720
so, if {(%eax = 1 ) and int $0x80, `echo $?` == %ebx}, why the output
is 208??