OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:20 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Pikoasm
PostPosted: Wed Apr 21, 2021 3:44 pm 
Offline
User avatar

Joined: Sun Mar 28, 2021 7:46 am
Posts: 9
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:
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:
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.

_________________
https://www.github.com/hanzlu/pikobrain


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Garnek0, Google [Bot] and 69 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group