问题描述
- 汇编语言习题求解给个答案,谢谢了
-
认真阅读以下代码,请判断该程序的功能及运算完成后数据区的数据排列。DATA SEGMENT
BUF DB 0AH,8F,15H,36H,0A6,20H,12H
N = $-BUFDATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
BEGIN: MOV AX,DATA
MOV DS,AX
MOV SI,1NEXT1: MOV DI,SI
INC DI
MOV AL,[BUF+SI-1]NEXT2: CMP AL,[BUF+DI-1]
JAE NEXT3
XCHG [BUF+DI-1],AL
MOV [BUF+SI-1],AL
NEXT3: INC DICMP DI,N
JBE NEXT2
INC SI
CMP SI,N-1
JBE NEXT1
MOV AH,4CH
INT 21H
CODE ENDS
END BEGIN
解决方案
;声明DATA段,声明常量数组BUF
DATA SEGMENT
BUF DB 0AH,8FH,15H,36H,0A6,20H,12H
N = $-BUF
DATA ENDS
;声明CODE段
CODE SEGMENT
;设置CS指向CODE段,DS指向DATA段
ASSUME CS:CODE,DS:DATA
;设置DS,SI
BEGIN: MOV AX,DATA
MOV DS,AX
MOV SI,1
NEXT1:
;将SI的值赋给DI
MOV DI,SI
INC DI
MOV AL,[BUF+SI-1]
NEXT2:
;比较AL,[BUF+DI-1]地址的内容
;若>=,则跳转到NEXT3
CMP AL,[BUF+DI-1]
JAE NEXT3
;否则互换[BUF+DI-1]地址的内容与AL的内容
XCHG [BUF+DI-1],AL
;用AL的值覆盖[BUF+SI-1]地址指向的内容(还是原内容)
MOV [BUF+SI-1],AL
NEXT3:
INC DI
;比较DI与N,结果为<=,跳到NEXT2
CMP DI,N
JBE NEXT2
INC SI
;比较SI与N-1,结果为<=,跳到NEXT1
CMP SI,N-1
JBE NEXT1
;调用DOS系统4C号功能(?没找到DOS 4C号功能)
MOV AH,4CH
INT 21H
CODE ENDS
解决方案二:
《汇编语言》习题1
时间: 2024-11-03 23:04:42