Question

IN MIPS Create a program that, given two inputs a and b, will output the following:...

IN MIPS

Create a program that, given two inputs a and b, will output the following: • (a*b+b*3)
Create a function that will perform this calculation, and use $a0 and $a1 as the argument registers, and $v0 for the return value.
Ensure that you are able to call this function with additional statements before and after the call: for example, you may be asked to place an addi a, a, 3 call before the function is called, or to calculate the return of the function multiplied by 3, etc. There are example runs of the program below.

#(without any extra instructions): Please enter a number:
2
Please enter a number:
3
The result of the calculation (a*b+b*3) is: 15
-- program is finished running --
#(program sets a to (a+3) before the function is called): Please enter a number:
2
Please enter a number:
3
The result of the calculation is: 24
-- program is finished running --
#(program adds 6 to result): Please enter a number:
2
Please enter a number:
3
The result of the calculation is: 21
-- program is finished running --
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given, Write a MIPS code to solve the above given problem and print the result for the same.

Please run the below code and verify the functionality asked in question.

MIPS code:

$LC0:
.ascii "Please enter a number: \000"
$LC1:
.ascii "The result of the calculation (a*b+b*3) is: \000"
$LC2:
.ascii "The result of calculation is: \000"
main:
addiu $sp,$sp,-56
sw $31,52($sp)
sw $fp,48($sp)
move $fp,$sp
lui $2,%hi($LC0)
addiu $5,$2,%lo($LC0)
lui $2,%hi(_ZSt4cout)
addiu $4,$2,%lo(_ZSt4cout)
jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
nop

addiu $2,$fp,36
move $5,$2
lui $2,%hi(_ZSt3cin)
addiu $4,$2,%lo(_ZSt3cin)
jal std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
nop

lui $2,%hi($LC0)
addiu $5,$2,%lo($LC0)
lui $2,%hi(_ZSt4cout)
addiu $4,$2,%lo(_ZSt4cout)
jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
nop

addiu $2,$fp,40
move $5,$2
lui $2,%hi(_ZSt3cin)
addiu $4,$2,%lo(_ZSt3cin)
jal std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
nop

lw $2,36($fp)
nop
addiu $3,$2,3
lw $2,40($fp)
nop
mult $3,$2
mflo $2
mtc1 $2,$f0
nop
cvt.d.w $f0,$f0
swc1 $f0,28($fp)
swc1 $f1,24($fp)
lui $2,%hi($LC1)
addiu $5,$2,%lo($LC1)
lui $2,%hi(_ZSt4cout)
addiu $4,$2,%lo(_ZSt4cout)
jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
nop

lw $7,28($fp)
lw $6,24($fp)
move $4,$2
jal std::basic_ostream<char, std::char_traits<char> >::operator<<(double)
nop

move $3,$2
lui $2,%hi(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
addiu $5,$2,%lo(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
move $4,$3
jal std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
nop

lw $2,36($fp)
nop
sw $2,32($fp)
lw $2,36($fp)
nop
addiu $2,$2,3
sw $2,36($fp)
lw $2,36($fp)
nop
addiu $3,$2,3
lw $2,40($fp)
nop
mult $3,$2
mflo $2
mtc1 $2,$f0
nop
cvt.d.w $f0,$f0
swc1 $f0,28($fp)
swc1 $f1,24($fp)
lui $2,%hi($LC2)
addiu $5,$2,%lo($LC2)
lui $2,%hi(_ZSt4cout)
addiu $4,$2,%lo(_ZSt4cout)
jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
nop

lw $7,28($fp)
lw $6,24($fp)
move $4,$2
jal std::basic_ostream<char, std::char_traits<char> >::operator<<(double)
nop

move $3,$2
lui $2,%hi(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
addiu $5,$2,%lo(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
move $4,$3
jal std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
nop

lw $2,32($fp)
nop
sw $2,36($fp)
lw $2,36($fp)
nop
addiu $3,$2,3
lw $2,40($fp)
nop
mult $3,$2
mflo $2
addiu $2,$2,6
mtc1 $2,$f0
nop
cvt.d.w $f0,$f0
swc1 $f0,28($fp)
swc1 $f1,24($fp)
lui $2,%hi($LC2)
addiu $5,$2,%lo($LC2)
lui $2,%hi(_ZSt4cout)
addiu $4,$2,%lo(_ZSt4cout)
jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
nop

lw $7,28($fp)
lw $6,24($fp)
move $4,$2
jal std::basic_ostream<char, std::char_traits<char> >::operator<<(double)
nop

move $3,$2
lui $2,%hi(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
addiu $5,$2,%lo(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
move $4,$3
jal std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
nop

move $2,$0
move $sp,$fp
lw $31,52($sp)
lw $fp,48($sp)
addiu $sp,$sp,56
j $31
nop

__static_initialization_and_destruction_0(int, int):
addiu $sp,$sp,-32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
sw $4,32($fp)
sw $5,36($fp)
lw $3,32($fp)
li $2,1 # 0x1
bne $3,$2,$L5
nop

lw $3,36($fp)
li $2,65535 # 0xffff
bne $3,$2,$L5
nop

lui $2,%hi(_ZStL8__ioinit)
addiu $4,$2,%lo(_ZStL8__ioinit)
jal std::ios_base::Init::Init() [complete object constructor]
nop

lui $2,%hi(__dso_handle)
addiu $6,$2,%lo(__dso_handle)
lui $2,%hi(_ZStL8__ioinit)
addiu $5,$2,%lo(_ZStL8__ioinit)
lui $2,%hi(_ZNSt8ios_base4InitD1Ev)
addiu $4,$2,%lo(_ZNSt8ios_base4InitD1Ev)
jal __cxa_atexit
nop

$L5:
nop
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop

_GLOBAL__sub_I_main:
addiu $sp,$sp,-32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
li $5,65535 # 0xffff
li $4,1 # 0x1
jal __static_initialization_and_destruction_0(int, int)
nop

move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop

Please let me know in the comments if you need more help in this.

Add a comment
Know the answer?
Add Answer to:
IN MIPS Create a program that, given two inputs a and b, will output the following:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how...

    Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how one can use subroutines (also called procedures, functions, and methods) in MIPS. Because of the importance of subroutines in modern programming, most hardware designers include mechanisms to help programmers. In a high-level language like C or Java, most of the details of subroutine calling are hidden from the programmer. MIPS has special registers to send information to and from a subroutine. The registers $a0,...

  • Turn the Following c-code into MIPS assembly code. You are given the main procedure which calls...

    Turn the Following c-code into MIPS assembly code. You are given the main procedure which calls multiply. You are also given the argument registers to be used. /* C-program */ int multiply (int number, int times) { int f; f = number * times return f; } # MIPS PROGRAM # assumes we have called the program leaf_example # $a0=number, $a1=times, $s0=f main: $addi $a0,$zero,3 $addi $a1,$zero,2 jal multiply # place the address into $ra j EXIT2 EXIT2: j OS...

  • Write a MIPS program with the following specifications: Use the my_mul function in question 1 to...

    Write a MIPS program with the following specifications: Use the my_mul function in question 1 to create a function which computes factorials: n! = n. (n - 1). … 3 .2 . 1 Note: You can only use my_mul function, and not use other functions). Each function must save all variables it modifies. below is my_mul my_mul : #multiply $a0 with $a1 #does not handle negative $a1 ! #Note : This is an inefficient way to multiply ! addi $sp,...

  • The task will be to write a program in assembler to enter a number and calculate...

    The task will be to write a program in assembler to enter a number and calculate its associated Fibonacci number using a procedure (subroutine) that is called recursively. Factorial and Fibonacci(outline Programs) # MIPS assembly assembly assemblyassemblycode .data n: .word 4 .text main: la $s0,n lw $a0, 0($s0) jal factorial # move what ever is returned into $a0 move $a0, $v0 li $v0,1 syscall b finished factorial: add $sp , $sp , -8 # make room sw $a0, 4($sp )...

  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

  • MIPS - Takes two inputs from the user, which are the lengths of two sides of...

    MIPS - Takes two inputs from the user, which are the lengths of two sides of a polygon. It adds those two lengths and prints the sum. Your task is modify the program to make it specific to a triangle, and to print the perimeter of that triangle. See blue highlighted. preamble: prompt1: prompt2: answer: endline: .data ascii .asciiz asciiz .asciiz asciiz .asciiz "\nThis program, written by <YOUR NAME>," " can be used to add the length of two sides...

  • 1. [2 points] Write a MIPS assembly language program of the following C function and the...

    1. [2 points] Write a MIPS assembly language program of the following C function and the code to call the function: int leaf_example (int g, h, i, j) { int f; f = (g + h) - (i + j); return f; مهه Arguments g, h, i, and j are passed to the function in registers $a0, $al, Şa2, and $a3, respectively while f in $50 (hence, need to save $50 on stack), and the result is to be stored...

  • Write the hexadecimal notation for a MIPS machine language program that adds 42 to the value in register 2 placing the result in register 3 and then returns. Example of running the program: Enter valu...

    Write the hexadecimal notation for a MIPS machine language program that adds 42 to the value in register 2 placing the result in register 3 and then returns. Example of running the program: Enter value for register 1: 2 Enter value for register 2: 3 Running MIPS program. MIPS program completed normally. $01 = 0x00000002 $02 = 0x00000003 $03 = 0x0000002D ...

  • im trying to complete mips program code about a calculator program that can calculate integer addition...

    im trying to complete mips program code about a calculator program that can calculate integer addition / subtraction written using the MIPS assembler. im having hard times to debug this. The input is given to the array of Formula char (base address $ s0) in the form of a formula. The null character (\ 0, ASCII code 0) is placed at the end. The calculation result is given to the register $ s1 and the overflow is ignored. For example,...

  • 2. Q2 [25 points) Consider the MIPS code given in the following. main: addi Ssp, Ssp,...

    2. Q2 [25 points) Consider the MIPS code given in the following. main: addi Ssp, Ssp, -4 addi Sa0, $0, 2 sw $a0, 4(Ss1) addi Sal, $0, 3 sw Sal, 8(Ss1) jal dofsum sw SvO, 16(8s1) lw Sra, O(Ssp) addi Ssp, Ssp, 4 jr Sra dofsum: jal sum jr Sra sum: add SvO, Sa0, Sal jr Sra Draw the snapshot of the stack before, during, and after dofsum) function call. As- sume SSP, 0x45fff00 before dofsum() function call.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT