4b. ARM architecture_part 2_new
4b. ARM architecture_part 2_new
Department of CSE
2024-25 Even semester
Contents
• Decoding (Hex to Assembly)
• Condition codes
• Procedures
• B L1
• ADD X10,X11,X12 //Skipped
• L1 : SUBX10,X11,X12
X9 X9
1 0
a in X22, b in X23
Exit:
Exit:
• Stack
• used to store the data of additional registers as needed by the procedure.
• Once procedure completes the use of the register, the data from stack will be replaced
in the register – Leave no trace of using the register.
Step 1: Save registers X19, temporary registers (X9 and X10) into stack
// adjust stack to make room for 3 items
SUBI SP, SP, #24
STUR X10, [SP,#16]
STUR X9, [SP,#8]
STUR X19, [SP,#0]
• Argument n in X0
• Result in X1
Step 5: Next, the value register X1 gets the product of old argument X0 and the
current value of the value register.
• MUL X1,X0,X1 // return n * fact (n − 1)
• The stack is adjusted to make room for all the saved registers and any
memory-resident local variables.
• Stable frame pointer
• If there are no local variables on the stack within a procedure, the compiler
will save time by not setting and restoring the frame pointer.
• When a frame pointer is used, it is initialized using the address in SP on a
call, and SP is restored using FP.
10-01-2025 Dept of CSE, Amrita School of Computing, Coimbatore 54
Working of SP and FP:
• When a function is called:
• The current SP is pushed onto the
stack.
• The value of the current FP is also
pushed onto the stack.
• The SP is updated to point to the new
stack frame.
• The FP is set to the current SP value,
marking the beginning of the current
function's stack frame