ASSEMBLY LANGUAGE - VISUAL STUDIOS (IDE) Write a Program to print the sum of two
ID: 3807692 • Letter: A
Question
ASSEMBLY LANGUAGE - VISUAL STUDIOS (IDE)
Write a Program to print the sum of two hex digits.
Example:
Enter first hex digit: 1
Enter second hex digit: A
Hex sum = B
Use ReadHex to read hex digit from keyboard.
Example: call ReadHex ;Input hexDig1
mov hexDig1, AL
To write a hex digit to the screen we will use author's routine, WriteHex. The routine is written to write a hex number but we will use it to just write a single hex digit.
movzx EAX, hexSum ;Print hexSum
call WriteHex
Use the following Definitions:
.data
hex1Msg BYTE
hex2Msg BYTE
hexSumMsg BYTE "Hex sum = ", 0
hexDig1 BYTE ?
hexDig2 BYTE ?
hexSum BYTE ?
Explanation / Answer
The following is the assembly code.
I hope this solves your problem
.data
hex1Msg BYTE “enter First hex number”, 0ah, 0dh, "$"
hex2Msg BYTE “Enter 2nd hex number”, 0ah, 0dh, "$"
hexSumMsg BYTE "Hex sum = ", 0ah, 0dh, "$"
hexDig1 BYTE ?
hexDig2 BYTE ?
hexSum BYTE ?
.code
Main proc
LEA DX, hex1Msg
MOV AH, 9
INT 21H ;Displays 1st msg for the user to enter hex number
call ReadHex
MOV hexD1g1, EAX
MOV AX, hexDig2
LEA DX, hex2Msg
MOV AH, 9
INT 21H
call ReadHex
MOV hexDig2, EAX
MOV BX, hexDig1
ADD AX,BX
mov hexSum, AL
LEA DX, hexSumMsg
MOV AH, 9
INT 21H
mov EAX, hexSum
call WriteHex
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.