汇编------双向循环链表
作者:互联网
.section .rodata
.LC0:.string "%d "
//struct node
//{
// int value;
// struct node *pre;
// struct node *next;
//}
//
//
//struct list
//{
// struct node nod;
// int count;
//}
.section .text
//void init(struct list *ls);
init:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
movl $0,(%eax)
movl %eax,4(%eax)
movl %eax,8(%eax)
movl $0,12(%eax)
movl %ebp,%esp
popl %ebp
ret
//void add(struct list *ls,int val)
add:
pushl %ebp
movl %esp,%ebp
pushl $12
call malloc
addl $4,%esp
movl 12(%ebp),%ecx
movl %ecx,(%eax)
movl 8(%ebp),%ecx
movl 4(%ecx),%edx
// edx eax ecx
movl %edx,4(%eax)
movl %ecx,8(%eax)
movl %eax,4(%ecx)
movl %eax,8(%edx)
addl $1,16(%eax)
movl %ebp,%esp
popl %ebp
ret
//void print(list *ls)
print:
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
movl 8(%ebp),%eax
movl %eax,%esi
movl 8(%eax),%edi
jmp .L1
.L2:
pushl (%edi)
pushl $.LC0
call printf
addl $8,%esp
movl 8(%edi),%edi
.L1:
cmpl %esi,%edi
jne .L2
pushl $'\n'
call putchar
addl $4,%esp
popl %edi
popl %esi
movl %ebp,%esp
popl %ebp
ret
//struct node *get(list *ls,int idx)
get:
pushl %ebp
movl %esp,%ebp
movl 12(%ebp),%eax
movl 8(%ebp),%edx
movl 12(%edx),%edx
cmpl $0,%eax
jl .L3
cmpl %edx,%eax
jge .L4
.L3:
pushl $1
call exit
.L4:
movl 8(%ebp),%eax
movl 8(%eax),%eax
movl 12(%ebp),%edx
jmp .L5
.L6:
movl 8(%eax),%eax
subl $1,%edx
.L5:
cmpl $0,%edx
jne .L6
movl %ebp,%esp
popl %ebp
ret
//void del(list *ls,int idx)
del:
pushl %ebp
movl %esp,%ebp
pushl %ebx
pushl 12(%ebp)
pushl 8(%ebp)
call get
addl $8,%esp
//ecx eax edx
movl 4(%eax),%ecx
movl 8(%eax),%edx
movl 8(%eax),%ebx
movl %ebx,8(%ecx)
movl 4(%eax),%ebx
movl %ebx,4(%edx)
movl 8(%ebp),%eax
subl $1,16(%eax)
popl %ebx
movl %ebp,%esp
popl %ebp
ret
.global main
main:
pushl %ebp
movl %esp,%ebp
subl $16,%esp
leal -16(%ebp),%eax
pushl %eax
call init
addl $4,%esp
pushl $11
leal -16(%ebp),%eax
pushl %eax
call add
addl $8,%esp
pushl $22
leal -16(%ebp),%eax
pushl %eax
call add
addl $8,%esp
pushl $33
leal -16(%ebp),%eax
pushl %eax
call add
addl $8,%esp
pushl $2
leal -16(%ebp),%eax
pushl %eax
call del
addl $8,%esp
leal -16(%ebp),%eax
pushl %eax
call print
addl $4,%esp
movl %ebp,%esp
popl %ebp
ret
标签:汇编,movl,esp,链表,eax,ebp,------,edx,pushl 来源: https://blog.csdn.net/pk_20140716/article/details/115322342