210 likes | 255 Views
First Programming Assignment For MIPS R3000 Processor. CS 286 Computer Organization and Architecture. Department of Computer Science Southern Illinois University Edwardsville Summer, 2019 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu. FirstProgram/001. R3000 CPU Chip Manufactured by IDT.
E N D
First Programming Assignment For MIPS R3000 Processor CS 286 Computer Organization and Architecture Department of Computer Science Southern Illinois University Edwardsville Summer, 2019 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu FirstProgram/001
R3000 CPU Chip Manufactured by IDT Assembly Programming using MIPS R3000 CPU 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/001
We start from here! SPIM Simulator does these for us Assembly Programming using MIPS R3000 CPU The process of assembly programming R3000/002
Start developing your first assembly program using SPIM Your source code file w/ “.asm” file extension Prepare your source code Three major components in your SPIM program (1) Data Section (2) Program Definition Step #1 (3) Program Body CS 286 Computer Organization and Architecture “Test.asm” FirstProgram/001
“#” indicates an in-line comment # ############################################################### # # 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 ############################################### “.text” label declares the beginning of your assembly program source code Declaring your program body name Overview: an assembly program source code for SPIM The program body Assembly instructions Stop your assembly program CS 286 Computer Organization and Architecture FirstProgram/002
The three components in your SPIM program This section is “optional” 1. “Data” Section CS 286 Computer Organization and Architecture • 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 FirstProgram/003
The three components in your SPIM program (continued) 2. “Program Definition” Section We will see this in examples later CS 286 Computer Organization and Architecture • 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) FirstProgram/004
The three components in your SPIM program (continued) 3. “Program Body” Section We never know before. CS 286 Computer Organization and Architecture • This is the place where you write your program (assembly instructions) • You must start with the beginning label you declared - If you declare “.globl main” in program definition - You must start your program with “main:” label • Your program should be stopped by “jr $31” instruction If you forget that, the CPU continues to execute What instructions will be executed? FirstProgram/005
Dissection: Program Body Section Instruction field Label field Comment field Beginning of a program Your program Stop your program CS 286 Computer Organization and Architecture main: jr $31 # Stop program FirstProgram/006
Open your program source code Start using SPIM This is when we start PC-SPIM for the first time CS 286 Computer Organization and Architecture FirstProgram/007
Specify your source code file Start using SPIM (continued) CS 286 Computer Organization and Architecture FirstProgram/008
Start using SPIM (continued) Once assembly program is opened, the four windows will be automatically re-loaded CS 286 Computer Organization and Architecture FirstProgram/009
Close-Look (1): “Register” Window “Register” window Contents of registers CS 286 Computer Organization and Architecture FirstProgram/010
Close-Look (2): “Text Segment” Window Assembler instructions (from your source code) Generated machine codes (in Hexadecimal expression) Address for your instructions CS 286 Computer Organization and Architecture FirstProgram/011
Close-Look (3): “Data Segment” Window Address of major program components are shown CS 286 Computer Organization and Architecture FirstProgram/012
Close-Look (4): “Message” Window Messages from SPIM Assembler are shown here CS 286 Computer Organization and Architecture Most probably, the least important window ... FirstProgram/013
To run your program, press this button CS 286 Computer Organization and Architecture FirstProgram/014
Text Segment Window Specify starting address of your assembly program (optional) CS 286 Computer Organization and Architecture FirstProgram/015
Examining registers for the result of program execution CS 286 Computer Organization and Architecture FirstProgram/016
The three components in your SPIM program (continued) CS 286 Computer Organization and Architecture FirstProgram/017
The three components in your SPIM program (continued) The results of program execution CS 286 Computer Organization and Architecture FirstProgram/018