//------------------------- add -------------------------
.data				; data section 
.text				; code section 
.globl _add 
_add: 
 
//FUNCTION INIT
mflr r0     //save caller address into r0
stw r1, -256(r1)     //save old sp on top of stack
subi r1, r1, 256     //create frame, move sp to 'top' of stack (256 bytes)
stmw r14, 16(r1)     //save registers r14-r32 onto stack (72 bytes)
stw r0, 8(r1)	    //save return address onto stack
 
//FUNCTION BODY
//RETURN STATEMENT
mr r14, r3     //moving parameter into temporary register
mr r15, r4     //moving parameter into temporary register
add r14, r14, r15     //add two registers
mr r3, r14   //move temporary value into return register (r3)
ba L_END0:     //jump to function return
//FUNCTION END
 
L_END0:     //end label
lwz r0, 8(r1)    //get the caller's link address
mtlr r0     //move address into link register (r0)
lmw r14, 16(r1)     //restore registers r14-r32
lwz r1,0(r1)     //set the original stack pointer
blr     //branch link register


//------------------------- add2 -------------------------
.data				; data section 
.text				; code section 
.globl _add2 
_add2: 
 
//FUNCTION INIT
mflr r0     //save caller address into r0
stw r1, -256(r1)     //save old sp on top of stack
subi r1, r1, 256     //create frame, move sp to 'top' of stack (256 bytes)
stmw r14, 16(r1)     //save registers r14-r32 onto stack (72 bytes)
stw r0, 8(r1)	    //save return address onto stack
 
//FUNCTION BODY
//RETURN STATEMENT
//FUNCTION CALL
mr r15, r3   //saving function parameter before next function call
mr r16, r4   //saving function parameter before next function call
mr r17, r3     //moving parameter into temporary register
mr r3, r17   //loading argument into register before function call
mr r18, r4     //moving parameter into temporary register
mr r4, r18   //loading argument into register before function call
bl _add     //call function
mr r14, r3     //store return value into register for future use
mr r3, r15   //restore function parameter
mr r4, r16   //restore function parameter
//FUNCTION CALL
mr r16, r3   //saving function parameter before next function call
mr r17, r4   //saving function parameter before next function call
mr r18, r3     //moving parameter into temporary register
mr r3, r18   //loading argument into register before function call
mr r19, r4     //moving parameter into temporary register
mr r4, r19   //loading argument into register before function call
bl _add     //call function
mr r15, r3     //store return value into register for future use
mr r3, r16   //restore function parameter
mr r4, r17   //restore function parameter
add r14, r14, r15     //add two registers
mr r3, r14   //move temporary value into return register (r3)
ba L_END1:     //jump to function return
//FUNCTION END
 
L_END1:     //end label
lwz r0, 8(r1)    //get the caller's link address
mtlr r0     //move address into link register (r0)
lmw r14, 16(r1)     //restore registers r14-r32
lwz r1,0(r1)     //set the original stack pointer
blr     //branch link register


//------------------------- even -------------------------
.data				; data section 
.text				; code section 
.globl _even 
_even: 
 
//FUNCTION INIT
mflr r0     //save caller address into r0
stw r1, -256(r1)     //save old sp on top of stack
subi r1, r1, 256     //create frame, move sp to 'top' of stack (256 bytes)
stmw r14, 16(r1)     //save registers r14-r32 onto stack (72 bytes)
stw r0, 8(r1)	    //save return address onto stack
 
//FUNCTION BODY
 
//IF STATEMENT
mr r14, r3     //moving parameter into temporary register
li r15, 2     //loading immediate value into register
divw r14, r14, r15     //divide two registers
li r15, 2     //loading immediate value into register
mullw r14, r14, r15     //multiply two registers
mr r15, r3     //moving parameter into temporary register
cmpw r14, r15     //compare two registers
beq L0     //if equal
li r14, 0     //fell through, store 0 in result (false)
ba L1     //jump to boolean evaluation end
L0:     //evaluated true
li r14, 1     //store 1 (true)
L1:     //end boolean evaluation
cmpwi r14, 0     //compare register to 0 (check if false)
beq L2     //if false, jmp to else label
//RETURN STATEMENT
li r14, 1     //loading immediate value into register
mr r3, r14   //move temporary value into return register (r3)
ba L_END2:     //jump to function return
ba L3:     //jump to end label (skip over else)
L2:     //else block
//RETURN STATEMENT
li r14, 0     //loading immediate value into register
mr r3, r14   //move temporary value into return register (r3)
ba L_END2:     //jump to function return
L3:     //end if
//END IF STATEMENT
//FUNCTION END
 
L_END2:     //end label
lwz r0, 8(r1)    //get the caller's link address
mtlr r0     //move address into link register (r0)
lmw r14, 16(r1)     //restore registers r14-r32
lwz r1,0(r1)     //set the original stack pointer
blr     //branch link register


//------------------------- slow_pow -------------------------
.data				; data section 
.text				; code section 
.globl _slow_pow 
_slow_pow: 
 
//FUNCTION INIT
mflr r0     //save caller address into r0
stw r1, -256(r1)     //save old sp on top of stack
subi r1, r1, 256     //create frame, move sp to 'top' of stack (256 bytes)
stmw r14, 16(r1)     //save registers r14-r32 onto stack (72 bytes)
stw r0, 8(r1)	    //save return address onto stack
 
//FUNCTION BODY
li r14, 1     //loading immediate value into register
stw r14, 88(r1)     //save temporary value into stack[stackoffset] (local var)
 
//LOOP START
li r14, 1     //loading immediate value into register
mr r15, r4     //moving parameter into temporary register
L4:     //for loop start.
stw r14, 92(r1)     //save loop variant into local var on stack
cmpw r14, r15     //compare loop variant to end condition (value)
bgt L5:     //is equal, for loop complete.  Jump to loop escape
addi r14, r14, 1     //falls through if loop continues, increment loop variant.
lwz r17, 88(r1)     //copying local var (on stack) into register
mr r18, r3     //moving parameter into temporary register
mullw r17, r17, r18     //multiply two registers
stw r17, 88(r1)     //save temporary value into stack[stackoffset] (local var)
ba L4:     //jump to top of loop.
L5:     //loop escape.
//LOOP END
//RETURN STATEMENT
lwz r14, 88(r1)     //copying local var (on stack) into register
mr r3, r14   //move temporary value into return register (r3)
ba L_END3:     //jump to function return
//FUNCTION END
 
L_END3:     //end label
lwz r0, 8(r1)    //get the caller's link address
mtlr r0     //move address into link register (r0)
lmw r14, 16(r1)     //restore registers r14-r32
lwz r1,0(r1)     //set the original stack pointer
blr     //branch link register


//------------------------- fib -------------------------
.data				; data section 
.text				; code section 
.globl _fib 
_fib: 
 
//FUNCTION INIT
mflr r0     //save caller address into r0
stw r1, -256(r1)     //save old sp on top of stack
subi r1, r1, 256     //create frame, move sp to 'top' of stack (256 bytes)
stmw r14, 16(r1)     //save registers r14-r32 onto stack (72 bytes)
stw r0, 8(r1)	    //save return address onto stack
 
//FUNCTION BODY
li r14, 1     //loading immediate value into register
li r15, 0     //loading immediate value into register
mulli r15, r15, 4     //multiply index by 4 (bytes)
addi r15, r15, 92     //add stack offset and index
stwx r14, r15, r1     //save value into stack[stackoffset+index]
li r14, 1     //loading immediate value into register
li r15, 1     //loading immediate value into register
mulli r15, r15, 4     //multiply index by 4 (bytes)
addi r15, r15, 92     //add stack offset and index
stwx r14, r15, r1     //save value into stack[stackoffset+index]
 
//LOOP START
li r14, 2     //loading immediate value into register
mr r15, r3     //moving parameter into temporary register
L6:     //for loop start.
stw r14, 136(r1)     //save loop variant into local var on stack
cmpw r14, r15     //compare loop variant to end condition (value)
bgt L7:     //is equal, for loop complete.  Jump to loop escape
addi r14, r14, 1     //falls through if loop continues, increment loop variant.
lwz r18, 136(r1)     //copying local var (on stack) into register
li r19, 1     //loading immediate value into register
sub r18, r18, r19     //subtract two registers
mulli r18, r18, 4     //multiply index by 4 (bytes)
addi r18, r18, 92     //add variable stack offset plus index
lwzx r17, r18, r1     //copying single index of local array var (on stack) into register
lwz r19, 136(r1)     //copying local var (on stack) into register
li r20, 2     //loading immediate value into register
sub r19, r19, r20     //subtract two registers
mulli r19, r19, 4     //multiply index by 4 (bytes)
addi r19, r19, 92     //add variable stack offset plus index
lwzx r18, r19, r1     //copying single index of local array var (on stack) into register
add r17, r17, r18     //add two registers
lwz r18, 136(r1)     //copying local var (on stack) into register
mulli r18, r18, 4     //multiply index by 4 (bytes)
addi r18, r18, 92     //add stack offset and index
stwx r17, r18, r1     //save value into stack[stackoffset+index]
ba L6:     //jump to top of loop.
L7:     //loop escape.
//LOOP END
//RETURN STATEMENT
mr r15, r3     //moving parameter into temporary register
mulli r15, r15, 4     //multiply index by 4 (bytes)
addi r15, r15, 92     //add variable stack offset plus index
lwzx r14, r15, r1     //copying single index of local array var (on stack) into register
mr r3, r14   //move temporary value into return register (r3)
ba L_END4:     //jump to function return
//FUNCTION END
 
L_END4:     //end label
lwz r0, 8(r1)    //get the caller's link address
mtlr r0     //move address into link register (r0)
lmw r14, 16(r1)     //restore registers r14-r32
lwz r1,0(r1)     //set the original stack pointer
blr     //branch link register


//------------------------- fib2 -------------------------
.data				; data section 
.text				; code section 
.globl _fib2 
_fib2: 
 
//FUNCTION INIT
mflr r0     //save caller address into r0
stw r1, -256(r1)     //save old sp on top of stack
subi r1, r1, 256     //create frame, move sp to 'top' of stack (256 bytes)
stmw r14, 16(r1)     //save registers r14-r32 onto stack (72 bytes)
stw r0, 8(r1)	    //save return address onto stack
 
//FUNCTION BODY
li r14, 1     //loading immediate value into register
li r15, 0     //loading immediate value into register
mulli r15, r15, 4     //multiply index by 4 (bytes)
stwx r14, r15, r3     //save value into ptr[index]
li r14, 1     //loading immediate value into register
li r15, 1     //loading immediate value into register
mulli r15, r15, 4     //multiply index by 4 (bytes)
stwx r14, r15, r3     //save value into ptr[index]
 
//LOOP START
li r14, 2     //loading immediate value into register
mr r15, r4     //moving parameter into temporary register
L8:     //for loop start.
stw r14, 88(r1)     //save loop variant into local var on stack
cmpw r14, r15     //compare loop variant to end condition (value)
bgt L9:     //is equal, for loop complete.  Jump to loop escape
addi r14, r14, 1     //falls through if loop continues, increment loop variant.
lwz r18, 88(r1)     //copying local var (on stack) into register
li r19, 1     //loading immediate value into register
sub r18, r18, r19     //subtract two registers
mulli r18, r18, 4     //multiply index by 4 (bytes)
lwzx r17, r18, r3     //copying single index of local array var (on stack) into register
lwz r19, 88(r1)     //copying local var (on stack) into register
li r20, 2     //loading immediate value into register
sub r19, r19, r20     //subtract two registers
mulli r19, r19, 4     //multiply index by 4 (bytes)
lwzx r18, r19, r3     //copying single index of local array var (on stack) into register
add r17, r17, r18     //add two registers
lwz r18, 88(r1)     //copying local var (on stack) into register
mulli r18, r18, 4     //multiply index by 4 (bytes)
stwx r17, r18, r3     //save value into ptr[index]
ba L8:     //jump to top of loop.
L9:     //loop escape.
//LOOP END
//RETURN STATEMENT
mr r15, r4     //moving parameter into temporary register
mulli r15, r15, 4     //multiply index by 4 (bytes)
lwzx r14, r15, r3     //copying single index of local array var (on stack) into register
mr r3, r14   //move temporary value into return register (r3)
ba L_END5:     //jump to function return
//FUNCTION END
 
