Casio_asm/doc/asm_file.md

2.6 KiB

Assembler files

Theses files are written in an assembly language specific to this project.
Theses files are a newline-separated list of instructions and labels, with optional comments and whitespace.
These files will be converted to bytecode by the assembler.

File format

All assembler files contain at least an instruction and a UNIX newline on the last used line. All excess whitespace is ignored. Instructions are separated from their arguments using delimiters, and whitespace is not allowed there.

Accepted whitespace characters are:

  1. spaces, ascii dec 32 or hex 20
  2. newline characters, both Windows and UNIX work as whitespace
  3. tabulation characters

Note that the only accepted instruction sparator is the UNIX newline, but they are included in Windows newline sequences.

Accepted delimiters are:

  1. comas ,
  2. semicolons ;

Comments start with a comment start character and end with a newline. They are completely ignored by the assembler and are used purely by the programmer.
Accepted comment start characters are:

  1. Double quotes "
  2. Simple quotes '
  3. Pipes |

Labels start with a dot . followed by alphanumeric characters and underscores _, the first character not being a number.

Arguments may be a register number, prefixed by a hash #, an immediate value written in hex, decimal or binary, or a label which address is taken as an immediate value.

Labels

Labels do not translate to instructions, and are present to allow the programmer to mark an arbitrary point in the code which memory address can later be used.
The primary objective of labels is to be entry points for subroutines or continue points for loops.
The current C implementation allows for up to 64 labels which name is hashed and may clash and return a duplicate label error.

Example

The following code is syntactically valid, and calculates values from the fibonacci sequence in registers #1 and #2 without printing anything to screen.

	| store 1 in #1 and #2
	dup,1
	store,#1
	store,#2
	| store the maximum value in #3
	| this value is equal to 65536
	high,x1
	store,#3
	
	| beginning of the loop
.loop
	| add #1 and #2 and store the result in #1
	add_i,#1,#2
	store,#1
	| add #1 and #2 and store the result in #2
	add_i,#1,#2
	store,#2
	| check if we're past the maximum value
	gt_i,#2,#3
	| if we are not, then go back to the beginning of the loop
	jnt,.loop
	
	| we are higher than the maximum value
	| set abort bit in status register and halt
	push,b1
	status_s,x3
	halt