Main | Assembly Programming | Input/Output | Memory | Computer Architecture | Advanced Topics |
Consider the assembly in (i), which implements the C-code factorial function in (ii).
(i)
003000: FACT link a6,#0 003004: tst.l 8(a6) 003008: bne NEXT 00300c: move.l #1,d0 003012: bra DONE 003016: NEXT move.l 8(a6),d0 00301a: subq.l #1,d0 00301c: move.l d0,-(a7) 00301e: bsr FACT 003022: addq.l #4,a7 003024: mulu.w 8(a6),d0 003028: DONE unlk a6 00302a: rts |
(ii)
int factorial(int x){ if (x == 0){ return 1; } return x * factorial(x-1); } |
Memory:
|
Resisters: a7: $24C a6: $254 PC: $3000 |
|
Registers: a7: a6: |
|
Registers: a7: $230 a6: $230 |