中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-15 01:12
47,812 topics / 349,917 posts / today 0 new / 48,268 members
DOS开发编程 & 发展交流 (开发室) » Assembler language compiler uses 5
Printable Version  2,139 / 4
Floor1 chrise Posted 2010-04-11 21:57
初级用户 Posts 32 Credits 88
### 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
Floor2 本是 Posted 2010-04-12 11:38
银牌会员 Posts 790 Credits 2,227
MOV AH,4CH
INT 21H
This program segment doesn't work! That is, it is not executed.

"ADD AL,AH; Convert two BCD numbers to binary numbers" is changed; to;
——That is, convert full-width characters to half-width!

"DISP PROC PAR MOV DL,AL" is broken into two lines and PAR is changed to FAR such as
DISP PROC FAR
MOV DL,AL

(1) Because the hexadecimal code value of the character "0" is 30h

(2) MOV DL,0AH MOV AL,02H INT 21H What is the function?
First, correct mov al,02h to mov AH,02h, and then say that the function is it is a carriage return

Brother, your input has too many errors, which will waste a lot of time. Be sure to carefully check the source program according to the content in the book, especially pay attention to distinguishing between numbers and characters (such as 0 and o or O, 1 and l, 6 and b, 9 and q), full-width and half-width (such as ; and ;, , and,, “” and "", ‘’ and ''), reserved words - custom words - undefined words (FAR-PAR) differences, especially do not misspell registers. If it is VGA monitor programming, it may burn the monitor hardware!

[ Last edited by 本是 on 2010-4-12 at 11:40 ]
Floor3 chrise Posted 2010-04-12 20:39
初级用户 Posts 32 Credits 88
What is a hexadecimal code? Are all the numbers entered from the keyboard hexadecimal codes?
Floor4 chrise Posted 2010-04-12 21:32
初级用户 Posts 32 Credits 88
In the STACK segment, there is a line:
DB 100 DUP (0)
What does 100 refer to?
Isn't stack operation a word operation? What is the function of this sentence? Thanks
Floor5 070 Posted 2010-04-12 22:33
高级用户 Posts 218 Credits 663 From 福建
Originally posted by chrise at 2010-4-12 20:39:
What is a hexadecimal code? Are all the numbers entered from the keyboard hexadecimal codes?


Hexadecimal Explanation
http://baike.baidu.com/view/230306.html?wtp=tt

In assembly, numbers ending with H or h are hexadecimal codes.


------------------------Make good use of search engines to solve specific and clear problems.


Originally posted by chrise at 2010-4-12 21:32:
There is a sentence in the STACK segment
DB 100 DUP (0)
What does 100 refer to?
Stack operations are word operations, aren't they? What is the function of this sentence? Thanks



The stack can also perform byte operations.
DB is to define byte units. DUP is to repeat the initial value. 100 is the number of times. The following (0) is the assigned initial value.

The function of the instruction is to apply for 100 bytes of space in the stack, and each byte is assigned a value of 0.

The function is to answer originally, ha. I don't know.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023