first programming assignment for mips r3000 processor department of computer science southern...

Post on 12-Jan-2016

234 Views

Category:

Documents

6 Downloads

Preview:

Click to see full reader

TRANSCRIPT

First Programming AssignmentFor MIPS R3000 Processor

Department of Computer ScienceSouthern Illinois University Edwardsville

Fall, 2015

Dr. Hiroshi FujinokiE-mail: hfujino@siue.edu

CS 312 Computer Organization and Architecture

FirstProgram/001

R3000/001

Assembly Programming using MIPS R3000 CPU

R3000 CPU Chip Manufactured by IDT

What is MIPS R3000 Processor?

• A 32-bit RISC CPU developed by MIPS Technologies Inc.,

• Used for high-performance desktops such as workstations

• Many venders manufacture the chip (NEC, IDT, Toshiba)

R3000/002

Assembly Programming using MIPS R3000 CPU

The process of assembly programming

We start from here!

SPIM Simulatordoes these for us

“Test.asm”

FirstProgram/001

(2) Program Definition

(1) Data Section

(3) Program Body

Start developing your first assembly program using SPIM

Prepare your source codeStep #1

Three major components in your SPIM program

Your source code filew/ “.asm” file extension

CS 312 Computer Organization and Architecture

# ############################################################### ## Test2.asm ## ## Sample assembly code No. 2 for testing SPIM Simulator. ## This sample program is just for understanding SPIM assembler. ## ## ############################################################### #

.text .globl main

main: li $s1, 1 # Load "1" to register $S1 li $s2, 2 # Load "2" (decimal "2") to register $S2 add $s0, $s1, $s2 # Add register S1 and S2 and save the # result to S0 register

jr $31 # Return from main (stop the program)

# END OF THE LINES ###############################################

FirstProgram/002

Overview: an assembly program source code for SPIM

The program body

Stop your assembly program

Declaring your program body name

“.text” label declares the beginning of your assembly program source code

“#” indicates an in-line comment

Assemblyinstructions

CS 312 Computer Organization and Architecture

FirstProgram/003

The three components in your SPIM program

1. “Data” Section

• This is the place where you keep any constants in your program

- Error message

- Prompt message for user input

- Any constant, such as “3.14”

- Input/Output buffers (contents vary, but buffer size unchanged)

• The data section is declared by “.data” assembler directive

• SPIM assumes the data section at the beginning

- Because the program codes are supposed to be at the end

This section is “optional”

CS 312 Computer Organization and Architecture

FirstProgram/004

The three components in your SPIM program (continued)

2. “Program Definition” Section

• This is the place where you declare your assembly program

• The program definition section is declared by “.text” assembler directive

• The beginning label of your assembly program declared by “.globl name_of_your_beginning_label”

The program definition section should be the simplest (and shortest)

We will see this in examples later

CS 312 Computer Organization and Architecture

FirstProgram/005

The three components in your SPIM program (continued)

3. “Program Body” Section

• This is the place where you write your program (assembly instructions)

• Your program should be stopped by “jr $31” instruction

• You must start with the beginning label you declared

If you forget that, the CPU continues to execute

What instructions will be executed?

- If you declare “.globl main” in program definition

- You must start your program with “main:” label

We never know before.

CS 312 Computer Organization and Architecture

Your program

main:

jr $31 # Stop program

Instruction field

Comment field

Stop your program

Beginning of a program

Dissection: Program Body Section

Labelfield

FirstProgram/006

CS 312 Computer Organization and Architecture

FirstProgram/007

Start using SPIMOpen your program source code

CS 312 Computer Organization and ArchitectureThis is when we start

PC-SPIM for the first time

FirstProgram/008

Start using SPIM (continued) Specify your source code file

CS 312 Computer Organization and Architecture

FirstProgram/009

Start using SPIM (continued)

Once assembly program isopened, the four windows willbe automatically re-loaded

CS 312 Computer Organization and Architecture

FirstProgram/010

Close-Look (1): “Register” Window

“Register” window

Contents of registers

CS 312 Computer Organization and Architecture

FirstProgram/011

Close-Look (2): “Text Segment” Window

Assembler instructions(from your source code)

Generated machine codes(in Hexadecimal expression)

Address for your instructions

CS 312 Computer Organization and Architecture

FirstProgram/012

Close-Look (3): “Data Segment” Window

Address of major programcomponents are shown

CS 312 Computer Organization and Architecture

FirstProgram/013

Close-Look (4): “Message” Window

Most probably, the least important window ...

Messages from SPIMAssembler are shown here

CS 312 Computer Organization and Architecture

FirstProgram/014

To run your program, press this button

CS 312 Computer Organization and Architecture

FirstProgram/015

Text Segment Window

Specify starting address of your assembly program (optional)

CS 312 Computer Organization and Architecture

FirstProgram/016

Examining registers for the result of program execution

CS 312 Computer Organization and Architecture

FirstProgram/017

The three components in your SPIM program (continued)

# ############################################################### ## Test2.asm ## ## Sample assembly code No. 2 for testing SPIM Simulator. ## This sample program is just for understanding SPIM assembler. ## ## ############################################################### #

.text

.globl main

main: li $s1, 1 # Load "1" to register $S1li $s2, 2 # Load "2" (decimal "2") to register $S2

add $s0, $s1, $s2 # Add register S1 and S2 and save the# result to S0 register

jr $31 # Return from main (stop the program)

# END OF THE LINES ###############################################

# ############################################################### ## Test2.asm ## ## Sample assembly code No. 2 for testing SPIM Simulator. ## This sample program is just for understanding SPIM assembler. ## ## ############################################################### #

.text

.globl main

main: li $s1, 1 # Load "1" to register $S1li $s2, 2 # Load "2" (decimal "2") to register $S2

add $s0, $s1, $s2 # Add register S1 and S2 and save the# result to S0 register

jr $31 # Return from main (stop the program)

# END OF THE LINES ###############################################

CS 312 Computer Organization and Architecture

FirstProgram/018

The three components in your SPIM program (continued)

The results of program execution

CS 312 Computer Organization and Architecture

top related