# jmp.s
.section .text
.globl _start
_start:
nop
movl $1, %eax
jmp gotohere
movl $10, %ebx
int $0x80
gotohere:
movl $20, %ebx
int $0x80
$ make as -o jmp.o jmp.s --gstabs ld -o jmp jmp.o $ ./jmp $ echo $? 20
(gdb) b *_start Breakpoint 1 at 0x8048054: file jmp.s, line 5. (gdb) r Starting program: /home/allen/as/4_jmp/jmp Breakpoint 1, _start () at jmp.s:5 5 nop (gdb) s 6 movl $1, %eax (gdb) s 7 jmp gotohere (gdb) s 11 movl $20, %ebx (gdb) s 12 int $0x80 (gdb) s Program exited with code 024. (gdb)
$ as -o jmp.o jmp.s $ ld -o jmp jmp.o $ objdump -D jmp jmp: file format elf32-i386 Disassembly of section .text: 08048054 <_start>: 8048054: 90 nop 8048055: b8 01 00 00 00 mov $0x1,%eax 804805a: eb 07 jmp 8048063 <gotohere> 804805c: bb 0a 00 00 00 mov $0xa,%ebx 8048061: cd 80 int $0x80 08048063 <gotohere>: 8048063: bb 14 00 00 00 mov $0x14,%ebx 8048068: cd 80 int $0x80
Breakpoint 1, _start () at jmp.s:5 5 nop (gdb) n 6 movl $1, %eax (gdb) n 7 jmp gotohere (gdb) print $eip $1 = (void (*)()) 0x804805a <_start+6> (gdb) n 11 movl $20, %ebx (gdb) print $eip $2 = (void (*)()) 0x8048063 <gotohere> (gdb)
func_lable:
push1 %ebp
movl %esp, %ebp
<function code here>
movl %ebp, %esp
popl %ebp
ret#call.s
.section .data
msg:
.asciz "this is as call test!\n"
len=.-msg
.section .text
.globl _start
_start:
nop
call output_func
movl $0, %ebx
movl $1, %eax
int $0x80
output_func:
pushl %ebp
movl %esp, %ebp
#<function code here>
movl $len, %edx
movl $msg, %ecx
movl $1, %ebx
movl $4, %eax
int $0x80
movl %ebp, %esp
popl %ebp
ret$ make as -o call.o call.s --gstabs ld -o call call.o $ ./call this is as call test! $
#cmp.s
.section .text
.globl _start
_start:
nop
movl $11, %eax
movl $24, %ebx
cmp %eax, %ebx
jae greater
movl $1, %eax
int $0x80
greater:
movl $11, %ebx
movl $1, %eax
int $0x80
$ make as -o cmp.o cmp.s --gstabs ld -o cmp cmp.o $ ./cmp $ echo $? 11
原文:http://blog.csdn.net/shallnet/article/details/45601949