Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 MIPS Assembly Language Programming CDA 3101 Discussion Section 03.

Similar presentations


Presentation on theme: "1 MIPS Assembly Language Programming CDA 3101 Discussion Section 03."— Presentation transcript:

1 1 MIPS Assembly Language Programming CDA 3101 Discussion Section 03

2 2 Outline MIPS simulator – PCSpim Problems from textbook 2.29, 2.30

3 3 PCSpim Installation 1.From the textbook CD 2.From the internet http://www.cs.wisc.edu/~larus/spim.html

4 4 Writing A Basic Program Let ’ s start by writing a program that sums all the numbers between 1 and 10. int main() { int i = 10; int sum = 0; do { sum = sum + i; i = i - 1; } while( i != 0 ); return sum; }

5 5 PC Spim

6 6 Note the top window – it contains the state of all registers.

7 7 PC Spim The button on the top right runs the program to its end, after you click “ OK ” on the dialog box. Note that you won ’ t see the register changes until the program ends.

8 8 PC Spim Click this menu item to reinitialize PC Spim – it ’ s like rebooting your computer. It ’ s often necessary to click Reload to run your program again.

9 9 PC Spim Click this menu item to change settings for the emulator.

10 10 PC Spim Click this menu item to change settings for the emulator. Sometimes it ’ s helpful to uncheck “ General registers in hexadecimal ” so that you can read values as regular numbers.

11 11 PC Spim Click the button that looks like a hand to set breakpoints. The program will stop running at positions you indicate, and wait for your authorization to continue upon reaching said point. You will also see the register values updated.

12 12 Understanding MIPS code Problem 2.30 Add comments to the following MIPS code and describe in one sentence what it computes. The code processes 2 arrays and produces a value in $v0. Each array consists of 2500 words indexed 0 through 2499, the base addresses of the arrays are stored in $a0, $a1, and their sizes are stored in $a2, $a3. What will be returned in $v0?

13 13 Understanding MIPS code Problem 2.30 sll$a2, $a2, 2 sll$a3, $a3, 2 add$v0, $zero, $zero add$t0, $zero, $zero outer:add $t4, $a0, $t0 lw $t4, 0($t4) add $t1, $zero, $zero inner:add$t3, $a1, $t1 lw$t3, 0($t3) bne$t3, $t4, skip addi$v0, $v0, 1 skip:addi $t1, $t1, 4 bne$t1, $a3, inner addi $t0, $t0, 4 bne $t0, $a2, outer

14 14 Understanding MIPS code Problem 2.29 Add comments to the following MIPS code and describe in one sentence what it computes. Assume $a0, $a1 are input, initial value a, b; $v0 is output. $a0: input a; $a1: input b; $v0: output; add$t0, $zero, $zero loop:beq $a1, $zero, finish add $t0, $t0, $a0 sub $a1, $a1, 1 jloop finish:addi $t0, $t0, 100 add $v0, $t0, $zero


Download ppt "1 MIPS Assembly Language Programming CDA 3101 Discussion Section 03."

Similar presentations


Ads by Google