这是我的8086 .COM
文件代码:
org 100h ;tells the assembler that the code that follows should be placed at offset 1000H
.MODEL SMALL ;Determies the size of code and data pointers
.STACK 100h ;Tells the size of the stack
.DATA ;Separates variable declaration
;Messages to be displayed
Message1 DB "Enter your Full name: $"
Message2 DB "Enter your date of birth : $"
Messagee3 DB "Enter the current date : $"
.CODE
Main PROC ;Beginning of the Main Procedure
mov ax, @data
mov ds, ax
mov ah, 9h
mov dx, OFFSET Message1
int 21h
mov ah, 0ah
int 21h
mov bl, al
mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h
mov ah, 9h
mov dx, OFFSET Message2
int 21h
mov ah, 0ah
int 21h
mov bl, al
mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h
mov dl, bl
mov ah, 0ah
mov ah, 4ch ;the program to exit immediately
int 21h ;The standard way to call the interrupt handler 0x21
Main ENDP ;denotes the end of the procedure
END Main ;denotes the end of the program, Main.
ret ;transfers control to the return address located on the stack.
您似乎使用DOS函数AH = 0Ah从键盘获取输入,但是首先必须保留一个存储数据的存储变量。它的地址应该放在DS:DX上,请参阅http://www.ctyme.com/intr/rb-2563.htm
请记住,从键盘获得的数字是十进制数字(字符串),需要先将其转换为二进制,然后才能对它们进行一些算术运算。而且减法的结果(您的年龄以二进制表示)必须转换为数字字符串才能在控制台中显示。
将您的作业拆分为一系列的呼叫说明宏:从CALL初始化和CALL终止,编写这些过程的代码,然后继续添加更多过程:WritePrompt,ReadInput,DecimalToBinary,BinaryToDecimal。
您可以查看宏库dosapi和cpuext16(如果您需要灵感)。这就是代码在EuroAssembler中的外观:
Peace16 PROGRAM FORMAT=COM
INCLUDE dosapi.htm, cpuext16.htm
Main:: PROC
StdOutput ="Enter your Full name: "
StdInput FullName
StdOutput ="Enter the year of your birth: "
StdInput BirthYear
StdOutput ="Enter this year: "
StdInput ThisYear
LodD BirthYear ; Convert the string of digits to binary number in AX.
MOV BX,AX ; Temporary save the converted birth year.
LodD ThisYear ; Convert the string of digits to binary number in AX.
SUB AX,BX ; Compute the difference.
StoD Age ; Convert binary number in AX to string of digits in Age.
StdOutput ="Hi ",FullName,=" you are now ",Age,=" years old."
TerminateProgram
FullName DB 32*BYTE
BirthYear DB 6*BYTE
ThisYear DB 6*BYTE
Age DB 4*BYTE
ENDP
ENDPROGRAM
BTW要求您的老师从16位DOS代码切换到32位,它更容易,更有用,并且您不必为模拟器烦恼。您的32位Windows版本的程序如下所示:
Peace32 PROGRAM FORMAT=PE,ENTRY=Main::
INCLUDE winapi.htm, cpuext32.htm
Main:: PROC
StdOutput ="Enter your Full name: "
StdInput FullName
StdOutput ="Enter the year of your birth: "
StdInput BirthYear
StdOutput ="Enter this year: "
StdInput ThisYear
LodD BirthYear ; Convert the string of digits to binary number in EAX.
MOV EBX,EAX ; Temporary save the converted birth year.
LodD ThisYear ; Convert the string of digits to binary number in EAX.
SUB EAX,EBX ; Compute the difference.
StoD Age ; Convert binary number in EAX to string of digits in Age.
StdOutput ="Hi ",FullName,=" you are now ",Age,=" years old."
TerminateProgram
ENDP
FullName DB 32*BYTE
BirthYear DB 6*BYTE
ThisYear DB 6*BYTE
Age DB 4*BYTE
ENDPROGRAM