Function Calls (with CCC Protocol)
Function sum
Based on the CCC protocol for function calls, function sum
-
expects two integers parameters as input and
-
returns the sum of these integers
Complete the following code fragment to do the job:
.equ ZERO, 0 .equ RIP, 1 .equ RSP, 3 .equ CALL, 4 .equ LOCAL1, 8 .equ LOCAL2, 9 .macro stack_init orq %ZERO, %ZERO, %RSP .endm .macro pushq REG subq $8, %RSP, %RSP movq \REG, (%RSP) .endm .macro popq REG movq (%RSP), \REG addq $8, %RSP, %RSP .endm .macro set VAL, REG orq \VAL, %ZERO, \REG .endm .macro enter VAL set \VAL, %LOCAL1 pushq %LOCAL1 .endm .macro call FUNC # your code here .endm .data res: .quad .text stack_init # your code here
Computing the factorial recursively
Write a function factorial that computes the factorial of a unsigned quad-word integer recursively