Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ASM Programming instructions: For this part your goal is to run some example assembly code (provided below), and then modify the code to read in

ASM Programming instructions: For this part your goal is to run some example assembly code (provided below), and then modify the code to read in and add 3 numbers instead of just 2.

  1. .data # variable declarations follow this line
  2. .text # instructions follow this line
  3. main:
  4. ## Code Part 1: Get first number from user, put into $t0.
  5. ori $v0, $0, 5 # OUR CODE BEGINS HERE: load syscall read_int into $v0.
  6. syscall # make the syscall.
  7. addu $t0, $0, $v0 # move the number read into $t0.
  8. ## Get second number from user, put into $t1.
  9. ori $v0, $0, 5 # load syscall read_int into $v0.
  10. syscall # make the syscall.
  11. addu $t1, $0, $v0 # move the number read into $t1.
  12. add $t2, $t0, $t1 # compute the sum.
  13. ## Print out $t2.
  14. addu $a0, $0, $t2 # move the number to print into $a0.
  15. ori $v0, $0, 1 # load syscall print_int into $v0.
  16. syscall # make the syscall.
  17. ori $v0, $0, 10 # syscall code 10 is for exit.
  18. syscall # make the syscall.
  19. ## end of add2.asm.

A discussion of each line of the code is as follows:

The first two lines declare the .data and the .text segments of our code. There is nothing after the .data segment because we have no variables to store. All of our instructions follow the .text segment.

Next comes the declaration of the main: label in line 3 which is required for any code we wish to run. Lines 4-7 read in and store a value. To read a value we must make a system call (or syscall), and tell our processor we need input. Each syscall (there are many types) has an associated number. In order to make a syscall we put the calls associated number in $v0 and then execute the syscall instruction. In our case the associated number for reading in a numerical value is 5. Once a syscall finishes its return values are stored in $v0 and/or $v1.

Lines 8-11 repeat the reading process but store the value in a different register. Line 12 calculates the sum of the two values we read in.

Lines 13-16 handle printing out the computed sum. In this case we are using the print_int syscall whose number is 1. This syscall prints out whatever value is stored in the argument register $a0.

Finally we must exit the main method. Lines 17 and 18 accomplish this by using the exit syscall.

Question 1 [10 pt]. Modify the above piece of code so it can add 3 numbers. Include your code in the report.

Question 2 [10 pt]. What modifications were needed to add the 3 numbers?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

Explain the factors influencing wage and salary administration.

Answered: 1 week ago

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago