汇编语言--冒泡排序

<span style="font-size:24px;">我就直接上代码了。思想和c语言的是一样的,冒泡排序使用双重循环来实现,进入内层循环时需要先将cx的内容保存,等内层循环结束后再恢复内容。具体的思想,代码注释写的很清楚,亲测可以使用。</span>
<span style="font-size:24px;">
</span>
<span style="font-size:24px;">ps:本程序实现的是用户输入10个数据,然后程序排序后输出。</span>
data segment
	s1 db 10 dup(?)
data ends
code segment
	assume cs:code,ds:data;确定cs/ds指向的逻辑段
start:
		mov ax,data
		mov ds,ax	;设置数据段的段地址ds
		mov si,offset s1
		mov cx,10
		mov ah,01h
l1:						;用户输入数据
		int 21h
		mov [si],al
		inc si
		loop l1

		mov ah,2h		;输出回车换行
		mov dl,0dh
		int 21h
		mov dl,0ah
		int 21h

		mov cx,9
l2:		
		mov bx,cx		;将cx的内容保存至bx
		mov si,0

l3:
		mov al,s1[si]
		cmp s1[si+1],al		;比较大小
		jge l4			;如果大于等于就交换
		xchg s1[si+1],al	;交换数据
		mov s1[si],al

l4:
		inc si
		loop l3

		mov cx,bx	;恢复外层循环的cx
		loop l2
		mov cx,10
		mov si,0
		mov ah,2

l5:				;输出排序后的数组
		mov dl,s1[si]
		int 21h
		inc si
		loop l5

		mov ax,4c00h
		int 21h
code ends
		end start

code ends

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://my.oschina.net/u/2516450/blog/531754

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值