asm.md 1.54 KB
Newer Older
Aaron Erhardt's avatar
Aaron Erhardt committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
## 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
```