nrj-oisc

NOR and Reference Jump OISC platform
git clone git://git.luxferre.top/nrj-oisc.git
Log | Files | Refs | README

example.nrjasm (1877B)


      1 ; a proposed assembly syntax for NRJ machines (example for NRJ16)
      2 ; semicolons are comments
      3 ; preprocessor instructions start with dot (.)
      4 ; every non-preprocessor instruction creates an entry in the lookup table
      5 ; all addressing is in words
      6 ; we usually start at the word 3 (don't pre-fill the I/O buffers)
      7 
      8 .bit 16 ; word/address size: NRJ16 is the default setting
      9 .org 3 ; .org defines the start of further code/data (in words, hex)
     10 
     11 ; include the standard library
     12 
     13 .inc stdlib.nrjasm
     14 
     15 .var x 2EF ; .var defines a label for a particular memory location
     16 .var y 2F0 ; define another variable at 0x2F0
     17 .set @x 'm ; .set sets a memory location to a particular hex constant at the build time, @ dereferences a label into the address
     18 .set @y 'M ; ' dereferences a character into a whole word with its ASCII code
     19 
     20 ; we CANNOT use dereferencing operators with .var, only with .set or directly
     21 
     22 ; there also can be .inc instruction to include a snippet from another file in the same directory
     23 
     24 ; now, main elementary macros:
     25 ; NXT - address of the next instruction position in the lookup table
     26 ; HLT - the last address position in the lookup table (0xFFFF for NRJ16), set by .bits
     27 ; FREE - address of the next available (at build time) memory cell, can only be used in .var
     28 
     29 ; for the lookup table and CUR/NXT macros to work correctly, the code must start at an address divisible by 3
     30 ; note that FREE doesn't intelligently detect the available cells, it only takes the next one after the maximum address used
     31 ; so in our case, the first FREE instance will be substituted with 2F1, the next with 2F2 and so on
     32 
     33 ; now, lets output a character by transferring the y value to the output cell 1
     34 ; in an endless loop
     35 
     36 .lbl myloop
     37 MOV 1 @x 
     38 MOV 1 @y @myloop ; output the character and jump to the beginning
     39 ; we don't have to explicitly zero out the cell 1 as it is done by the I/O logic
     40