CS计算机代考程序代写 prolog proc: deca r5 # callee prologue \ (allocate space for ra)

proc: deca r5 # callee prologue \ (allocate space for ra)
st r6, (r5) # callee prologue / (store ra)

ld 8(r5), r1 # r1 = a1
beq r1, L0 # if(a1 == 0) goto L0

La: dec r1 # r1 = a1-1
ld 4(r5), r2 # r2 = a0

deca r5 # caller prologue \ (allocate 8 bytes for two arguments)
deca r5 # caller prologue /
st r2, (r5) # a0 = r2 for call
st r1, 4(r5) # a1 = r1 for call
gpc $6, r6 # r0 = proc(r2, r1)
j proc # (note: we do not split basic blocks after a function call)
inca r5 # caller epilogue \ (deallocate two arguments)
inca r5 # caller epilogue /

ld 4(r5), r2 # r2 = a0
ld 8(r5), r1 # r1 = a1
dec r1 # r1 = a1 – 1
ld (r2,r1,4), r1 # r1 = a0[a1-1]
add r1, r0 # r0 = r0 + r1
br L1 # goto L1

L0: ld $0, r0 # r0 = 0

L1: ld (r5), r6 # callee epilogue \ (restore value of ra)
inca r5 # callee epilogue / (deallocate ra)
j (r6) # return to caller

# basic block connections:
# proc -> L0 (beq)
# proc -> La (!beq)
# La -> L1
# L0 -> L1