我是装配新手,也是我使用DOSBox
我试图以大写字母打印用户输入的小写字母的字母顺序前后字母。 (例如,如果用户输入B
,则会打印D
和 .MODEL SMALL
.STACK 100H
.DATA
MSG1 DB "Enter a letter between a and z:$"
MSG2 DB "The previous letter is:$"
MSG3 DB "The next letter is:$"
X DB ?
.CODE
MAIN PROC
; initialize DS
MOV AX, @DATA
MOV DS, AX
; print MSG1
LEA DX, MSG1
MOV AH, 9h
INT 21H
; read lowercase letter
MOV AH,1h
INT 21H
; save the letter X
MOV X, AL
; printing new line
MOV DL, 10
MOV AH, 02h
INT 21h
MOV DL, 13
MOV AH, 02h
INT 21h
; print MSG2
MOV AH, 9h
LEA DX, MSG2
INT 21H
; The previous letter
MOV DL, X
SUB DL, 1
ADD DL, 48
MOV AH, 2h
INT 21H
; print MSG3
MOV AH, 9h
LEA DX, MSG3
INT 21H
; The previous letter
MOV DL, X
ADD DL, 1
ADD DL, 48
MOV AH, 2h
INT 21H
; DOS exit
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
)
但我的代码打印出奇怪的样本。
我的代码:
{{1}}
答案 0 :(得分:0)
您可以执行以下操作 看:
.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 0DH,0AH,'Enter a lowerCase letter between a and z :$'
MSG2 DB 0DH,0AH,'Tht previous letter is :$'
MSG3 DB 0DH,0AH,'The next letter is:$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
LEA DX,MSG2
MOV AH,9
INT 21H
MOV AH,2
SUB AL,20H
SUB AL,1H
MOV BL,AL
MOV DL,BL
INT 21H
LEA DX,MSG3
MOV AH,9
INT 21H
MOV AH,2
ADD AL,2H
MOV DL,AL
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN