Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

A.7 [5] Using SPIM, write and test a program that reads in three integers and prints out the sum of the largest two of the three. Use the SPIM system calls described on pages A-43 and A-45. You can break ties arbitrarily.

Short Answer

Expert verified

The required code:

.data

Str1: .asciiz

Str2: .asciiz

Str3: .asciiz

.text

main:

la $t0, X lw $s0, 0($t0) addi $t1, $0, 0 li $t1, 0

li $a0,0

loop: bge $t0, 8 End_Loop bgt X($t1), $s0, Set_Max_number bgt X($t2), $s1, Set_Max_number addi $t1, $t1, 4 addi $t0, $t0, 1Set_Max_number: move $s0, X($t1) move $s1, X($t2) j loopEnd_Loop: li $v0, 1 addi $s2, $s0, $s1 li $v0,1

syscall

Step by step solution

01

Define the concept.

  • The MIPS instruction “la” is used for loading the address.
  • The MIPS instruction “li” is used for loading immediately.
  • The “branch-on-equal (beq)” is a decision-making instruction in MIPS assembly language. The purpose of using this MIPS assembly instruction “beq reg1, reg2 Label” is going to the statement “Label” if the value of “reg1” is equal to the “reg2”.
  • One of the MIPS instructions is “add $t3 $t4 $t5” for add where $t3 = $t4 + $t5.
  • One of the MIPS instruction is “addi $t3 $t4 1” “$t4” is the source register, “$t3” is the destination register, and “1” is the immediate value. The purpose of using it for add immediately
  • One of the MIPS instructions “bgt Rsrc1, Src2, label” is used for Branching on greater than the conditional branch to the instruction at the mentioned- statement “label” if the register “Rsrc1” contents are greater than the register “Src2” content.

And another kind of the MIPS instruction “bge Rsrc1, Src2, label” is used for Branching on greater than the equal conditional branch to the instruction at the mentioned- statement “label” if the register “Rsrc1” contents are greater than the register “Src2” content.

02

Determine the calculation.

The required code:

.data //this is the data section

Str1: .asciiz "Please enter a number:"

Str2: .asciiz "Please enter a number:"

Str3: .asciiz "Please enter a number:"

Str4: .asciiz "The Sum :"

.text

main:

la $t0, X

lw $s0, 0($t0) //for initialize the first value in array into Max

addi $t1, $0, 0 //Sets the counter to 0

li $t1, 0 //Index for the array of the three user given numbers

li $a0,0 //sum = 0

loop:

bge $t0, 8 End_Loop

bgt X($t1), $s0, Set_Max_number

bgt X($t2), $s1, Set_Max_number

addi $t1, $t1, 4 //Increases the index for the array of given three numbers

addi $t0, $t0, 1 // the counter is increamented

Set_Max_number:

move $s0, X($t1) // set the first greatest number among three numbers

move $s1, X($t2) // set the second greatest number among three numbers

j loop

End_Loop:

li $v0, 1 addi $s2, $s0, $s1 //add the two greatest number

li $v0,1 //print the sum of the two greatest number

syscall

The output of the program:

Please enter a number: 2

Please enter a number: 5

Please enter a number:3

The Sum :8

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Implement a switching network that has two data inputs (Aand B), two data outputs (Cand D), and a control input (S). If Sequals 1, the network is in pass-through mode, and Cshould equal A, and Dshould equal B. If Sequals 0, the network is in crossing mode, and Cshould equal B, and Dshould equal A.

Implement the four functions described in Exercise B.11 using a PLA

B.26 [5] <§B.6> Rewrite the equations on page B-44 for a carry-lookahead logic for a 16-bit adder using a new notation. First, use the names for the CarryIn signals of the individual bits of the adder. That is, use c4, c8, c12, … instead of C1, C2, C7, …. In addition, let Pi,j; mean a propagate signal for bits i to j, and Gi,j; mean a generate signal for bits i to j. For example, the equation

C2 = G1+( P1.G0)+( P1.P0. c0) can be rewritten as

c8= G 7,4 + (P7,4 .G7,0) +( P7,4 .P3,0.c0)

This more general notation is useful in creating wider adders.

One logic function that is used for a variety of purposes

(including within adders and to compute parity) is exclusive OR. The output of a two-input exclusive OR function is true only if exactly one of the inputs is true. Show the truth table for a two-input exclusive OR function and implement this function using AND gates, OR gates, and inverters

We would like to execute the loop below as efficiently as possible. We have two different machines, a MIMD machine and a SIMD machine.

for (i=0;i<2000;i++)

for(j=0;j<3000;j++)

X_array[i][j] = Y_array[j][i] + 200;

6.11.1 [10] For a 4 CPU MIMD machine, show the sequence of MIPS instructions that you would execute on each CPU. What is the speedup for this MIMD machine?

6.11.2 [10] For an 8-wide SIMD machine (i.e.,8 parallel SIMD functional units), write an assembly program in using your own SIMD extensions to MIPS to execute the loop. Compare the number of instructions executed on the SIMD machine to MIMD machine.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free