Upgrade to remove ads

This preview shows page 1-2-3 out of 10 pages.

Save
View Full Document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Upgrade to remove ads
Unformatted text preview:

Programming Studio #7 ECE 190Programming Studio #7 • Concepts this week: • TRAP Instructions + MP3.1 Demo • Subroutines + MP3.1 Demo • MP3 Q&AAnnouncements • Exam 1 Regrade Requests • Written part request due TODAY by 5PM in Everitt Drop Box • Programming part extended, due MONDAY by 5PM via email to [email protected] • HW 2 Regrade Requests • Due TODAY by 5PM • MP1 Functionality Grades on Compass • No regrades on functionality • EXAM 2 CONFLICT REQUESTS, ON COMPASS, DUE THIS MONDAY 5PM. NO EXTENSIONS, NO EXCEPTIONS.TRAP Service Routines • TRAP Routines are provided by the Operating System and called by a User program to perform a specific task • Uses the TRAP instruction to call a TRAP Routine TRAP 1111 0000 trapvect8 • trapvect8 is an 8-bit offset – Used to determine the starting address of a TRAP routine – Trap vector table is in memory locations x0000 through x00FF and contains starting addresses of the TRAP routines – How many possible traps are there? • When a TRAP instruction is used, R7 is loaded with the current contents of PC, and PC is loaded with the address of the TRAP routine – Why? – When the TRAP routine is completed, PC is loaded with the value stored in R7 and control is returned to the user program – What does this mean about using R7 as a general purpose register now?TRAP Routines Trap vector Assembler Name Description x20 GETC Read one character from keyboard into R0[7:0] and clear R0[15:8]; doesn’t echo x21 OUT Write R0[7:0] to display x22 PUTS Display string from subsequent locations starting at mem[R0] until x0000 (null character) in a location x23 IN Print a prompt, read a character from the keyboard into R0 like GETC, echo character x24 PUTSP Display string from subsequent locations starting at mem[R0], with 2-chars per location, bits [7:0] first, then [15:8] until x0000 in a location; [15:8] = x00 if odd length x25 HALT Halt execution and print message (In appendix A: table A.2)TRAP Example: echo again .ORIG x3000 LEA R0, MSG TRAP x22 ; PUTS LOOP TRAP x20 ; GETC TRAP x21 ; OUT BRnzp LOOP MSG .STRINGZ "User Input: " .ENDSubroutines • Subroutines allow us to write a piece of code once, and execute it several time throughout a program • Use JSR(R) instruction to jump to a subroutine JSR 0100 1 PCOffset11 JSRR 0100 0 00 baseReg 000000 • When a JSR(R) instruction is executed the return address is stored in R7, and PC is loaded with the address of the subroutine – Bit 11 of JSR(R) determines the addressing mode – PC-relative or Base Register • Use RET (JMP R7) instruction to return to caller functionSubroutine: CLEAR_BOARD CLEAR_BOARD ST R0, SAVE_R0 ST R1, SAVE_R1 ... ST R6, SAVE_R6 ST R7, SAVE_R7 ... ; Do stuff LD R0, SAVE_R0 LD R1, SAVE_R1 ... LD R6, SAVE_R6 LD R7, SAVE_R7 RET • IMPORTANT: Subroutines should not clobber registers! • Save/Restore any registers used in the subroutine besides the register used to hold a return value • Do not clobber R7! Your code WILL fail! • Callee vs. caller saveFull Example • To demonstrate the use of TRAP routines and subroutines in a program, let’s take a look at the MAIN and CLEAR_BOARD files for MP3. • wget <URL for mp3.zip> • mp3.asm • Illustrates TRAPs, JSRR • Step through code in DEBUGGER to see what happens to R7 when a TRAP (GETC) is called. • clear.asm • Illustrates callee saved codeMP3: Conway's Game of Life • The “Life” board used in this MP is a 16x16 board (256 total cells). • Any two cells are neighbors if they share a border, and each cell has eight neighbors. • When iterating through the “Life” game, each cell lives or dies depending on rules published in handout. • DEMO


View Full Document
Download Programming Studio
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Programming Studio and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Programming Studio 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?