#include .text .globl main main: /* Function prolog. */ /* Sets up environment for user program to execute. */ stwu r1,-32(r1) /* Make room on Stack for O/S values. */ mflr r0 /* Store O/S return address on Stack. */ stw r0,36(r1) stw r31,28(r1) /* Store O/S frame pointer on Stack. */ mr r31,r1 /* new stack top is now frame pointer. */ /* Start of your program. */ li r13, 0 /* r13 will be my grand total. Zero it.*/ loop: bl getnum /* Fetch an integer from the user. */ /* It is returned in r3. */ cmpwi r3, 0 /* if (r3 == 0) */ beq done /* then branch to done */ /* else add r3 to grand total. */ add r13, r13, r3 mr r3, r13 /* Grand total is first argument to */ bl printnum /* printnum() function. */ b loop /* Keep looping. */ done: /* End of your program. */ /* Function epilogue. */ /* Restores the environment from the O/S. */ lwz r11,0(r1) /* Restore O/S Stack pointer. */ lwz r0,4(r11) /* Restore O/S return address. */ mtlr r0 lwz r31,-4(r11) /* Restore O/S frame pointer. */ mr r1,r11 blr /* Return to Operating System. */