0
0
ARM Architectureknowledge~10 mins

Recursive function in assembly in ARM Architecture - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the base case check in a recursive factorial function.

ARM Architecture
cmp r0, [1]
beq end_factorial
Drag options to blanks, or click blank then click option'
A#1
B#0
Cr1
Dr2
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with 1 instead of 0 for the base case.
Using a register instead of an immediate value in the compare instruction.
2fill in blank
medium

Complete the code to decrement the argument register before the recursive call.

ARM Architecture
sub r0, r0, [1]
Drag options to blanks, or click blank then click option'
A#1
Br1
Cr2
D#0
Attempts:
3 left
💡 Hint
Common Mistakes
Subtracting 0 or a register instead of 1.
Using the wrong register as the source or destination.
3fill in blank
hard

Fix the error in the recursive call instruction to correctly branch to the factorial function.

ARM Architecture
bl [1]
Drag options to blanks, or click blank then click option'
Afactorial
Bfactor
Cfact
Dfact_recursive
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect or partial label name for the branch.
Misspelling the function label.
4fill in blank
hard

Fill both blanks to multiply the current argument with the result of the recursive call.

ARM Architecture
mul r0, r0, [1]
mov [2], r0
Drag options to blanks, or click blank then click option'
Ar1
Br0
Cr2
Dr3
Attempts:
3 left
💡 Hint
Common Mistakes
Multiplying by the wrong register.
Moving the result to the wrong register.
5fill in blank
hard

Fill all three blanks to correctly save and restore the link register around the recursive call.

ARM Architecture
push [1]
bl factorial
pop [2]
mov [3], r0
Drag options to blanks, or click blank then click option'
A{lr}
Cr1
Dr0
Attempts:
3 left
💡 Hint
Common Mistakes
Not saving or restoring the link register.
Using the wrong registers in push/pop instructions.