CPE225 Final
C Compiler
1. Preprocessor - handles instructions for the compiler 2. compiler - translates C into assembly or machine instructions, produces object files 3. linker - combines object files into an executable
Steps to a Caller setup
1. Push arguments in the reverse order? 2. Call the subroutine
Steps to a caller setup
1. Push space for a return value 2. Push the return address (R7) 3. Push the dynamic link (R5) 4. Set up the new frame pointer which points at the first local variable 5. Push the local variables
Stack Frames
1. arguments passed 2. return value 3. return address (in R7) 4. dynamic link (in R5) 5. local variables stores DATA not information
How do you call subroutines?
1. need to place it's expected arguments 2. know where to find the return values 3. starting address of subroutine JSR subroutine
What are the steps of a trap (system call)?
1. push the PSR on the supervisor stack 2. push the PC onto the supervisor stack 3. set bit 15 of PSR to '0' 4. zero-extend (not as important) 5. load value at address into PC
How many levels of priorities does the LC3 have?
8 - from PL0-PL7
What are the different types of TRAPs?
GETC - gets character OUT - outputs a character PUTS - puts a string HALT - indicates the end of program data, afterwards are usually labels to store data
For JSR & JSRR, where is the pc value placed?
Into R7. JSR is pc related whereas JSRR is register based, putting the data into whatever register is called after JsRR
stack
LIFO , push, pop, peek
Are all subroutines pure functions? Are all functions subroutines?
NO, but all functions are subroutines
RTI
Return from trap or interrupt. Pops PC and PSR off supervisor stack if PSR is '0' (unconditional). Can only be executed in supervisor mode
RET
Returns from subroutine
What are the three types of registers in I/O devices?
Status register: provides info ABOUT the device Data register: transfers data TO AND FROM device Control register: provides instructions TO device
T or F Devices can only interrupt programs of lower priority
True -- the Priority encoder is responsible for checking to see if the device has a higher priority than the running program
T or F: C is a statically typed language?
True because all the variables' types must be known before runtime.
Supervisor Stack
Where the PC and PSR are saved to store and restore the state of the program. Stack pointer is automatically set in R6.
Service routine
a System call, aka TRAP
Interrupts
allows a device to notify CPU of an event. The Polling constantly checks for something. Interrupts only happen when triggered
header file
contains information shared among source files
Interpretation in programming languages
executes high level instructions, translates them into machine instructions AS the program is executed. Must be translated everytime it is executed.
In C, what are the 4 commonly used types?
int, double, char, void. Note: int guarantees 4 bytes
Array
is an ordered collection of elements of fixed size, Where each element is associated With an index
Zero extension
occurs when narrow unsigned type is converted to fit width of wider type ( EX: 1101 0010 --> 0000 0000 1101 0010 )
Process Status Register
privilege: the right to execute certain operations. Are instructions that can only be run by operating system. --> LC3 has one privilege instruction priority: the urgency of the operation
Subroutine
sequence of instructions that can be Called as a single unit as part of a larger program . Are also called procedures
Function protoypes
specifies the return and argument types. Compiler must know these types before function is called. example: int sum(int n) -- prototype int main(){ sum(5); } sum function defined here...
Trap Vector Table
stored in memory location x0000-x00ff that keeps track of the starting address of each service routine.
What are Interrupt Service Routines?
subroutines that handle interrupts. The starting address of each routine is stored in the Interrupt Vector table
What is the processor state?
the information needed to resume an interrupted task --> for LC3: PC, PSR, Register
Compilation in programming lanaguges
translates high level program into machine instructions. Is faster than interpreter. Must be re-compiled for each architecture but does not need to be translated into machine instructions each time program is executed (unlike intepretation)