『楼 主』:
汇编语言编译器使用5
使用 LLM 解释/回答一下
题目是 从键盘输入二位非压缩的BCD数,存入AX中中,并将其转化为二进制数,且显示出来
NAME EX_05_18
STACKS SEGMENT
DB 100 DUP(0)
STACKS ENDS
CSAG SEGMENT
ASSUME CS:CSAG,SS:STACKS
MAIN PROC FAR
START:PUSH DS
MOV AX,0
PUSH AX
REV:MOV AH,1
INT 21H
MOV BL,AL
INT 21H
MOV AH,AL
MOV AL,BL
CMP AX,3030H;判AX中是否为'00'
JE ENDTRAN
CALL NEAR PTR TRAN
CALL FAR PTR CON
MOV AL,0DH;?
CALL FAR PTR DISP
MOV AL,0AH;?
CALL FAR PTR DISP
JMP REV
ENDTRAN:RET
MAIN ENDP
TRAN PROC NEAR
AND AX,0F0FH
MOV BL,AL
MOV CL,3
SHL AL,CL
MOV CL,1
SHL BL,CL
ADD AL,BL
ADD AL,AH;将两位BCD数转为二进制数
RET
TRAN ENDP
CSAG ENDS
CSBG SEGMENT PARA'CODE'
ASSUME CS:CSBG
CON PROC FAR
PUSH AX
MOV CL,4
SHR AL,CL
ADD AL,30H
CMP AL,39H
JBE CON2
ADD AL,07H
CON2:PUSH AX
MOV AL,0DH
CALL FAR PTR DISP
MOV AL,0AH
CALL FAR PTR DISP
POP AX
CALL FAR PTR DISP;显示高位十六进制数
POP AX
AND AL,0FH
ADD AL,30H
CMP AL,39H
JBE CON1
ADD AL,07H
CON1:CALL FAR PTR DISP
RET
CON ENDP
DISP PROC PAR MOV DL,AL
MOV AL,02H
INT 21H
RET
DISP ENDP
MOV AH,4CH
INT 21H
CSBG ENDS
END START
麻烦指教一下,有以下问题
(1)判断输入的是不是00,为什么是CMP AX,3030H,为什么跟3030比较?
(2)上次请教过MOV DL,0DH MOV AH,02H INT21H 是换行功能。MOV DL,0AH MOV AL,02H INT 21H 是什么功能?
(3)子程序 TRAN 是将ASSCII码转换为二进制数的功能,帮忙看一下算法有没有问题?
(4)编译后有错误:ADD AL,AH
DISP PROC FAR
谢了
Last edited by chrise on 2010-4-11 at 22:34 ]
### Question (1)
The input is two non-compressed BCD numbers entered from the keyboard. Each digit of the BCD number is represented in ASCII code. For example, the ASCII code for '0' is 30H. So, two '0's would be represented as 3030H in ASCII. When we compare AX with 3030H, we are checking if the user has entered two '0's, which would indicate the end of input.
### Question (2)
`MOV DL,0AH` followed by `MOV AH,02H` and `INT 21H` is for a line feed operation. It moves the line feed character (ASCII 0AH) to DL and then uses the DOS function 02H to output it, which moves the cursor to the start of the next line.
### Question (3)
The algorithm in the `TRAN` procedure:
First, `AND AX,0F0FH` is used to clear the high nibble of AH and the low nibble of AL to isolate the two BCD digits. Then, `MOV BL,AL` and `MOV CL,3; SHL AL,CL` shifts the high nibble (now in AL) left by 3 bits. `MOV CL,1; SHL BL,CL` shifts the low nibble (now in BL) left by 1 bit. Then `ADD AL,BL` adds the two shifted nibbles. However, there is an issue with `ADD AL,AH` because AH still has the original ASCII code of the second character. It should probably be `ADD AL, BL` and then adjust based on the correct BCD to binary conversion. The correct BCD to binary conversion for two digits should be: if the two digits are in AL (high nibble) and BL (low nibble), the binary value is (AL * 10) + BL. But the current code is not correctly implementing that. The step `ADD AL,AH` is incorrect as AH is not part of the correct BCD digit components after the initial `AND` operation.
### Question (4)
In the `DISP` procedure, the definition `DISP PROC PAR` is incorrect. It should be `DISP PROC FAR`. Also, the `ADD AL,AH` in the `TRAN` procedure is incorrect as explained above.
The translated text of the code part remains as follows:
NAME EX_05_18
STACKS SEGMENT
DB 100 DUP(0)
STACKS ENDS
CSAG SEGMENT
ASSUME CS:CSAG,SS:STACKS
MAIN PROC FAR
START:PUSH DS
MOV AX,0
PUSH AX
REV:MOV AH,1
INT 21H
MOV BL,AL
INT 21H
MOV AH,AL
MOV AL,BL
CMP AX,3030H;Check if AX is '00'
JE ENDTRAN
CALL NEAR PTR TRAN
CALL FAR PTR CON
MOV AL,0DH;?
CALL FAR PTR DISP
MOV AL,0AH;?
CALL FAR PTR DISP
JMP REV
ENDTRAN:RET
MAIN ENDP
TRAN PROC NEAR
AND AX,0F0FH
MOV BL,AL
MOV CL,3
SHL AL,CL
MOV CL,1
SHL BL,CL
ADD AL,BL
ADD AL,AH;Convert two BCD digits to binary number
RET
TRAN ENDP
CSAG ENDS
CSBG SEGMENT PARA'CODE'
ASSUME CS:CSBG
CON PROC FAR
PUSH AX
MOV CL,4
SHR AL,CL
ADD AL,30H
CMP AL,39H
JBE CON2
ADD AL,07H
CON2:PUSH AX
MOV AL,0DH
CALL FAR PTR DISP
MOV AL,0AH
CALL FAR PTR DISP
POP AX
CALL FAR PTR DISP;Display high hexadecimal number
POP AX
AND AL,0FH
ADD AL,30H
CMP AL,39H
JBE CON1
ADD AL,07H
CON1:CALL FAR PTR DISP
RET
CON ENDP
DISP PROC FAR MOV DL,AL
MOV AH,02H
INT 21H
RET
DISP ENDP
MOV AH,4CH
INT 21H
CSBG ENDS
END START
Please give advice, there are the following problems
(1)Judge whether the input is 00, why is CMP AX,3030H, why compare with 3030?
(2)I asked before that MOV DL,0DH MOV AH,02H INT21H is the line feed function. MOV DL,0AH MOV AL,02H INT 21H is what function?
(3)Subroutine TRAN is the function of converting ASCII code to binary number, please see if the algorithm is problematic?
(4) There is an error after compilation: ADD AL,AH
DISP PROC FAR
Thanks
|