high level to assembly let see the simplest program compiled into assembly main() a = 0 the output is: (ignore the symbol/data section) ... .code 0 mov fp #3500 mov sp #3000 jal rads main *** call main trap r0 #0 *** stop :main st r1 @1 fp add fp fp #2 st rads @0 fp mov r1 #0 *** a = 0 :L101 ld rads @0 fp sub fp fp #2 ld r1 @1 fp ret rads .end note to access frame, we use addressing with offset (disp) ld r1 @d r2 R[r1] = M[ R[r2] + d] st r1 @d r2 M[ R[r2] + d] = R[r1] The runtime stack is created. :main st r1 @1 fp add fp fp #2 st rads @0 fp *** create frame ld rads @0 fp sub fp fp #2 ld r1 @1 fp *** delete frame ret rads when a function is called, it creates a "frame" to store the "return point" and local variables. in the above example, fp points to the current frame, the return point (rads) is stored at the slot 0. local var r1 ("a") is stored at the slot 1. a frame looks like this memory stack grows downward ---- <- fp' r1 fp-1 (main) retads fp+0 <- fp ----- let us see a call to a user defined function double(x) return x + x main() a = double(2) its assembly language is: .code 0 :double st r1 @1 fp st r2 @2 fp add fp fp #3 st rads @0 fp pop sp r1 *** get actual parameter x add r2 r1 r1 *** tmp = x + x mov retval r2 *** return tmp ... ld rads @0 fp sub fp fp #3 ld r2 @2 fp ld r1 @1 fp *** delete frame ret rads :main ... mov r2 #2 push sp r2 *** pass x to double jal rads double .... ret rads .end double() has two local vars r1 (x) and r2 (tmp). it accepts the passing value (x) from stack frames look like this: ---- r1 (main) retads ----- r1 fp-2 (double) r2 fp-1 retads fp+0 <- fp ----- Now let us see how to access an array ax[10] main() ax[1] = 22 its assembly is: .symbol ax 1100 *** compiler allocate ax at 1100 .code 0 :main ... mov r1 #22 mov r2 #1 st r1 @ax r2 *** ax[1] = 22 ... .end