Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I was trying to multiply three numbers in assembly language with c++. Can someon

ID: 3862982 • Letter: I

Question

I was trying to multiply three numbers in assembly language with c++. Can someone check and let me know what I am doing wrong and how I can do to improve this code?

.global main

.func main

main:

PUSH {LR}

LDR R0, value1

BL printf

SUB SP, SP, #4

LDR R0, =scanformat

MOV R1, SP

BL scanf

LDR R4, [SP]

LDR R0, value2

BL printf

SUB SP, SP, #4

LDR R0, =scanformat

MOV R1, SP

BL scanf

LDR R5, [SP]

LDR R0, value3

BL printf

SUB SP, SP, #4

LDR R0, =scanformat

MOV R1, SP

BL scanf

LDR R6, [SP]

MOV R0, R4

MOV R1, R5

MOV R2, R6

BL printf

MUL R7, R4, R5

MUL R7, R7, R6

LDR R0, =product

MOV R1, R4

MOV R2, R5

MOV R3, R6

MOV R4, R7

BL printf

ADD SP, SP, #4

POP {PC}

_exit:

MOV PC, LR

value1: .word first

value2: .word second

value3: .word third

.data

string:

product: .asciz "The product of %d,%d, and %d is %d "

first: .asciz "Enter First Number: "

second: .asciz "Enter Second Number: "

third: .asciz "Enter Third Number: "

scanformat: .asciz "%d"

Explanation / Answer

.global main

.func main

main:

PUSH {LR}

LDR R0, value1

BL printf

SUB SP, SP, #4

LDR R0, =scanformat

MOV R1, SP

BL scanf

LDR R4, [SP]

LDR R0, value2

BL printf

SUB SP, SP, #4

LDR R0, =scanformat

MOV R1, SP

BL scanf

LDR R5, [SP]

LDR R0, value3

BL printf

SUB SP, SP, #4

LDR R0, =scanformat

MOV R1, SP

BL scanf

LDR R6, [SP]

MOV R0, R4

MOV R1, R5

MOV R2, R6

BL printf

MUL R7, R4, R5

MUL R7, R7, R6

LDR R0, =product

MOV R1, R4

MOV R2, R5

MOV R3, R6

MOV R4, R7

BL printf

ADD SP, SP, #4

POP {PC}

_exit:

MOV PC, LR

value1: .word first

value2: .word second

value3: .word third

.data

string:

product: .asciz "The product of %d,%d, and %d is %d "

first: .asciz "Enter First Number: "

second: .asciz "Enter Second Number: "

third: .asciz "Enter Third Number: "

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote