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.
IN MIPS Create a program that, given two inputs a and b, will output the following:...
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 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 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,...
IN MIPS PLEASE. Need help writing a MIPS program that reads from a text file named "input.txt" and places it in a buffer. A buffer of 80 bytes is more than enough. Before you call your function, set $a0 equal to the address of the filename and $a1 to the address of the buffer where data is stored. The function should return the number of bytes read in $v0. In the main program, print an error message and terminate the...
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 )...
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 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...
Write an assembly program that takes two values, a and b, multiplies them, and then stores the result in c. When the program begins: • a is located in $fp + 1 • b is located in $fp + 2 At the end of the program: • a is located in $fp + 1 • b is located in $fp + 2 • c is located in $fp + 3 In doing this, there must be at least one function,...
MIPS ASSEMBLY LANGUAGE Write MIPS code to convert binary to decimal: (01110001)2 to (113)10 .data binary_digit: .word 0 1 1 1 0 0 0 1 # is 113 in decimal .globl main main: # Load arguments to argument registers # Call convert() # Print return value # (it's in $v0, make sure to copy it before overwriting to print) # Properly end program convert: # This label is where conversion of the current...
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...