Question
Write four MIPS–Assembly programs to implement the following mathematical ex-
pressions (use the “loop approach”)
2 2 2 2 (d) 4D: Ï Ï Ï Ï [2° +2° +2° +2°) d=1 c=1 b=1 a=1 Place the result, of each mathematical expression, in the console of
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is complete MIPS-Assembly program that calculates given expression:

.text
.globl main

main:
li $t3,1 # d = 1
li $s0,0 # sum
loop1:
beq $t3,3,exit1
li $t2,1 # c = 1
loop2:
beq $t2,3,exit2
li $t1,1 # b = 1
loop3:
li $t0,1 # a = 1
beq $t1,3,exit3
loop4:
# Compute the values
beq $t0,3,exit4
mul $t4,$t0,2
mul $t5,$t1,2
mul $t6,$t2,2
mul $t7,$t3,2
add $s0,$s0,$t4
add $s0,$s0,$t5
add $s0,$s0,$t6
add $s0,$s0,$t7
addi $t0,$t0,1
j loop4
exit4:
addi $t1,$t1,1
j loop3
exit3:
addi $t2,$t2,1
j loop2
exit2:
addi $t3,$t3,1
j loop1
exit1:
# Prints the value on the MARS console
move $a0,$s0
li $v0,1
syscall
# exit
li $v0,10
syscall

Screenshot of the code:

. text .globl main main: li $t3,1 # d = 1 li $80,0 # sum loopl: beq $t3, 3, exiti li $t2,1 = c = 1 loop2: beq $t2,3, exit2 li

exit 3: addi $t2, $t2,1 j loop2 exit2: addi $t3, $t3,1 j loop1 exiti: # Prints the value on the MARS console move $al, $50 li

Here is output (printed on the console):

192

You can comment below the answer, for any doubts, and I will be happy to help!

Please give a thumbs up if my answer could be of help!

All the best!

Add a comment
Know the answer?
Add Answer to:
Write four MIPS–Assembly programs to implement the following mathematical ex- pressions (use the “loop approach”) 2...
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
  • MIPS Programming Assignment 4 (logical operations) Please write a complete MIPS assembly language programs for the...

    MIPS Programming Assignment 4 (logical operations) Please write a complete MIPS assembly language programs for the following questions and print a hardcopy of your code to submit 1. Swap each pair of elements in the string "chararn be an even number of characters in "chararray". (see loop4.a) 2 "numbers" is an array of five words. Catculate the sum of aftetements in "number muttiples of 4. Use the and instruction, not div or remfor thisquestion(S 3. "number" is a word. Write...

  • PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs...

    PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to:             -define a recursive procedure/function and call it.             -use syscall operations to display integers and strings on the console window             -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9                      if n <= 5              =...

  • 2. The table below holds MIPS assembly code fragments with different branch instructions LOOP addi $s2....

    2. The table below holds MIPS assembly code fragments with different branch instructions LOOP addi $s2. $s2. 2 subi $t1. st1. 1 bne t1. 0. LOOP DONE: LOOP: it st2. $0. stl beq t2. 0. DONE addi $s2. Ss2. 2 LOOP DONE: For the loops written in MIPS assembly in the above table, assume that the register Şt1 is initialized to the value of 10. What is the value in register $s2 assuming that $s2 initially has a value of...

  • Compiling C Programs into MIPS Assembly and Machine Code sll $t1, $a1, 2 add $t1, $a0....

    Compiling C Programs into MIPS Assembly and Machine Code sll $t1, $a1, 2 add $t1, $a0. $t1 lw $t0, 0($t1) lw $t2, 4($t1) sw $t2, 0($t1) sw $t0, 4($t1) 1. From the assembly code, what machine code might a MIPS assembler produce? 2. What does this program do? Write the C code for this assembly program.

  • Name B. (7 pts) MIPS short answer 1. (3pt) For the following MIPS assembly language program:...

    Name B. (7 pts) MIPS short answer 1. (3pt) For the following MIPS assembly language program: loop: addi Sto, $to,-1 bne $to, $zero, loop Translate the second instruction into MIPS machine language and write it in hex. 2. (2 pt) Which best describes the reason that we maintain the stack pointer in a register? (circle one) i. The hardware forces use of a stack pointer. ii. We need a local pointer because we are often limited to relative addressing. ili....

  • Write MIPS code for each of the following instructions, Your assembly should implement the C code...

    Write MIPS code for each of the following instructions, Your assembly should implement the C code directly – i.e.,do not ’optimize’ the C code to change the order of operations or reduce computations. Use commands only like add, sub, lw, sw, immediate Part 1. x = 3-13*x; Do not use multiply. One way of doing the multiply without a multiply instruction is by using many add instructions (x+x+...+x). For this problem, you should do it with fewer additions. Hint: We...

  • MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4,...

    MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4, 5, 6); int main) int num, position; scanf("%d",&num) ; position search(array, printf("The position is: num, 5); %d\n",positio int search(int array, int num, int size int position =-1; for(int i-0;i<size; i++) if(array [i]=num) { position-i; break; return position; Register map $s1: position $a0: array address $a1: num . $a2: size . $VO: return value

  • 2) Write a MIPS assembly language version of the following C code segment: int A[75], B[75];...

    2) Write a MIPS assembly language version of the following C code segment: int A[75], B[75]; for (i = 1; i < 73; i ++) { C[i] = (A[i + 1] + A[i]) * (B[i + 2] - A[i-1]); } Arrays A, B and C start at memory location A000hex, B000hex and C000hex respectively. Try to reduce the total number of instructions and the number of expensive instructions such as multiplies. WRITE A SIMPLE CODE WORKING FOR MARS 4.5

  • Provide assembly code for the following expression in MIPS: if ($2 >= $3) $6 = $7+1;...

    Provide assembly code for the following expression in MIPS: if ($2 >= $3) $6 = $7+1; Please write reason for the solutions

  • Implement the functionality of "main" function for the following C code in MIPS assembly. Comment your...

    Implement the functionality of "main" function for the following C code in MIPS assembly. Comment your code including which registers represent the variables in the main function. Include the .data and the .text sections. Do not write the bit_count function. int main() { int count = 149; int num = 432; if (count + num > 534){ count = bit_count(num); printf("%d bits to store the number", count); }else{ printf("cannot count bit in %d",) } }

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