#------------------------------------------------------------------------------- # Thomas C. Bressoud # 29 January 2007 # addAB.s # # Description: Simple first program that sinply adds two numbers together # and prints the result to the console #------------------------------------------------------------------------------- # Next directive defines additions to the data segment .data .align 2 ; Start on 16 byte boundary .globl A A: .long 25 ; Allocate a 4 byte data word .globl B B: .long 17 ; Allocate another 4 byte data word # Next directive defines additions to the text (code) segment .text .align 2 ; Start on a 16 byte boundary .globl _main ; Make the _main symbol visible outside this module _main: .line 25 ; Function prologue mflr r0 ; Put the return address from main into r0 stw r0,8(r1) ; Save in the linkage of the callers stack frame stwu r1,-32(r1) ; Allocate a new stack frame, updating the stack ptr ; Function body code ; Construct the address of A lis r9, ha16(A) ; Load high 16 bits of address of A lwz r4, lo16(A)(r9) ; and low 16 bits of address lwz r5, lo16(B)(r9) add r3,r4,r5 bl _println_int ; Function epilogue addi r1, r1, 32 lwz r0, 8(r1) mtlr r0 blr