MIPS Assembly Language Programming - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

MIPS Assembly Language Programming

Description:

2. MIPS. Assembly Language Programming. CDA 3101 Discussion Section 03. Outline ... Click this menu item to change settings for the emulator. ... – PowerPoint PPT presentation

Number of Views:163
Avg rating:3.0/5.0
Slides: 15
Provided by: CISE9
Category:

less

Transcript and Presenter's Notes

Title: MIPS Assembly Language Programming


1
MIPS Assembly Language Programming
CDA 3101 Discussion Section 03
2
Outline
  • MIPS simulator PCSpim
  • Problems from textbook
  • 2.29, 2.30

3
PCSpim
  • Installation
  • From the textbook CD
  • From the internet
  • http//www.cs.wisc.edu/larus/spim.html

4
Writing A Basic Program
  • Lets 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
PC Spim
6
PC Spim
  • Note the top window it contains the state of
    all registers.

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 wont see the register changes
    until the program ends.

8
PC Spim
  • Click this menu item to reinitialize PC Spim
    its like rebooting your computer. Its often
    necessary to click Reload to run your program
    again.

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

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

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
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
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
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
  • j loop
  • finish addi t0, t0, 100
  • add v0, t0, zero
Write a Comment
User Comments (0)
About PowerShow.com