ABC of Electronics cosycom.com
EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 8

Assembly Language Basics

Writing instructions one at a time when every clock cycle counts.

Assembly is a human-readable form of machine code: one line usually equals one CPU instruction. Each processor family has its own instruction set, so assembly is not portable between them.

Use it for exact cycle-by-cycle timing, tiny boot code, or squeezing the last bytes out of flash. Most firmware is written in C, with assembly only for the few places that need it.

The pseudo-assembly below is generic and invented for teaching; real syntax differs per chip.

EXAMPLE
; generic teaching syntax, not a real instruction set
        LOAD  R1, 5        ; R1 = 5
loop:   SUB   R1, 1        ; R1 = R1 - 1
        JNZ   loop         ; repeat until R1 is zero
        STORE PORT, R1     ; write result to an output port