2023-11-13 08:56来源:m.sf1369.com作者:宇宇
assume cs:code,ds:data
data segment
db 11h,10h ;两个内存相邻的字节
data ends
code segment
start:
mov ax,data
mov ds,ax
mov ah,ds:[0] ;将和源11h放入
mov al,ds:[1] ;将10h放入
mov cx,1
;设置死循环不停比较,也可自己设置cx值改变循环次数
s:
inc cx
call s0 ;调用子程序s0
loop s
mov ax, 4c00h
int 21h
;子程序
s0:
cmp ah,al ;比较低地址和高地址斗旅的数唤销态
je s1 ;等于就返回
jb s1 ; 小于就返回,不必交换
;不是上面两个结果就是大于,就交换高低地址
mov ds:[0],al
mov ds:[1],ah
s1:
ret ;返回继续循环
code ends
end start
CODE SEGMENT
ASSUME CS:CODE
BUF DB 99,87,56,09,78,32,87,43,123,234
START: PUSH CS
POP DS
PUSH CS
POP ES
LEA SI,BUF
INC SI
INC SI
CALL SWAP
MOV AL,[SI]
; CBW
CALL DSPAL
MOV AH,4CH
INT 21H
;==================================
SWAP PROC NEAR
MOV AL,[SI]
CMP AL,[SI+1]
JBE @1
XCHG AL,[SI+1]
MOV [SI],AL
@1:
RET
SWAP ENDP
;===============================
DSPAL PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSHF
XOR AH,AH
XOR CX,CX
MOV BL,10
@DSPAL1:
DIV BL
INC CX
MOV DL,AH
XOR AH,AH
OR DX,30H
PUSH DX
CMP AL,0
JNE @DSPAL1
MOV AH,2
@DISPAL2:
POP DX
INT 21H
LOOP @DISPAL2
MOV DL,32
INT 21H
POPF
POP DX
POP CX
POP BX
POP AX
RET
DSPAL ENDP
;==================================
CODE ENDS
END START