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.6 [5] Using SPIM, write and test an adding machine program that repeatedly reads in integers and adds them into a running sum. The program should stop when it gets an input that is 0, printing out the sum at that point. Use the SPIM system calls described on pages A-43 and A-45.

Short Answer

Expert verified

The required code:

.data

str: .asciiz

str2: .asciiz

.text

main:

li $a0,0

loop:

li $v0,4

la $a0,str

syscall

li,$v0,5

syscall

beq $v0,$0,done

add $v0,$0,$v0

j loop

done:

li $v0,4

la $a0,str2

syscall

li $v0,1

move $a0,$s0

syscall

.end

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.
02

Determine the calculation

The required code:

.data //this is the data section

str: .asciiz "Please enter the number to be added:"

str2: .asciiz "The Sum:"

.text //this is the text section

main:

li $a0,0 //Initialize the sum is equal to 0

loop:

li $v0,4 //for printing the string

la $a0,str

syscall

li,$v0,5 //for taking the user given input

syscall

beq $v0,$0,done // if zero was taken as a input then end and print the sum

add $v0,$0,$v0 //sum = sum + input

j loop // Jump to the input another number

done:

li $v0,4 // for printing the string

la $a0,str2

syscall

li $v0,1 //for printing the sum

move $a0,$s0

syscall

.end

The output of the code:

Please enter the number to be added: 2

Please enter the number to be added: 3

Please enter the number to be added: 1

Please enter the number to be added: 0

The Sum : 6

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

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.

A.8 [5] Using SPIM, write and test a program that reads in a positive integer using the SPIM system calls. If the integer is not positive, the program should terminate with the message “Invalid Entry”; otherwise the program should print out the names of the digits of the integers, delimited by exactly one space. For example, if the user entered “728,” the output would be “Seven Two Eight.”

Rewrite the code for fact to use fewer instructions.

Question: 6.17 Benchmarking is field of study that involves identifying representative workloads to run on specific computing platforms in order to be able to objectively compare performance of one system to another. In this exercise we will compare two classes of benchmarks: the Whetstone CPU benchmark and the PARSEC Benchmark suite. Select one program from PARSEC. All programs should be freely available on the Internet. Consider running multiple copies of Whetstone versus running the PARSEC Benchmark on any of systems described in Section 6.11.

6.17.1 [60] what is inherently different between these two classes of workload when run on these multi-core systems?

6.17.2 [60] In terms of the Roofline Model, how dependent will the results you obtain when running these benchmarks be on the amount of sharing and synchronization present in the workload used?

Figure B.8.8 on page B-55 illustrates the implementation of the register file for the MIPS datapath. Pretend that a new register file is to be built, but that there are only two registers and only one read port, and that each register has only 2 bits of data. Redraw Figure B.8.8 so that every wire in your diagram corresponds to only 1 bit of data (unlike the diagram in Figure B.8.8, in which some wires are 5 bits and some wires are 32 bits). Redraw the registers using D flipflops. You do not need to show how to implement a D flip-flop or a multiplexor.

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