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

Write a complete MIPS program that prompts the user for two integer (in a subrou

ID: 3887701 • Letter: W

Question

Write a complete MIPS program that prompts the user for two integer (in a subroutine - call it twice), calculates the product of the integers (also in a subroutine) and prints the product with simple descriptive text (also in a subroutine). You will have three little subroutines. Use the "simple linkage convention" (no stack use, use appropriate registers for arguments and return values). Do not worry about branch delays. Some syscall codes you may need are: print string, code 4 in $v0, string address in $a0; read integer, code 5, value returned in $v0; print integer, code 1, value in $a0; end program, code 10.

Explanation / Answer

MIPS code:

$LFB0 = .

main:

addiu $sp,$sp,-48

sw $31,44($sp)

sw $fp,40($sp)

move $fp,$sp

jal getInt()

nop

sw $2,24($fp)

jal getInt()

nop

sw $2,28($fp)

lw $5,28($fp)

lw $4,24($fp)

jal mul(int, int)

nop

sw $2,32($fp)

lw $4,32($fp)

jal print(int)

nop

move $2,$0

move $sp,$fp

lw $31,44($sp)

lw $fp,40($sp)

addiu $sp,$sp,48

j $31

nop

$LFB1 = .

getInt():

addiu $sp,$sp,-40

sw $31,36($sp)

sw $fp,32($sp)

move $fp,$sp

lui $2,%hi($LC0)

addiu $4,$2,%lo($LC0)

jal printf

nop

addiu $2,$fp,24

move $5,$2

lui $2,%hi($LC1)

addiu $4,$2,%lo($LC1)

jal scanf

nop

lw $2,24($fp)

move $sp,$fp

lw $31,36($sp)

lw $fp,32($sp)

addiu $sp,$sp,40

j $31

nop

$LFB2 = .

mul(int, int):

addiu $sp,$sp,-8

sw $fp,4($sp)

move $fp,$sp

sw $4,8($fp)

sw $5,12($fp)

lw $3,8($fp)

lw $2,12($fp)

nop

mult $3,$2

mflo $2

move $sp,$fp

lw $fp,4($sp)

addiu $sp,$sp,8

j $31

nop

$LFB3 = .

print(int):

addiu $sp,$sp,-32

sw $31,28($sp)

sw $fp,24($sp)

move $fp,$sp

sw $4,32($fp)

lw $5,32($fp)

lui $2,%hi($LC2)

addiu $4,$2,%lo($LC2)

jal printf

nop

nop

move $sp,$fp

lw $31,28($sp)

lw $fp,24($sp)

addiu $sp,$sp,32

j $31

nop

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