Page 1 of 1

Pikoasm

Posted: Wed Apr 21, 2021 3:44 pm
by Hanzlu
As part of Pikobrain, I made an assembler, and called the language Pikoasm. The assembler is 16-bit and provides most of the usual/basic assembly instructions. It is only about 1.8kB in size (machine code). All instructions are written in upper-case.

The mneumonics are a bit different as each instruction will have its own letter. For example 'add' and 'and' both begin with 'a', so 'and' became B (both).
If an instruction can take either a register or an immediate value as source, this is specified in the mneumonic. Such as AR (add register) and AN (add number).
Some instructions are only one character long, such as 'int' = I, 'inc' = H (higher), and 'push ax' = PA.
Segmentation is limited to specific combinations (es:bx, fs:si, gs:di), and are always done with the al register.
It is also possible to use "macros" which are functions the OS calls, such as the random function which returns a random number in al, by using WR.

Labels are specified by placing dots in the start and end of the name. Only the last dot is written when doing jumps.

The assembler directly translates the Pikoasm code into machine code in two stages.
The first stage directly translates the code into machine code, and during the second stage the jmp lenghts are calculated and inserted into the machine code.

Here is an example program that prints all the 8-bit ascii chars:

Code: Select all

MN AX 0E00
.LOOP.
I 10
H AL
CN AL 00
JN LOOP.
Ee
Immediate values are always written in full lenght, such that an 8-bit value is written as two hexadecimal digits. The E and e instructions are used to show where the program and source code ends respectively.

The above program would translate to (in "normal" assembly):

Code: Select all

mov ax, 0xe00
loop:
int 10h
inc al
cmp al, 0h
jne loop
ret
The assembler supports a couple more things such as string printing, comments and it is also possible to write multiple instructions on the same line.