我对组装很陌生-不到一周的经验。我试图从提示中接收一个字符,然后以十进制显示 ASCII 码。我已经为此工作了几个小时,并决定来这里。
当我在提示符中输入“a”时,我的模拟器显示我的 char 变量正在存储 61 十六进制,这是正确的。我似乎无法让它打印到屏幕上(十六进制或十进制)。
编辑:将代码更改为循环并除以十。我有正确的字符打印出来,但相反。数字 97 打印出 79
到目前为止,这就是我所拥有的:
; **************** MACROS *********************
; START PROGRAM
START MACRO
MOV AX, DATA ; Data Segment to AX Register
MOV DS, AX ; HAVE DS Point to Data Segment
ENDM
; END PROGRAM
END MACRO
MOV AH, 4CH ; END Program
INT 21H ; Call DOS Service
ENDM
; PRINT STRING TO OUTPUT
PSTRING MACRO STR
MOV AH,09H
LEA DX,STR
INT 21H
ENDM
; Creates a New Line
NEWLINE MACRO
MOV DX, 0AH ; Input of string to DX
MOV AH, 02H ; Write Char to standard output
INT 21H
MOV DL, 0DH ;
MOV AH, 02H ; Carriage Return
INT 21H ;
ENDM
; Get CHAR Input
GETINPUT MACRO INPUT
MOV AH, 01H ; Receive input
INT 21H ; Call DOS Service
MOV INPUT, AL ; Store into Input Variable
ENDM
; ********** END MACROS *******************
.MODEL
.DATA
MSG1 db 'Choose A Char to Convert To ASCII: $'
CHAR db ? ; Store Input Char
REM db ? ; Remainder 8-bit storate
QUOT db ? ; Quotient 8-bit storage
.CODE
MAIN PROC
START
PSTRING MSG1
GETINPUT CHAR
NEWLINE
MOV AX, 0 ; Clear AX Register
MOV AL, CHAR ; Move input to AL
MOV DX, 0 ; Clear DX Register
MOV DL, 10 ; Add 10 to DL Register
DIV DL ; Divide By Number of Students For Average
; ********************** ;
; QUOTIENT STORED IN AL ;
; REMAINDER STORED IN AH ;
; ********************** ;
myLoop:
MOV REM, AH ; Move Remainder into REM Variable
MOV QUOT, AL ; Move Quotient into QUOT Variable
MOV DL, REM ; Move Data we want printed into DL
ADD DL, '0' ; Make into Ascii Char
MOV AH,02H ; Output Char Service
INT 21H ; Call DOS Service
MOV AL, QUOT ; Place Quotient Into AL
MOV AH, 0 ; AH was altered, Zero it out
MOV DL, 10 ; Set Divisor to 10
DIV DL ; Divide AX by 10
CMP AH, 0 ; If No Quotient Remains we can exit
JNZ myLoop ; Jump if NOT zero
MOV AH, 4CH ; End Program
INT 21H
END
MAIN ENDP
END MAIN