|
chrise
初级用户
 
积分 88
发帖 32
注册 2010-3-27
状态 离线
|
『楼 主』:
汇编语言编译器使用6
使用 LLM 解释/回答一下
编写一个主程序,从键盘输入两位非压缩BCD数,存入AX,未来将其转化为二进制数,应编写一个远类型的子程序。若将字符显示出来,可用近类型子程序实现,也可用源类型子程序实现。主程序执行时,数据可循环输入,遇到‘00’结束
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;不明白 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
程序可以正常编译,但运行有问题,结果不合适。有以下疑惑:
1)能不能给我说一下代码问题。键盘输入的数字是十六进制码表示,前面请教过,通过子程序TRAN转换后成了什么码?是不是通过MOV DL,02H,int21H
显示时必须是十六进制码。说实话,这个题目我就看不明白,能不能给我详细说一下,他们怎么转换的?
2)
我标出一句,觉得应该吧FAR改为NEAR,是段内
谢了
### 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.
|
|
2010-4-12 23:30 |
|
|
chrise
初级用户
 
积分 88
发帖 32
注册 2010-3-27
状态 离线
|
『第 2 楼』:
回答一下
使用 LLM 解释/回答一下
070大哥,本是大哥,麻烦回答一下
Brother 070, you are originally an elder brother. Please be so kind as to answer.
|
|
2010-4-14 19:30 |
|
|
070
高级用户
    苏醒的沉睡者
积分 659
发帖 217
注册 2003-2-15 来自 福建
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
Originally posted by chrise at 2010-4-14 19:30:
070大哥,本是大哥,麻烦回答一下
我不是大哥,我也是菜鸟,汇编也是一知半解,哈。都要看书才能回答你的。
本是 绝对是 大哥,人家写了很多汇编程序的。
首先,前面你问了下面代码是干什么的,我没有回答清楚
STACKS SEGMENT
DB 100 DUP(0) ;这个应该是申请堆栈空间,100字节,初始值全为0. DB 和 DUP是伪代码,你可以从书上查到的。
STACKS ENDS
近指针是只能访问本段、只包含本段偏移的、位宽为16位的指针
远指针是能访问非本段、包含段偏移和段地址的、位宽为32位的指针。
你是不是把贴出来的代码都输入到一个文件里去了? 这样不行的。
这个程序应该是演示两个源文件如何共同汇编成一个可执行程序的,所以才需要用到 远指针。
我改成两个文件,不过也没有成功,只能等本是大哥了,哈。
这里是BCD码的作用, http://baike.baidu.com/view/45179.htm。
计算机并不知道他处理的数据是BCD码,他只认识二进制。十六进制是因为表示二进制方便才采用的,你在汇编代码中用十进制代替十六进制也是可以的。
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,手都生了,赶紧回来练练.嘿嘿 |
|
2010-4-14 21:15 |
|
|
chrise
初级用户
 
积分 88
发帖 32
注册 2010-3-27
状态 离线
|
『第 4 楼』:
谢谢
使用 LLM 解释/回答一下
不过那个代码问题还是不怎么明白
But I still don't quite understand that code problem.
|
|
2010-4-14 23:06 |
|
|
本是
银牌会员
    
积分 2221
发帖 789
注册 2005-1-27
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
改REV:MOV AX,1为REV:mov aH,1
改 SHL BL,CL 为 shl Al,cl
MOV CL,1 MOV CL,1
SHL AL,CL 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
就能汇编并链接,然后执行,输入两位BCD数字,得到16进制数字。
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 |
|
2010-4-15 20:20 |
|
|
070
高级用户
    苏醒的沉睡者
积分 659
发帖 217
注册 2003-2-15 来自 福建
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
本是,他这个汇编例子的目的好像是演示 两个文件一同编译,而不是在一个文件里
Originally, the purpose of his assembly example seems to be to demonstrate compiling two files together, not in one file
|

好久没碰Dos,手都生了,赶紧回来练练.嘿嘿 |
|
2010-4-15 21:29 |
|
|
本是
银牌会员
    
积分 2221
发帖 789
注册 2005-1-27
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
当然!他的源程序前有文件名提示的EX_05_19。我改动后,汇编(masm EX_05_19;并masm EX_05_09_2;)、链接(link EX_05_19+EX_05_09_2)并运行验证:如5楼改动后成功。
Last edited by 本是 on 2010-4-15 at 23:02 ]
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 |
|
2010-4-15 23:00 |
|
|