Write a program code in assembly language for an elementary decimal number calcu
ID: 3806832 • Letter: W
Question
Write a program code in assembly language for an elementary decimal number calculator, that will be capable of multiplying two 2-digit integer number. Follow the below requirent:
1. At power-up, the display is blank, waiting for user input 2. The user enters exactly two decimal digits representing the first integer factor in the multiplication. (f e number is 9 or smaller, the user will be required to enter a leading zero. These digits are echoed to the display as they are entered. 3. The user presses the key to signal that a multiplication is desired. 4. The user enters exactly two more decimal digits representing the second integer factor. (Again, if the number is 9 or smaller, the user will be required to enter a leading zero.) These digits are echoed to the display as they are entered. 5. The result of the multiplication in base 10 is calculated immediately and appears on the display. Note that the largest result possible from the multiplication is 99x99 9801 and will fit on the four digits of the display. 6. The result remains on the display until the user presses the C key to indicate "clear," after which the display is blanked and the calculator is ready for the next multiplication.Explanation / Answer
section .data
; Messages
msg1 db 10,'-Calculator-',10,0
lmsg1 equ $ - msg1
msg2 db 10,'Number 1: ',0
lmsg2 equ $ - msg2
msg3 db 'Number 2: ',0
lmsg3 equ $ - msg3
msg4 db 'Multiply',10,0
lmsg6 equ $ - msg6
msg5 db 'Operation: ',0
lmsg8 equ $ - msg8
msg6 db 10,'Result: ',0
lmsg9 equ $ - msg9
msg7 db 10,'Invalid Option',10,0
lmsg10 equ $ - msg10
nlinea db 10,10,0
lnlinea equ $ - nlinea
section .bss
; Spaces reserved for storing the values provided by the user.
opc: resb 2
num1: resb 2
num2: resb 2
result: resb 2
section .text
global _start
_start:
; Print on screen the message 1
mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, lmsg1
int 80h
; Print on screen the message 2
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, lmsg2
int 80h
; We get num1 value.
mov eax, 3
mov ebx, 0
mov ecx, num1
mov edx, 2
int 80h
; Print on screen the message 3
mov eax, 4
mov ebx, 1
mov ecx, msg3
mov edx, lmsg3
int 80h
; We get num2 value.
mov eax, 3
mov ebx, 0
mov ecx, num2
mov edx, 2
int 80h
; Print on screen the message 4
mov eax, 4
mov ebx, 1
mov ecx, msg4
mov edx, lmsg4
int 80h
; Print on screen the message 5
mov eax, 4
mov ebx, 1
mov ecx, msg5
mov edx, lmsg5
int 80h
; We get the option selected.
mov ebx,0
mov ecx,opc
mov edx,2
mov eax,3
int 80h
mov ah, [opc] ; Move the selected option to the registry ah
sub ah, '0' ; Convert from ascii to decimal
; We compare the value entered by the user to know what operation to perform.
cmp ah, 1
je add
cmp ah, 2
je subtract
cmp ah, 3
je multiply
cmp ah, 4
je divide
; If the value entered by the user does not meet any of the above
; conditions then we show an error message and we close the program.
mov eax, 4
mov ebx, 1
mov ecx, msg10
mov edx, lmsg10
int 80h
jmp exit
multiply:
xor dx,dx
mov bx,03E8h
div bx
mov ax,dx
xor dx,dx
mov bx,0064h
div bx
mov ax,dx
xor dx,dx
mov bx,000Ah
div bx
mov al,dl
mov [result], ax
; Print on screen the message 9
mov eax, 4
mov ebx, 1
mov ecx, msg9
mov edx, lmsg9
int 80h
; Print on screen the result
mov eax, 4
mov ebx, 1
mov ecx, result
mov edx, 1
int 80h
; We end the program
jmp exit
; We end the program
jmp exit
exit:
; Print on screen two new lines
mov eax, 4
mov ebx, 1
mov ecx, nlinea
mov edx, lnlinea
int 80h
; End the program
mov eax, 1
mov ebx, 0
int 80h
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.