First working assembler!
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
; a proposed assembly syntax for NRJ machines (example for NRJ16)
|
||||
; semicolons are comments
|
||||
; preprocessor instructions start with dot (.)
|
||||
; every non-preprocessor instruction creates an entry in the lookup table
|
||||
; all addressing is in words
|
||||
; we usually start at the word 3 (don't pre-fill the I/O buffers)
|
||||
|
||||
.bit 16 ; word/address size: NRJ16 is the default setting
|
||||
.org 3 ; .org defines the start of further code/data (in words, hex)
|
||||
|
||||
; include the standard library
|
||||
|
||||
.inc stdlib.nrjasm
|
||||
|
||||
.var x 12EF ; .var defines a label for a particular memory location
|
||||
.var y 12F0 ; define another variable at 0x12F0
|
||||
.set @x 33EE ; .set sets a memory location to a particular hex constant at the build time, @ dereferences a label into the address
|
||||
.set @y 'M ; ' dereferences a character into a whole word with its ASCII code
|
||||
|
||||
; we CANNOT use dereferencing operators with .var, only with .set or directly
|
||||
|
||||
; there also can be .inc instruction to include a snippet from another file in the same directory
|
||||
|
||||
; now, main elementary macros:
|
||||
; NXT - address of the next instruction position in the lookup table
|
||||
; HLT - the last address position in the lookup table (0xFFFF for NRJ16), set by .bits
|
||||
; FREE - address of the next available (at build time) memory cell, can only be used in .var
|
||||
|
||||
; for the lookup table and CUR/NXT macros to work correctly, the code must start at an address divisible by 3
|
||||
; note that FREE doesn't intelligently detect the available cells, it only takes the next one after the maximum address used
|
||||
; so in our case, the first FREE instance will be substituted with 12F1, the next with 12F2 and so on
|
||||
|
||||
|
||||
; now, lets output a character by transferring the y value to the output cell 1
|
||||
; in an endless loop
|
||||
|
||||
.lbl myloop
|
||||
MOV 1 @y @myloop ; output the character and jump to the beginning
|
||||
; we don't have to explicitly zero out the cell 1 as it is done by the I/O logic
|
||||
|
||||
Reference in New Issue
Block a user