ARMv8-A Architecture Flashcards
Which type of Architecture is ARMv8? (RISC or CISC)
RISC
Is the ARMv8 a Load/Store Machine?
Yes
How many registers does the Register file contain?
Register file contains 31 64-bit registers
Which data is manipulated by most instructions in the registers?
32-bit or 64-bit data
What are the 2 execution states of ARMv8 architecture?
AArch64 and AArch32
What does the AArch64 execution state use?
Uses the A64 Instruction set and 64-bit registers
What does the AArch32 execution state use?
Uses the A32 or T32 Instruction sets (provides computability with older ARM and THUMB instruction sets using 32-bit registers)
What are the ARMv8’s 4 exception levels
EL0 - for normal user apps with limited privileges EL1 - for the OS kernel EL2 - for a Hypervisor EL3 - Low-Level firmware
EL0
- Restricted access to a limited set of instructions and registers - Most programs work at this level
EL1
- Privileged access to instructions, registers and memory - Accessed indirectly by user programs using system calls - Lots of System registers accessible only in EL1 and used in OS kernel code
EL2
- Support virtualization, where the computer hosts multiple guest OSs, each on its own virtual machine
EL3
- Include the Secure Monitor
How many General-purpose registers does AArch64 have? What are they numbered as? When using all 64 bits, use? When using only the lower-order 32 bits, use?
31 64-bit wide general-purpose registers Numbered from 0 to 30 x or X (eXtended) w or W (Word)
Register uses: x0-x7 x8 x9-x15 x16-x17
x0 - x7: to pass args into a procedure and return results x8: indirect result location register x9 - x15: temp registers x16 - x17: intra-procedure-call temp registers (IP0, IP1)
Register uses: x18 x19-x28 x29 x30
x18: platform register x19 - x28: callee-savee registers (value is preserved by any function you call) x29: frame pointer (FP) register x30: procedure link register (LR)
Special-Purpose Registers: (Use/Types)
Stack Pointer - Points to top of run-time stack SP: 64-bit WSP: 32-bit Zero Register - Gives 0 value when read from and discards value when written to XZR: 64-bit WZR: 32-bit Program Counter - Holds address of currently executing instruction / Can’t be accessed directly as a named register / Is changed indirectly by branch and other instructions / Is used implicitly by PC-relative load/stores PC: 64-bit
How many floating-point registers are there?
32 128-bit wide floating-point registers
What is an immediate value and how can it be used?
An immediate value (a constant) may be used as final source operand or some instructions
Which symbol is optional when using gcc?
A # symbol can prefix the immediate, but is optional when using gcc
How many constants are allowed
It depends on the particular instruction and how many bits are available within the machine instruction
Prefixes to prevent immediates to be assumed as decimals
Hexadecimal: 0x Octal: 0 Binary: 0b
Why use aliases?
mov x29, sp is alias for add x29, sp, 0 provided for readability and programmer convenience
Commonly used instructions
- Move immediate mov Wd, #imm32 [-(2^31) to +(2^32) - 1] mov Xd, #imm64 [-(2^63) to +(2^64) - 1] - Move register mov Wd, Wm [alias for orr Wd, wzr, Wm] mov Xd, Xm [alias for orr Xd, xzr, Xm]
What is Branch and Link instruction used for? In what are args and return value?
To call a function (library or your own) Arguments put into x0-x7 before call Return value is in x0
Main routine of a program structure

What does .global main do?
Makes the label “main” visible to the linker
The main() routine is where execution always starts
What does … [sp, -16] do?
Allocates 16 bytes in stack memory (in RAM)
Does this by pre-incrementing the SP register by 16
What does stp x29, x30, … do?
Stores the contents of the pair of registers to the stack
Saves the state of the registers used by calling code
What does SP do after stp?
SP points to the location in RAM where we write to
What does mov x29, sp do?
What is the FP used as?
Updates FP to the current SP
FP may be used as a base address in the routine
What does ldp x29, x30, … do?
Loa_d_s the _p_airs of registers from RAM
Restores the state of the FP and LR registers
What does the SP do after ldp?
SP points to the location in RAM where we read from
What does …, [sp], 16 do?
Deallocates 16 bytes of stack memory
Does so by post-incrementing SP by +16
What does ret do?
Returns control to calling code (in OS)
Uses the address in LR
Addition registers/operands
1 DR, 2SO
Subtraction registers/operands
1 DR, 2SO
Multiplication registers/operands/immediates
Aliases
1 DR, 2 or 3 SR
No immediates allowed
mul Wd, Wn, Wm
Alias for
madd, Wd, Wn, Wm, wzr
Multiply-add registers/operands
madd Wd, Wn, Wm, Wa
Multiply-subtract registers/operands
msub Wd, Wn, Wm, Wa
Calculates: Wd = Wa – (Wn * Wm)
Multiply-negate registers/operands
mneg Wd, Wn, Wm, Wa
Calculates -(Wm * Wa)
Division registers/operands/immediates
Forms
1DR, 2SR
Does integer division
No immediates allowed
Signed-form
sdiv Wd, Wn, Wm
Operands are signed integers
Unsigned-form
udiv Wd, Wn, Wm
Operands are unsigned integers
To get remainder or Modulus, do?
numerator - (quotient * denominator)
Use msub
What does dividing by 0 do?
Does not generate an exception but instead writes 0 to DR
Printing to Standard Output
printf()
Invoked with 1 or more args
First is the format string (usually literal)
Rest corresponds to placeholders in the string

What does a branch instruction do?
What happens to PC?
A branch instruction transfers control to another part of the program
PC is not incremented as usual but is set ot th ecomputed address of an instruction (corresponds to the value of its label)
b label
is an unconditional branch that’s always taken
What are condition flags used for?
SIze?
What does 0 and 1 mean?
To store information about the result of an instruction
Are single bits in the CPU
0 = false, 1 = true
What are the 4 condition flags and when are they true?
- Z: true if result is zero
- N: true if result is a negative
- V: true if result overflows
- C: true if result generates a carry out
How are condition flags set?
Condition flags are set by instructions that end in “s” (set flags)
e.g. subs, adds
What is cmp an Alias for?
Form (64-bit): cmp Xn, Xm
Is an alias for: subs wzr, Xn, Xm
What are Conditional branch instructions used for?
Conditional branch instructions use the condition flags to make a decision
e.g b.eq
If Z is true, branches
Otherwise drops through to the following instruction
Diagram for signed integers
b.cc where cc is the condition code
Condition codes for signed integers are

How are loops formed?
By branching from the bottom of the loop to the top
What type of loop is a do loop and its format
A do loop is a post-test loop (loop body executed at least once)

How can you optimize code for a pre-test loop?
Move the test to the end of the loop
It reduces the loop by one instruction
Branch does not use complemented logic (idk)
Must branch to the test the first time though

How can a for loop be formed?
Convert it to a while loop

How can you make the If construct
Is formed by branching over the statement body if the condition is not true
Uses logical complement
b. lt <-> b.ge
b. le <-> b.gt
b. eq <-> b.ne
If-else construct
Using gdb debugger
Start a program under debugger control
Set breakpoint
Run program
Continue to next breakpoint
Single Step
ni
display/i $pc
p$reg
q
gdb myprogram
b label
- r*
- c*
- si*
- ni* (also executes next instruction but if a function call, proceeds until the function returns)
shows current instruction when single stepping (do before running program)
prints contents of register (Can append a format character:
Signed decimal: p/d
Hexadecimal: p/x
Binary: p/t)
q