120 likes | 359 Views
ENGR 330: Today’s Class. Questions/issues? In-class Exam next week – more on Wed. Cliffhanger on procedure calls MIPS Simulator Memory and register use Principles and Pitfalls IF time: what is floating point? (Chapter 3). Cliffhanger. The scene: We’ve called a subroutine from Main.
E N D
ENGR 330: Today’s Class • Questions/issues? • In-class Exam next week – more on Wed. • Cliffhanger on procedure calls • MIPS Simulator • Memory and register use • Principles and Pitfalls • IF time: what is floating point? (Chapter 3) R. Smith - University of St Thomas - Minnesota
Cliffhanger • The scene: • We’ve called a subroutine from Main. • The return address was stored in $ra • Now we’re calling ANOTHER subroutine • How are we ever getting back to Main?? R. Smith - University of St Thomas - Minnesota
Words that are interchangeable • (more or less, at this architectural level) • Procedure • Function • Subroutine • Method R. Smith - University of St Thomas - Minnesota
MIPS Simulator • Don’t Panic • Dr. Jalkio assures me you’ve suffered enough • No more ASM assignments (well, this semester anyway) • Except maybe when we do C (I’ll look into it) • There are many simulators • They’re all lame in one way or another • But interesting features worth looking at here • PCSPIM • Blurs the line between ASM and machine language • Already a problem with the MIPS R. Smith - University of St Thomas - Minnesota
Memory map elements • Code/text • Global variables • Dynamic allocation space • Stack space R. Smith - University of St Thomas - Minnesota
Weird MIPS stuff that matters • .data versus .text • Stack space, local variables, global variables • Dedicated general registers • See above: stack, fp, global pointer • Reserved for the OS kernel – contents may change at any time • Procedure temporary variables – trashed by subroutine calls • Saved temporary variables • If you use it, you save it first and restore it before returning • You can assume other subroutines won’t trash it • Arguments passed to subroutines • Procedure results returned from subroutines • ASM temporary variables R. Smith - University of St Thomas - Minnesota
Mapping it to C or Java • Globals – defined outside of methods • Point $gp at the start of the global area • Int add2(arg1, arg2) • { • Int local1, local2; • } • Add2 is a function • Collect arg1, arg2 into $a1, $a2 • Save current $rp on the stack • Save $s registers on the stack • Make stack space for local1, local2 (“automatic variables”) • Point $fp at the stack space for local1, local2 • Put result of add2 in $v0 • Restore saved registers and $rp • Return by jr $rp R. Smith - University of St Thomas - Minnesota
Loading and Relocating • Loading a single program to the same spot • Loading in unpredictable spots • PC relative – great, but not enough • Relocation via patching – ‘object’ format R. Smith - University of St Thomas - Minnesota
Instruction set design principles • From P & H, Chapter 2 • Simplicity favors regularity – 1 instruction size, arithmetic on registers, register spec in same instruction location • Smaller is faster – 32 registers instead of 64, instruction size • Make the common case fast – PC relative on conditional branches, branch on equal, constants in immediate instrs. • Good design demands good compromises – how to handle larger addresses and offsets while keeping instructions a single size R. Smith - University of St Thomas - Minnesota
Fallacies and Pitfalls • More powerful instructions = higher performance • ASM programming achieves highest performance • Sequential word addresses on byte addressable machines: not by 1 • Pointers to automatic variables outside of the defining procedure R. Smith - University of St Thomas - Minnesota
What is Floating Point? • Double vs Float • Parts • Matissa • Exponent • Signs • Overflow • Underflow • Loss of precision R. Smith - University of St Thomas - Minnesota