14
Lab 5 CSE141L

Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

Lab 5 

CSE141L 

Page 2: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

Announcements 

•  New lab due date policy – Assigned Friday – Due the next Friday or – Due Sunday night for 10% off. 

•  Applies to current Lab 4, and the Lab 5.  

Page 3: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

ClarificaHon About Memories 

Fifo  …

Fetch unit Back end

Instruction memory in fetch unit: 17 bits wide Accessible via special load/store instructions

Data memory in back end: 34 bits wide Accessible via normal load/store instructions

•  This is a Harvard Architecture – Easier for the lab, not how real machines work. 

Page 4: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

Lab 5 

•  Assembler •  Simulator 

Page 5: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

Assembler 1/2 

• Manually wriHng machine code  – Time consuming 

– Error prone – Monotonous – Hard to maintain 

– ….(bad bad bad) 

Why not Automate? 

Page 6: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

Assembler 2/2 

•  Inputs – A program source wriVen in your own assembly language 

– InstrucHon start address (entry point) – Data start address 

•  Outputs – $name_i.coe  ‐‐ instrucHons – $name_d.coe – data 

Page 7: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

*.coe  

• Why coe? – IniHalize vector format in Xilinx CoreGen 

– Your RAM modules will be iniHalized as specified in a *.coe file 

Page 8: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

The assembly process .text not_fibinacci: 

        la  $1, table0 

        lw  $2, $1         

        lw  $3, table0 

        lw  $4, 3(table0         lw  $5, 1($4) 

        sw  $5, 1($1) 

        li  $6, 0xC0FFEE 

.data 

   table0:         .word 0x002C0FFEE 

        .word table1 

   table1: 

        .word 0x0DEADBEEF 

        .word 0x4DEADBEEF,  0x42 

        .fill 10 0x0 

stack: .fill 1024 0x0

.text stub: li stack mov sp // really r1 in my ISA li table0 mov gp // really r2 in my ISA li 4 mov r4 // first arg by convention in my ISA call not_fibinacci out rv, 0 // rv is the “return value” in my ISA // tell us the function result

Assembler  asm –stub stub.s -src not_fib.s -data_addr

MEMORY_INITIALIZATION… MEMORY_INITIALIZATION…

not_fib_i.coe not_fib_d.coe stub.s

not_fib.s

Execution starts here @ 0x0

The assembler should fill in these constants.

Page 9: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

TesHng the Assembler 

•  Simple test cases –  Check output by hand. 

•  Lots of asserts() and error checking •  The simulator will help 

Page 10: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

Simulator 

•  Why? – verify your ISA  – debug your applicaHons – improve your ISA by spoeng performance boVlenecks in benchmark programs 

– Collect data about how your processor performs  ‐‐ what actually is the common case? 

•  Inputs – $name_i.coe – $name_d.coe 

•  Your simulator will have a command line interface for easy debugging 

Page 11: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

Simulator Commands 

Page 12: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

Simulator Algorithm 

Allocate and iniHalize architectural state While (1) { 

Setup; 

Read InstrucHon; Decode InstrucHon; Execute InstrucHon; 

Do command line interacHon; 

Page 13: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

Things to consider 

•  Both your assembler and simulator need to understand your ISA –  Best pracHce:  Use a single representaHon for the ISA, so the 

assembler and simulator cannot get out of sync. 

•  There are many sources of error in your system: –  Conceptual errors in the ISA –  Bugs in your implementaHon of your ISA 

–  Bugs in the simulator –  Bugs in the assembler 

–  Bugs and conceptual errors in your assembly program 

–  Debug carefully, and do lot of error checking!!!!  Detect errors early. –  E.g. Make sure all unused bits are zero. 

–  E.g. Fill all of memory a recognizable value or non‐executable instrucHon 

Page 14: Lab 5 - University of California, San Diegocseweb.ucsd.edu/classes/sp09/cse141L/Slides/2007-02-08... · 2007. 2. 8. · asm –stub stub.s -src not_fib.s -data_addr MEMORY_INITIALIZATION…

Notes 

•  You can use any language you like (even different ones for the assembler and simulator, if you like; ‐‐ Can you sHll use a single representaHon of your ISA)? 

•  You can share code for bit (un)packing and 34‐bit/17‐bit stuff, but nothing else.  You must credit your source. – We have provided some java code for this purpose.