data SEGMENT
ORG 1000h
buf DB 1,2,3,4,5,6,7
count DB $-buf
data ENDS
stack SEGMENT
DB 100 DUP (?)
stack ENDS
code SEGMENT
ASSUME CS:code,DS:data,SS:stack
start: MOV AX,data
MOV DS,AX
LEA CX,count
DEC CX
l1: LEA BX,buf
MOV DX,CX
l2: MOV AL,[BX]
CMP AL,[BX+1]
JGE NExt
XCHG AL,[BX+1]
MOV [BX],AL
JMP NExt
NExt: INC BX
DEC DX
JNE l2
DEC CX
JNZ l1
INT 20h
code ENDS
END start
为什么 运行的时候 DOS显示无效指令
哪里 出现错误啊 怎么改?
參考答案:LEA CX,count 这一句是送count的偏移量给cx,送的是地址,并不是个数。
应该改为:
LEA si,count
MOV cx,[si]
INT 20H 这一条结束语句有误,没有入口参数,应该改为:
mov ah,04h
INT 21H
修改的程序如下,能够进行显示
data SEGMENT
ORG 1000h
buf DB 1,2,3,4,5,6,7
count DB $-buf
data ENDS
stack SEGMENT
DB 100 DUP (?)
stack ENDS
code SEGMENT
ASSUME CS:code,DS:data,SS:stack
start: MOV AX,data
MOV DS,AX
LEA si,count
MOV cx,[si]
push cx
DEC CX
l1: LEA BX,buf
MOV DX,CX
l2: MOV AL,[BX]
CMP AL,[BX+1]
JGE NExt
XCHG AL,[BX+1]
MOV [BX],AL
JMP NExt
NExt: INC BX
DEC DX
JNE l2
DEC CX
JNZ l1
lea bx,buf
pop cx
display:mov dl,[bx]
add dl,30h
mov ah,02h
int 21h
inc bx
loop display
mov ah,1 ;暂停,任意键关闭
int 21h
mov ah,4ch
int 21h
code ENDS
END start