L_END5:     //end label
lwz r0, 8(r1)    //get the caller's link address
mtlr r0     //move address into link register (r0)
lmw r14, 16(r1)     //restore registers r14-r32
lwz r1,0(r1)     //set the original stack pointer
blr     //branch link register


//------------------------- recurse -------------------------
.data				; data section 
.text				; code section 
.globl _recurse 
_recurse: 
 
//FUNCTION INIT
mflr r0     //save caller address into r0
stw r1, -256(r1)     //save old sp on top of stack
subi r1, r1, 256     //create frame, move sp to 'top' of stack (256 bytes)
stmw r14, 16(r1)     //save registers r14-r32 onto stack (72 bytes)
stw r0, 8(r1)	    //save return address onto stack
 
//FUNCTION BODY
 
//IF STATEMENT
mr r14, r3     //moving parameter into temporary register
li r15, 0     //loading immediate value into register
cmpw r14, r15     //compare two registers
beq L10     //if equal
li r14, 0     //fell through, store 0 in result (false)
ba L11     //jump to boolean evaluation end
L10:     //evaluated true
li r14, 1     //store 1 (true)
L11:     //end boolean evaluation
cmpwi r14, 0     //compare register to 0 (check if false)
beq L12     //if false, jmp to else label
//RETURN STATEMENT
li r14, 0     //loading immediate value into register
mr r3, r14   //move temporary value into return register (r3)
ba L_END6:     //jump to function return
ba L13:     //jump to end label (skip over else)
L12:     //else block
//RETURN STATEMENT
//FUNCTION CALL
mr r15, r3   //saving function parameter before next function call
mr r16, r3     //moving parameter into temporary register
li r17, 1     //loading immediate value into register
sub r16, r16, r17     //subtract two registers
mr r3, r16   //loading argument into register before function call
bl _recurse     //call function
mr r14, r3     //store return value into register for future use
mr r3, r15   //restore function parameter
mr r15, r3     //moving parameter into temporary register
add r14, r14, r15     //add two registers
mr r3, r14   //move temporary value into return register (r3)
ba L_END6:     //jump to function return
L13:     //end if
//END IF STATEMENT
//FUNCTION END
 
L_END6:     //end label
lwz r0, 8(r1)    //get the caller's link address
mtlr r0     //move address into link register (r0)
lmw r14, 16(r1)     //restore registers r14-r32
lwz r1,0(r1)     //set the original stack pointer
blr     //branch link register


//------------------------- pow -------------------------
.data				; data section 
.text				; code section 
.globl _pow 
_pow: 
 
//FUNCTION INIT
mflr r0     //save caller address into r0
stw r1, -256(r1)     //save old sp on top of stack
subi r1, r1, 256     //create frame, move sp to 'top' of stack (256 bytes)
stmw r14, 16(r1)     //save registers r14-r32 onto stack (72 bytes)
stw r0, 8(r1)	    //save return address onto stack
 
//FUNCTION BODY
 
