/* -------------------------------------------------- Demo file for sumSquares function -------------------------------------------------- */ .global main, Stop, CodeEnd, DataStart, DataEnd .global Pause, sumSquares /* -------------------------------------------------- Begin of the program instructions -------------------------------------------------- */ .text main: /* ===================================================== Statement: z = sumSquares(4,7) ===================================================== */ /* ------------------------------------------------- Pass parameters in regs r0 and r1 ------------------------------------------------- */ /* ----------------------------------------------------------------- Save return value (in r0) to variable z (z = sumSquares(..)) ----------------------------------------------------------------- */ Pause: /* ===================================================== Statement: z = sumSquares(4,7) ===================================================== */ /* ------------------------------------------------- Pass parameters 4 and 7 in regs r0 and r1 ------------------------------------------------- */ /* ----------------------------------------------------------------- Save return value (in r0) to variable z (z = sumSquares(..)) ----------------------------------------------------------------- */ Stop: nop // Stop point of main( ) /* ---------------------------------------------------------------- Function sumSquares(a,b): agreed inputs: r0 = a, r1 = b agreed return: r0 = return value ---------------------------------------------------------------- */ sumSquares: // When sumSquares begin, we will have: r0 = a, r1 = b mul r2, r0, r0 // r2 = a*a mul r3, r1, r1 // r3 = b*b add r0, r2, r3 // r0 = a*a + b*b // The result value is now in r0 mov pc, lr // Return to the caller CodeEnd: nop /* -------------------------------------------------- Begin of the permanent program variables -------------------------------------------------- */ .data DataStart: x: .4byte 3 y: .4byte 4 z: .4byte -1 DataEnd: .end