China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-30 14:32
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » Assembler compilers use 6 View 2,368 Replies 6
Original Poster Posted 2010-04-12 23:30 ·  中国 陕西 西安 电信
初级用户
Credits 88
Posts 32
Joined 2010-03-27 14:30
16-year member
UID 163163
Gender Male
Status Offline
### Translation:
### Write a main program that inputs two non-compressed BCD numbers from the keyboard and stores them in AX. In the future, it will be converted into a binary number. An far-type subroutine should be written. If the character is to be displayed, a near-type subroutine can be implemented, or a source-type subroutine can be implemented. When the main program is executed, the data can be input cyclically and ends when '00' is encountered.
NAME EX_05_19
STACKS SEGMENT
DB 100 DUP(0)
STACKS ENDS
EXTRN CON:FAR,DISP:FAR
CODES SEGMENT
ASSUME CS:CODES,SS:STACKS
MAIN PROC FAR
START:PUSH DS
MOV AX,0
PUSH AX
REV:MOV AX,1
INT 21H
MOV BL,AL
INT 21H
MOV AH,AL
MOV AL,BL
CMP AX,3030H
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 BL,CL
MOV CL,1
SHL AL,CL
ADD AL,BL
ADD AL,AH
RET
TRAN ENDP
CODES ENDS
END START
NAME EX_05_09_2
PUBLIC CON,DISP
CSBG SEGMENT PARA 'CODE'
ASSUME CS:CSBG
CON PROC FAR
PUSH AX
MOV CL,4
SHR AL,CL
ADD AL,30H
ADD AL,30H
CMP AL,39H
JBE CON2
ADD AL,7
CON2:PUSH AX
MOV AL,0DH
CALL FAR PTR DISP; I don't understand 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 DISP
RET
CON ENDP
DISP PROC FAR
MOV DL,AL
MOV AH,2
INT 21H
RET
DISP ENDP
CSBG ENDS
END

There is a problem with the program when running. There are the following doubts:
1) Can you tell me about the code problem. The numbers input from the keyboard are represented by hexadecimal codes. I asked before, what code does it become after conversion through the subroutine TRAN? Is it necessary to use MOV DL,02H, int21H to display in hexadecimal code. To be honest, I don't understand this question at all. Can you tell me in detail how they convert?
2)
I marked a sentence and think that FAR should be changed to NEAR, which is within the segment
Thanks

### Note: The part with ... is the original content that remains as is as per the requirements.
Floor 2 Posted 2010-04-14 19:30 ·  中国 陕西 西安 电信
初级用户
Credits 88
Posts 32
Joined 2010-03-27 14:30
16-year member
UID 163163
Gender Male
Status Offline
Brother 070, you are originally an elder brother. Please be so kind as to answer.
Floor 3 Posted 2010-04-14 21:15 ·  中国 黑龙江 哈尔滨 教育网
高级用户
★★
苏醒的沉睡者
Credits 659
Posts 217
Joined 2003-02-15 00:00
23-year member
UID 930
Gender Male
From 福建
Status Offline
Originally posted by chrise at 2010-4-14 19:30:
Brother 070, you are originally a brother, please trouble to answer.


I'm not a brother, I'm also a novice, and my assembly knowledge is also half-baked, heh. I have to read books to answer your questions.
Ben Shi is definitely a brother, he has written many assembly programs.

First of all, you asked what the following code does earlier, and I didn't answer clearly.
STACKS SEGMENT
DB 100 DUP(0) ;This should be applying for stack space, 100 bytes, initial value all 0. DB and DUP are pseudo-code, you can find them in the book.
STACKS ENDS


A near pointer is a 16-bit pointer that can only access the current segment and only contains the offset of the current segment.
A far pointer is a 32-bit pointer that can access non-current segments and contains the segment offset and segment address.


Did you input all the posted code into one file? That won't work.
This program should be to demonstrate how two source files are assembled into an executable program together, so far pointers are needed.

I changed it into two files, but it still didn't succeed, I can only wait for Brother Ben Shi, heh.

Here is the function of BCD code, http://baike.baidu.com/view/45179.htm.

Computers don't know that the data they process is BCD code, they only recognize binary. Hexadecimal is adopted because it is convenient to represent binary. You can also use decimal instead of hexadecimal in assembly code.
好久没碰Dos,手都生了,赶紧回来练练.嘿嘿
Floor 4 Posted 2010-04-14 23:06 ·  中国 陕西 西安 电信
初级用户
Credits 88
Posts 32
Joined 2010-03-27 14:30
16-year member
UID 163163
Gender Male
Status Offline
But I still don't quite understand that code problem.
Floor 5 Posted 2010-04-15 20:20 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 2,227
Posts 790
Joined 2005-01-27 00:00
21-year member
UID 35703
Gender Male
Status Offline
Rev:mov aH,1
shl Al,cl
MOV CL,1 MOV CL,1
shl Bl,cl
改 ADD AL,30H 为 一行add al,30h
ADD AL,30H
CALL FAR PTR DISP;不明白 MOV AL,0AH
改为两行,如
CALL FAR PTR DISP;不明白
MOV AL,0AH
Then it can be assembled and linked, and then executed. Input two - digit BCD numbers to get hexadecimal numbers.
my major is english----my love is dos----my teacher is the buddha----my friends--how about U
Floor 6 Posted 2010-04-15 21:29 ·  中国 黑龙江 哈尔滨 教育网
高级用户
★★
苏醒的沉睡者
Credits 659
Posts 217
Joined 2003-02-15 00:00
23-year member
UID 930
Gender Male
From 福建
Status Offline
Originally, the purpose of his assembly example seems to be to demonstrate compiling two files together, not in one file
好久没碰Dos,手都生了,赶紧回来练练.嘿嘿
Floor 7 Posted 2010-04-15 23:00 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 2,227
Posts 790
Joined 2005-01-27 00:00
21-year member
UID 35703
Gender Male
Status Offline
Of course! The file name prompt EX_05_19 is in front of his source program. After I made changes, I assembled (masm EX_05_19; and masm EX_05_09_2;), linked (link EX_05_19+EX_05_09_2) and ran for verification: as modified in floor 5, it was successful.

[ Last edited by 本是 on 2010-4-15 at 23:02 ]
my major is english----my love is dos----my teacher is the buddha----my friends--how about U
Forum Jump: