汇编语言,冒泡

yu1300429115 2018-10-16 09:12:53
怎么用汇编语言写冒泡程序,要求,随机输出(不限于个位数:),比较后输出
...全文
701 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
西北狼人 2018-12-01
  • 打赏
  • 举报
回复
正在学习中 支持LZ
  • 打赏
  • 举报
回复
这一看就是C输出的汇编代码,手写汇编的数组初始化没人这么写:
movl $8, -40(%ebp)
movl $3, -36(%ebp)
movl $12, -32(%ebp)
...
xiaoji0507 2018-11-27
  • 打赏
  • 举报
回复

.section .text

.type display, @function
fmt:
.string "%d "

newline:
.string "\n"

display:
pushl %ebp
movl %esp, %ebp

movl $1, %ebx

LDISPLAY1:
cmpl %ebx, 12(%ebp)
jl RETURN

movl 8(%ebp), %esi
pushl (%esi, %ebx, 4)
pushl $fmt
call printf
incl %ebx
jmp LDISPLAY1

RETURN:
pushl $newline
call printf

movl %ebp, %esp
popl %ebp
ret

.type bubble_sort, @function
bubble_sort:
pushl %ebp
movl %esp, %ebp

movl $1, %eax
movl 12(%ebp), %edi

L1:
cmpl %eax, 12(%ebp)
jae L2
movl %ebp, %esp
popl %ebp
ret

L2:
movl %eax, %ebx
addl $1, %ebx

L3:
cmpl %ebx, 12(%ebp)
jae COMPARE
incl %eax
jmp L1

COMPARE:
movl 8(%ebp), %esi
movl (%esi, %eax, 4), %ecx
movl (%esi, %ebx, 4), %edx
cmpl %ecx, %edx

jl L4
incl %ebx
jmp L3

L4:
movl %edx, (%esi, %eax, 4)
movl %ecx, (%esi, %ebx, 4)
incl %ebx
jmp L3


.global _start

_start:
pushl %ebp
movl %esp, %ebp
subl $40, %esp
movl $8, -40(%ebp)
movl $3, -36(%ebp)
movl $12, -32(%ebp)
movl $32, -28(%ebp)
movl $43, -24(%ebp)
movl $9, -20(%ebp)
movl $7, -16(%ebp)
movl $20, -12(%ebp)
movl $19, -8(%ebp)
movl $70, -4(%ebp)
pushl -40(%ebp)


leal -44(%ebp), %eax
pushl $10
pushl %eax
call display
addl $8, %esp

leal -44(%ebp), %eax
pushl $10
pushl %eax
call bubble_sort
addl $8, %esp

leal -44(%ebp), %eax
pushl $10
pushl %eax
call display

movl %ebp, %esp
popl %ebp

movl $1, %eax
movl $0, %ebx
int $0x80
grey_Jokid 2018-11-25
  • 打赏
  • 举报
回复
这个在其他人的帖子里有很多吧。。。
leetow2006 2018-11-17
  • 打赏
  • 举报
回复
这个程序用汇编写?太厉害了,哪里有源码?
  • 打赏
  • 举报
回复
推荐里就有,虽然只是16位代码

21,497

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