230 likes | 336 Views
PseudoInstructions. 21 - Extended Assembler. Pseudoinstructions Instructions defined at assembly level Assembler translates to machine intsructions. Intent. Intent signaling instructions. Convenience. lw : Load word with label Sets up base address/offset. Convenience.
E N D
21 - Extended Assembler • Pseudoinstructions • Instructions defined at assembly level • Assembler translates tomachine intsructions
Intent • Intent signaling instructions
Convenience • lw : Load word with label • Sets up base address/offset
Convenience • sw : Store register to labeled memory
Load Address • la : Load Address • Get memory address of labeled item • Assembly pointer
Other Pseudo Tricks (23) • Immediate value impliesimmediate instruction • Convenience math/logic
Assembler Temporary Register • Instructions requiring multiple steps built using $1
Registers • Registers have meanings defined by convention • Can use memnonic names instead of numbers
Registers • Tips: • Avoid $0, $1and $26-$31 • $8-$25 safe for now :$t0-$t9 and $s0-$s7
24 – More Pseudo • Whole bunch o' branches and sets:
Indexed Addressing • Arrays last week: • Move baseaddress around
Unnatural • Offset/Base addressing ofteninconvenient • Indexed Addressing • Label(Offset)Array[i]
Arrays Now • Arrays now • Change offset, uselabel as baseaddress
Interrupts • Interrupt: signal to CPU that something needs to happen • Hardware Interrupts • Input/output ready • Ctrl-C • Code needs help • Trap from math overflow • Request for OS
Interrupt Handling • OS take over • Saves stateof running program • Runs interrupt handler • Restores state
22 - Syscalls • syscall: program generated interruptOperating System please do something • Use registers to send/receive information
Syscalls • Syscall codes:
MIPS cin / cout • Read and print integer:
More Syscalls • Properly end the program:
Print String • Strings usually longer than word • Live in memory, not registers • String syscalls need pointer to string : $a0 • Prints bytes until null char (00)
Read Print Int 3 Print promptand answermessages:
Read String • Read string code needs • Location to write to • Space available