問題:
Write a program that clears the screen, locates the cursor near the
middle of the screen, prompts the user for two integers, adds the
integers, and displays their sum. You will need to use the ClrScr,
Gotoxy, WriteString, Crlf, and ReadInt procedures from the Irvine32
library.
代碼:
TITLE MASM Template (main.asm)
; Description:
;
; Revision date:
INCLUDE Irvine32.inc
.data
input1stIntMsg BYTE "Input the 1st integer: ",0
input2ndIntMsg BYTE "Input the 2nd integer: ",0
outputSumMsg BYTE "The sum of the two integers: ",0
num1 DWORD ?
num2 DWORD ?
sum DWORD ?
.code
main PROC
call Clrscr ; clear screen
; read the first number
mov dl, 20 ; set the column
mov dh, 11 ; set the row
call Gotoxy ; move the cursor to near the center
; output the prompt message
mov edx,OFFSET input1stIntMsg
call WriteString
call ReadInt ; read integer
mov num1, eax ; store the value
; read the second number
mov dl, 20 ; set the column
mov dh, 12 ; set the row
call Gotoxy ; move the cursor to near the center
; output the prompt message
mov edx,OFFSET input2ndIntMsg
call WriteString
call ReadInt ; read integer
mov num2, eax ; store the value
; compute the sum
mov eax, num2
add eax, num1
mov sum, eax
; output result
mov dl, 20 ; set the column
mov dh, 13 ; set the row
call Gotoxy ; move the cursor to near the center
mov edx, OFFSET outputSumMsg
call WriteString
mov eax, sum
call WriteInt
exit
main ENDP
END main
; Description:
;
; Revision date:
INCLUDE Irvine32.inc
.data
input1stIntMsg BYTE "Input the 1st integer: ",0
input2ndIntMsg BYTE "Input the 2nd integer: ",0
outputSumMsg BYTE "The sum of the two integers: ",0
num1 DWORD ?
num2 DWORD ?
sum DWORD ?
.code
main PROC
call Clrscr ; clear screen
; read the first number
mov dl, 20 ; set the column
mov dh, 11 ; set the row
call Gotoxy ; move the cursor to near the center
; output the prompt message
mov edx,OFFSET input1stIntMsg
call WriteString
call ReadInt ; read integer
mov num1, eax ; store the value
; read the second number
mov dl, 20 ; set the column
mov dh, 12 ; set the row
call Gotoxy ; move the cursor to near the center
; output the prompt message
mov edx,OFFSET input2ndIntMsg
call WriteString
call ReadInt ; read integer
mov num2, eax ; store the value
; compute the sum
mov eax, num2
add eax, num1
mov sum, eax
; output result
mov dl, 20 ; set the column
mov dh, 13 ; set the row
call Gotoxy ; move the cursor to near the center
mov edx, OFFSET outputSumMsg
call WriteString
mov eax, sum
call WriteInt
exit
main ENDP
END main