Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Aaron Erhardt
Cheatsheets
Commits
0f31e336
Commit
0f31e336
authored
Apr 15, 2021
by
Aaron Erhardt
🦀
Browse files
Add assembler cheat heet
parents
Changes
1
Show whitespace changes
Inline
Side-by-side
Mikrocomputertechnik/asm.md
0 → 100644
View file @
0f31e336
## 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
```
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment