KANGA SPECIFICATION Kanga is a MIPS-oriented language. It is a lot like Spiglet, but with the following changes: 1) Instead of temporaries it uses 24 registers (s0,s1,s2,s3,s4,s5,s6,s7,a0,a1, a2,a3,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,v0,v1). that are also found on MIPS. 2) Call is now a statement, the return value of a call is returned in reg v0. How does a Call in Spiglet translate to Kanga? In Spiglet a call is an Exp: Call ::= "CALL" SimpleExp "(" ( Temp )* ")" but in Kanga a call is a Statement : CallStmt ::= "CALL" SimpleExp Also as you probably noticed there is no Register List to send arguments to the procedure you are calling. You need to use the 'a' register to send the arguments. If there are more than 4 arguments accepted by a procedure you need to use the PASSARG stmt which saves the args to locations with names SPILLEDARG 0 SPILLEDARG 1 etc. During the call of the procedure, one can load a value from such a location using ALOAD. Here is an example. The Spiglet Statement : MOVE TEMP 38 CALL TEMP 22( TEMP 23 TEMP 32 TEMP 33 TEMP 34 TEMP 35 ) will translate to the following code in Kanga: (Assuming after register allocation you have the following register assignment TEMP 23 = t0, TEMP 32 = t1, TEMP 33 = t3, TEMP 34 =t4, TEMP 35 =t5, TEMP 22 = t2 and TEMP 38 = t8.) MOVE a0 t0 # first move 4 args to a registers MOVE a1 t1 MOVE a2 t3 MOVE a3 t4 PASSARG 1 t5 # if there are more args save them to the stack. CALL t2 MOVE t8 v0 # the return value is in v0 3) A procedure is no longer a StmtExp but a StmtList. The return value is sent in register v0. 4) A procedure has three integers in its header like: procA [5] [3] [4] What do all these integers mean? The first integer 5 has the same meaning as the integer in Spiglet, i.e its the number of args taken by the procedure. The second integer is for the number of arguments that are saved on the stack in the procedure. The third integer is the maximum arguments a call uses in procA. i.e if procA makes a call to procB that takes 3 args, procC that takes 2 and procD that takes 4 args, then since 4 is the maximum args a call uses this integer is set to 4. 5) If all the registers are used up, arguments can be saved (spilled) on the stack using the ASTORE stmt.