HELP PLEASE Program in assembly language using MARIE Using the MARIE computer as
ID: 3838582 • Letter: H
Question
HELP PLEASE
Program in assembly language using MARIE
Using the MARIE computer assembly language, write a program that computes the following expression: z (a * b) * (c * d). The computer will read in the input values a, b, c, and d from the keyboard, and the final result (z) has to be displayed. In addition, every time an input value is read in, it must be displayed on the screen. Each time a multiplication of two numbers is needed, it has to be done using a multiplication subroutine. Remember that the MARIE instruction set does not have an instruction to execute multiplication, you must create a subroutine (function) that multiplies two numbers and call it each time you need it
Explanation / Answer
mul(int, int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-20], edi
mov DWORD PTR [rbp-24], esi
mov DWORD PTR [rbp-8], 0
mov DWORD PTR [rbp-4], 0
.L3:
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-24]
jge .L2
mov eax, DWORD PTR [rbp-20]
add DWORD PTR [rbp-8], eax
add DWORD PTR [rbp-4], 1
jmp .L3
.L2:
mov eax, DWORD PTR [rbp-8]
pop rbp
ret
.LC0:
.string "Enter value of a: "
.LC1:
.string "%d"
.LC2:
.string "A=%d"
.LC3:
.string "Enter value of b: "
.LC4:
.string "Enter value of c: "
.LC5:
.string "Enter value of d: "
.LC6:
.string "Z=%d"
main:
push rbp
mov rbp, rsp
push rbx
sub rsp, 40
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
lea rax, [rbp-24]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-24]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov edi, OFFSET FLAT:.LC3
mov eax, 0
call printf
lea rax, [rbp-28]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-28]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov edi, OFFSET FLAT:.LC4
mov eax, 0
call printf
lea rax, [rbp-32]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-32]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov edi, OFFSET FLAT:.LC5
mov eax, 0
call printf
lea rax, [rbp-36]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-36]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov edx, DWORD PTR [rbp-36]
mov eax, DWORD PTR [rbp-32]
mov esi, edx
mov edi, eax
call mul(int, int)
mov ebx, eax
mov edx, DWORD PTR [rbp-28]
mov eax, DWORD PTR [rbp-24]
mov esi, edx
mov edi, eax
call mul(int, int)
mov esi, ebx
mov edi, eax
call mul(int, int)
mov DWORD PTR [rbp-20], eax
mov eax, DWORD PTR [rbp-20]
mov esi, eax
mov edi, OFFSET FLAT:.LC6
mov eax, 0
call printf
mov eax, 0
add rsp, 40
pop rbx
pop rbp
ret
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.