Run make && sudo make install
in the root directory of the project
./c8asm <c8asm source file> <output file name>
(if no name is supplied for the output file then "out.ch8" is used)
the following assumes the reader is familiar with the CHIP8 architecture
C8asm has 60 reserved names, these consist of..
25 mnemonics:
cls
jmp
vjmp
call
ret
sne
se
mov
or
and
xor
add
sub
subn
shr
shl
rnd
drw
wkp
skd
sku
ldf
bcd
lod
str
3 reserved keywords:
stimer
dtimer
I
32 register names:
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 va vb vc vd ve vf
V0 V1 V2 V3 V4 V5 V6 V7 V8 V9 VA VB VC VD VE VF
These are referred to as "names" in error messages.
Constants are used to supply operands to mnemonics and c8asm supports four formats for integer constants:
format | notation |
---|---|
decimal | <decimal number> |
hexadecimal | 0(x|X)<hexadecimal number> |
binary | 0(b|B)<binary number> |
octal | 0(o|O)<octal number> |
Labels are supported as an abstraction over addresses and can be used as operands to instructions jmp, vjmp and call. To define a label a name which is not a reserved keyword is written before a colon (:) and to reference a label it's name is written with no leading or trailing characters.
Characters which are valid in label names include underscores, lower and upper case ASCII characters and digits. Note
that digits may not be used as the first character of a label name, for example, 7abel
is not a valid label name but
_7abel
is.
Simple examples of using labels:
loop:
add v0, 1
jmp loop
jmp skip_xor
xor v0, v0
skip_xor:
call some_proc
add va, vb
some_proc:
xor v0, v0
ret
- cls (clear screen)
cls
- jmp (jump to address)
jmp (<label>|<constant>)
- vjmp (jump to address + v0)
vjmp (<label>|<constant>)
- call (call subroutine at address)
call (<label>|<constant>)
- ret (return from subroutine)
ret
- sne (skip next instruction if operands are not equal)
sne <register>, (<register>|<constant>)
- se (skip next instruction if operands are equal)
se <register>, (<register>|<constant>)
- mov (load value into memory location)
mov (<register>|stimer|dtimer), (<register>)
mov (<register>|I), (<constant>)
- or (bitwise or)
or <register>, <register>
- and (bitwise and)
and <register>, <register>
- xor (bitwise xor)
xor <register>, <register>
- add (addition)
add (<register>|I), <register>
- sub (subtraction)
sub <register>, (<register>|<constant>)
- subn (subtraction, set carry flag)
subn <register>, (<register>|<constant>)
- shr (bitwise right shift)
shr <register>, <constant>
- shl (bitwise left shift)
shl <register>, <constant>
- rnd (RNG)
rnd <register>, <constant>
- drw (draw sprite)
drw <register>, <register>, <constant>
- wkp (wait for keypress)
wkp <register>
- skd (skip next instruction if key down)
skd <register>
- sku (skip next instruction if key up)
sku <register>
- ldf (load font location)
lfd <register>
- bcd (binary coded decimal)
bcd <register>
- lod (load into registers)
lod <register>
- str (store in memory)
str <register>