Lecture 4 - ARM Architecture
Lecture 4 - ARM Architecture
Department of CSE
2024-25 Even semester
Contents
• ARM processor
• Registers and operands
• Instruction formats
• X8: Indirect result location register (hold the memory address where the result should be
stored.)
• X9 – X15: Temporaries storage. (When the CPU needs to quickly hold data during
calculations, it uses these registers.)
• Case: the load register instruction must specify two registers and a constant.
• If the address were to use one of the 5-bit fields in the format above, the
largest constant within the load register instruction would be limited to only
25−1 or 31.
• Array size is limited.
• Conflict between the desire to keep all instructions the same length and the
desire to have a single instruction format.
SUB: 1624
Load/store instructions
Rn: base register
Address: constant offset from contents of base register
(+/- 32 doublewords)
Rt: destination (load) or source (store) register number
Op2: 0 always
LDUR opcode: 1986, STUR opcode : 1984
What is the LEGv8 machine language code for these three instructions?
• Answer : 4 option
SUB X9,X22,X23 // X9 = i − j
CBNZ X9, Else // go to Else if i ≠ j (X9 ≠ 0)
ADD X19,X20,X21 // f = g + h (skipped if i ≠ j)
B Exit // go to Exit
Else: SUB X19,X20,X21 // f = g − h (skipped if i = j)
Exit:
Loop:
ADD X1, X1, #1 // Increment i: i = i + 1
MOV X0, #0 // Initialize sum = 0 (X0 register holds ADD X0, X0, X1 // Add i to sum: sum = sum + i
sum) SUB X3, X1, X2 // Calculate (i - upper limit)
MOV X1, #0 // Initialize i = 0 (X1 register holdsCBZ
i) X3, Exit // If (i - upper limit) == 0, exit the
MOV X2, #10 // Set the upper limit 10 (X2 loop
register) B Loop // Otherwise, repeat the loop
Loop: Exit:
ADD X1, X1, #1 // Increment i: i = i + 1 // Loop complete. The result is in X0 (sum)
ADD X0, X0, X1 // Add i to sum: sum = sum + i
SUB X3, X2, X1 // Calculate (upper limit - i)
CBNZ X3, Loop // If (upper limit - i) != 0, continue
the loop
26-12-2024
Exit: Dept of CSE, Amrita School of Computing, Coimbatore 62
Question
Opcode:
Add:
Sub:
Branch:
Unconditional branch:
Immediate: