从首地址为1000H开始存放数据,从小大大排序后仍放在该区域。下面程序错在哪里了?
DATA SEGMENT
ORG 0FFEH
ARRAY DB 100
DB ?
DB 100 DUP(?)
BUF1 DB 'PLEASE INPUT STRING$'
BUF2 DB 'THE ORDER IS$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MAIN PROC
MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET BUF1
MOV AH,09H
INT21H
MOV DX,OFFSET ARRAY
MOV AH,0AH
INT21H
MOV AX,DATA
MOV DS,AX
MOV CX,[0FFFH]
L1:
DEC CX
MOV DI,CX
MOV BX,0
L2:
MOV AX,[1000H+BX]
CMP AX,[1000H+BX+1]
JBECONTINUE
XCHG AX,[1000H+BX+1]
MOV [1000H+BX],AX
CONTINUE:
INC BX
LOOPL2
MOV CX,DI
LOOPL1
CALLNEAR PTR CURS
MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET BUF2
MOV AH,09H
INT21H
MOV DX,1000H
MOV AH,09H
INT21H
MOV AH,4CH
INT21H
MAIN ENDP
CURS PROC NEAR
MOV AL,02H
MOV BH,00H
MOV DH,03H
MOV DL,00H
INT10H
RET
CURS ENDP
CODE ENDS
END
汇编语言编写程序
答案:2 悬赏:70 手机版
解决时间 2021-01-25 11:28
- 提问者网友:書生途
- 2021-01-24 11:40
最佳答案
- 五星知识达人网友:轻熟杀无赦
- 2021-01-24 12:42
DATA SEGMENT
ARRAY DB 100
DB ?
DB 100 DUP(?)
BUF1 DB 'Please input string : $'
BUF2 DB 'The order is : $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
MAIN PROC
MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET BUF1
MOV AH, 09H
INT 21H
MOV DX, OFFSET ARRAY
MOV AH, 0AH
INT 21H
MOV CL, ARRAY + 1
MOV CH, 0
DEC CX
L1:
MOV DI, CX
MOV BX, 0
L2:
MOV AL, [ARRAY + BX + 2]
CMP AL, [ARRAY + BX + 3]
JBE CONTINUE
XCHG AL, [ARRAY + BX + 3]
MOV [ARRAY + BX + 2], AL
CONTINUE:
INC BX
LOOP L2
MOV CX, DI
LOOP L1
MOV BL, ARRAY + 1
MOV BH, 0
MOV [ARRAY + BX + 2], '$'
MOV AH, 2
MOV DL, 13
INT 21H
MOV DL, 10
INT 21H
CALL NEAR PTR CURS
MOV DX, OFFSET BUF2
MOV AH, 09H
INT 21H
MOV DX, OFFSET ARRAY
ADD DX, 2
MOV AH, 09H
INT 21H
EXIT:
MOV AH, 4CH
INT 21H
MAIN ENDP
CURS PROC NEAR
MOV AL, 02H
MOV BH, 00H
MOV DH, 03H
MOV DL, 00H
INT 10H
RET
CURS ENDP
CODE ENDS
END MAIN
可以了。
ARRAY DB 100
DB ?
DB 100 DUP(?)
BUF1 DB 'Please input string : $'
BUF2 DB 'The order is : $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
MAIN PROC
MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET BUF1
MOV AH, 09H
INT 21H
MOV DX, OFFSET ARRAY
MOV AH, 0AH
INT 21H
MOV CL, ARRAY + 1
MOV CH, 0
DEC CX
L1:
MOV DI, CX
MOV BX, 0
L2:
MOV AL, [ARRAY + BX + 2]
CMP AL, [ARRAY + BX + 3]
JBE CONTINUE
XCHG AL, [ARRAY + BX + 3]
MOV [ARRAY + BX + 2], AL
CONTINUE:
INC BX
LOOP L2
MOV CX, DI
LOOP L1
MOV BL, ARRAY + 1
MOV BH, 0
MOV [ARRAY + BX + 2], '$'
MOV AH, 2
MOV DL, 13
INT 21H
MOV DL, 10
INT 21H
CALL NEAR PTR CURS
MOV DX, OFFSET BUF2
MOV AH, 09H
INT 21H
MOV DX, OFFSET ARRAY
ADD DX, 2
MOV AH, 09H
INT 21H
EXIT:
MOV AH, 4CH
INT 21H
MAIN ENDP
CURS PROC NEAR
MOV AL, 02H
MOV BH, 00H
MOV DH, 03H
MOV DL, 00H
INT 10H
RET
CURS ENDP
CODE ENDS
END MAIN
可以了。
全部回答
- 1楼网友:舍身薄凉客
- 2021-01-24 13:09
; 本程序通过编译,运行正确
code segment
assume cs:code,ds:code
; -----------------------------------------
; 入口参数
; si=声音频率地址
; bx=时间节拍地址
do_music proc near
push dx
push cx
push ax
@@sound: test word ptr [si],0ffffh
jz @@return
mov al,0b6h ;向计数器写控制字
out 43h,al ;方式3、双字节写和二进制计数方式写到控制口
mov dx,12h ;设置被除数
mov ax,533h*896
div word ptr [si] ;其商ax为预置值
out 42h,al ;先送lsb
mov al,ah
out 42h,al ;后送msb
in al,61h ;读端口原值
mov ah,al
or al,3
out 61h,al ;接通扬声器
mov cx,[bx]
@@waitf1: push cx
mov cx,28010 ;设循环次数为8ff0h
@@delay1: loop @@delay1
pop cx ;循环持续cx次,即传进来的节拍时间
loop @@waitf1
inc si
inc si ;下一个频率值
inc bx
inc bx ;下一个节拍值
mov al,ah ;写回61h端口值,关闭扬声器
out 61h,al ;关闭扬声器
jmp @@sound
@@return: pop ax
pop cx
pop dx
ret
do_music endp
; -----------------------------------------
didas equ 18 ;延时(时钟嘀嗒次数)
; 《圣诞铃声》频率值
christ_freq dw 7 dup(330),392,262,294,330,4 dup(349),2 dup(330),330,294,294,262
dw 294,392,7 dup(330),392,262,294,330,4 dup(349),2 dup(330),392,392
dw 349,294,262,0
; 最后一个0控制结束;设置节拍时间时,采用了25*400=10000表示4/4拍的音节,即0.25秒(四分音符),0.5秒用50*400表示
christ_time dw 2 dup(25*400,25*400,50*400),4 dup(25*400),100*400
dw 2 dup(25*400,25*400,50*400),4 dup(25*400),2 dup(50*400)
dw 2 dup(25*400,25*400,50*400),4 dup(25*400),100*400
dw 2 dup(25*400,25*400,50*400),4 dup(25*400),100*400
start: push cs
pop ds
push cs
pop es ;使数据段、附加段与代码段同段
lea si,christ_freq ;对应的频率值地址
lea bx,christ_time ;对应的节拍值地址
call do_music ;激活扬声器,使之发出指定频率、指定时长的声音,奏乐
exit_proc: mov ah,4ch ;结束程序
int 21h
code ends
end start ;编译到此结束
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