# io - 1 Reading and Printing Integers For our next example...

This preview shows pages 1–2. Sign up to view the full content.

1 . Reading and Printing Integers For our next example, we'll write a program named add2.asm that computes the sum of two numbers specified by the user at runtime, and displays the result on the screen. The algorithm this program will follow is: 1. Read the two numbers from the user - We'll need two registers to hold these two numbers. We can use \$t0 and \$t1 for this. 2. Compute their sum- We'll need a register to hold the result of this addition. We can use \$t2 for this. 3. Print the sum. 4. Exit. We already know how to do this, using syscall. The only parts of the algorithm that we don't know how to do yet are to read the numbers from the user, and print out the sum. Luckily, both of these operations can be done with a syscall. Looking again in table from lecture 7 , we see that syscall 5 can be used to read an integer into register \$v0, and and syscall 1 can be used to print out the integer stored in \$a0. The syscall to read an integer leaves the result in register \$v0, however, which is a small problem, since we want to put the first number into \$t0 and the second into \$t1.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern