一个简单的汇编程序,请高手帮忙看下有什么问题没?

2024-12-23 08:21:43
推荐回答(3个)
回答1:

MOV [DI],DL
INC DI
AND AX,AX
JZ STO
MOV DL,0
LOOP AGAIN
STO:INC BX
INC BX
DEC CL
BACK:MOV DL,[DI]
MOV AH,2
INT 21H
你的dl(ASCII码)送入di后,di加了1,此时BACK取出的是DI+1的值,而不是你存入的ASCII码(DI),所以显示的是非ASCII码。(是从 JZ STO跳转来的)。你可以把程序输入到debug中跟踪调试一下。

回答2:

DATA SEGMENT
DATA1 DW 20 DUP(?)
DATA2 DB 5 DUP(?)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
LEA BX,DATA1
MOV WORD PTR [BX],0000H
MOV WORD PTR [BX+2],0001H
MOV CX,18
NEXT: MOV AX,[BX]
MOV DX,[BX+2]
ADD AX,DX
MOV [BX+4],AX
INC BX
INC BX
LOOP NEXT

MOV CX,20
LEA BX,DATA1
MOV BP,0AH
OUTPUT:XOR DX,DX
LEA DI,DATA2
MOV AX,[BX]

AGAIN:DIV BP
ADD DL,30H
MOV [DI],DL
AND AX,AX
JZ BACK
INC DI
XOR DX,DX
JMP AGAIN

BACK:MOV DL,[DI]
MOV AH,2
INT 21H
DEC DI
CMP DI,OFFSET DATA2
JAE BACK

MOV DL,0DH
MOV AH,2
INT 21H
MOV DL,0AH
MOV AH,2
INT 21H
INC BX
INC BX
LOOP OUTPUT
MOV AH,4CH
INT 21H
CODE ENDS
END START

回答3:

;拿2分,添了个蛇足.
DATA SEGMENT
DATA1 DW 25 DUP(?)
;DATA2 DB 5 DUP('$')
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
LEA BX,DATA1
MOV word ptr [BX],0
MOV word ptr [BX+2],1
MOV CL,23
CLC
CLD
NEXT: MOV AX,[BX]
MOV DX,[BX+2]
ADC AX,DX
MOV [BX+4],AX
INC BX
INC BX
DEC CL
JNZ NEXT
MOV Cx,25;显示前25项
LEA si,DATA1
nt:
call show
inc si
inc si
mov ax,0e20h
int 10h
loop nt
mov ah,0
int 16h
MOV AH,4CH
INT 21H

show:
push bx
push cx
push dx
mov ax,[si]
xor cx,cx
mov bx,10
t5:xor dx,dx
div bx
or dx,30h
push dx
inc cx
cmp ax,0
jnz t5
t6:pop ax
mov ah,0eh
int 10h
loop t6
pop dx
pop cx
pop bx
ret

CODE ENDS
END START