//IF STATEMENT
mr r14, r4     //moving parameter into temporary register
li r15, 0     //loading immediate value into register
cmpw r14, r15     //compare two registers
beq L14     //if equal
li r14, 0     //fell through, store 0 in result (false)
ba L15     //jump to boolean evaluation end
L14:     //evaluated true
li r14, 1     //store 1 (true)
L15:     //end boolean evaluation
cmpwi r14, 0     //compare register to 0 (check if false)
beq L16     //if false, jmp to else label
//RETURN STATEMENT
li r14, 1     //loading immediate value into register
mr r3, r14   //move temporary value into return register (r3)
ba L_END7:     //jump to function return
ba L17:     //jump to end label (skip over else)
L16:     //else block
L17:     //end if
//END IF STATEMENT
 
//IF STATEMENT
mr r14, r4     //moving parameter into temporary register
li r15, 1     //loading immediate value into register
cmpw r14, r15     //compare two registers
beq L18     //if equal
li r14, 0     //fell through, store 0 in result (false)
ba L19     //jump to boolean evaluation end
L18:     //evaluated true
li r14, 1     //store 1 (true)
L19:     //end boolean evaluation
cmpwi r14, 0     //compare register to 0 (check if false)
beq L20     //if false, jmp to else label
//RETURN STATEMENT
mr r14, r3     //moving parameter into temporary register
mr r3, r14   //move temporary value into return register (r3)
ba L_END7:     //jump to function return
ba L21:     //jump to end label (skip over else)
L20:     //else block
L21:     //end if
//END IF STATEMENT
 
//IF STATEMENT
//FUNCTION CALL
mr r15, r3   //saving function parameter before next function call
mr r16, r4   //saving function parameter before next function call
mr r17, r4     //moving parameter into temporary register
mr r3, r17   //loading argument into register before function call
bl _even     //call function
mr r14, r3     //store return value into register for future use
mr r3, r15   //restore function parameter
mr r4, r16   //restore function parameter
cmpwi r14, 0     //compare register to 0 (check if false)
beq L22     //if false, jmp to else label
//FUNCTION CALL
mr r15, r3   //saving function parameter before next function call
mr r16, r4   //saving function parameter before next function call
mr r17, r3     //moving parameter into temporary register
mr r3, r17   //loading argument into register before function call
mr r18, r4     //moving parameter into temporary register
li r19, 2     //loading immediate value into register
divw r18, r18, r19     //divide two registers
mr r4, r18   //loading argument into register before function call
bl _pow     //call function
mr r14, r3     //store return value into register for future use
mr r3, r15   //restore function parameter
mr r4, r16   //restore function parameter
stw r14, 88(r1)     //save temporary value into stack[stackoffset] (local var)
//RETURN STATEMENT
lwz r14, 88(r1)     //copying local var (on stack) into register
lwz r15, 88(r1)     //copying local var (on stack) into register
mullw r14, r14, r15     //multiply two registers
mr r3, r14   //move temporary value into return register (r3)
ba L_END7:     //jump to function return
ba L23:     //jump to end label (skip over else)
L22:     //else block
L23:     //end if
//END IF STATEMENT
//RETURN STATEMENT
mr r14, r3     //moving parameter into temporary register
//FUNCTION CALL
mr r16, r3   //saving function parameter before next function call
mr r17, r4   //saving function parameter before next function call
mr r18, r3     //moving parameter into temporary register
mr r3, r18   //loading argument into register before function call
mr r19, r4     //moving parameter into temporary register
li r20, 1     //loading immediate value into register
sub r19, r19, r20     //subtract two registers
mr r4, r19   //loading argument into register before function call
bl _pow     //call function
mr r15, r3     //store return value into register for future use
mr r3, r16   //restore function parameter
mr r4, r17   //restore function parameter
mullw r14, r14, r15     //multiply two registers
mr r3, r14   //move temporary value into return register (r3)
ba L_END7:     //jump to function return
//FUNCTION END
 
L_END7:     //end label
lwz r0, 8(r1)    //get the caller's link address
mtlr r0     //move address into link register (r0)
lmw r14, 16(r1)     //restore registers r14-r32
lwz r1,0(r1)     //set the original stack pointer
blr     //branch link register


