Commit 0f31e336 authored by Aaron Erhardt's avatar Aaron Erhardt 🦀
Browse files

Add assembler cheat heet

parents
## Load
```asm
ldr rd, = const ; load constant
ldr r1, [r0] ; load content of address of r0 into r1
ldr r1, [r0, #8] ; same with offset
ldr r1, [r0], #8 ; post-increment
ldr r1, [r0, #8]! ; pre-increment
```
Load value defined by dcd
```asm
MAX DCD 10
ldr r3, MAX
```
## Move
```asm
mov r0, r1 ; r0 := r1
mov rd, #const ; const max. 16-Bit, otherwise load
```
## Add
```asm
add r0, r1, r2 ; ro = r1 + r2
add r0, r1 ; ro = r0 + r1
add r0, #1 ; ro = r0 + 1, for small constants
```
Set flags while adding
```asm
adds r0, r1, r2 ; ro = r1 + r2, also sets flags
```
## Compare
```asm
; like subtraction, but only sets flags
cmp r0, r1 ; zero flag set if equal, etc.
cmp r0, 0 ; compare with constant
```
## Branch
Unconditional branch
```asm
b LABEL ; jump to label
```
Compare binary numbers
```asm
; use "cmp r1 r2" always before branch
; COMMAND ; meaning C-Code Flags
beq LABEL ; equal r1 == r2 Z = 1
bne LABEL ; not equal r1 != r2 Z = 0
bgt LABEL ; greater r1 > r2 N = 0
bge LABEL ; greater equal r1 => r2 N = 0 or Z = 1
blt LABEL ; lower r1 < r2 N = 1
ble LABEL ; lower equal r1 =< r2 N = 1 or Z = 1
```
Branch with flag values
```asm
; COMMAND ; meaning Flags
bcs LABEL ; carry set C = 1
bcc LABEL ; carry cleared C = 0
bmi LABEL ; minus N = 1
bpl LABEL ; plus N = 0
bvs LABEL ; overflow set V = 1
bvc LABEL ; overflow cleared V = 0
beq LABEL ; equal Z = 1
bne LABEL ; not equal Z = 0
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment