NoRAL

From Esolang
Jump to: navigation, search

No-Register Assembly Language - A simple assembly-style language based on a hypothetical processor that has no internal registers. Created by User:DMC

General Concept

  • All volatile memory is external to the processor
  • Addresses are 16 bit, stored big endian
  • Memory is 8 bits
  • Instructions use 0, 1, or 2 memory references
  • m1 - first memory reference
  • m2 - second memory reference
  • xxx m1 m2 - 3 letter mnemonic, arguments separated with spaces
  • Program listings are in hex
  • It’s okay to write self-modifying code (maybe even necessary)
  • # comment with ‘#’ as first character in a line
  • Turing complete: No, only 64k addressable memory

Addressing modes

  • Implied: (brk, nop, ret)
  • Absolute: 2 byte address (17 instructions)
  • Immediate: 1 byte (sto)

The Virtual machine

Description Memory
Total memory 0000 - ffff
Program counter 0000 - 0001 (initialized to 0200)
carry flag 0002
zero flag 0003
Top of stack 0004
Stack 0005 - 00ff
Display memory 0100 - 01ff, 32 x 8, 256 bytes
Start of program memory 0200

The Instruction set

Instruction Op Code Description Flags
add 01 m1 = m1 + m2 + carry
CZ
and 02 m1 = m1 & m2
Z
jmp 03 pc = m1
jpc 04 if C = 1: PC = m1
jpz 05 if Z = 1: PC = m1
jsr 06 push PC, PC = m1
mov 07 m1 = m2
Z
nop 08 place holder
not 09 m1 = not(m1)
Z
orr 0a m1 = m1 or m2
Z
pop 0b pop m1
Z
psh 0c psh m1
ret 0d pop PC
shl 0e shl m1
CZ
shr 0f shr m1
CZ
sto 10 m1 = immediate byte
Z
sub 11 m1 = m1 - m2 - carry
CZ
inc 12 m1 +=1
CZ
dec 13 m1 -= 1
CZ
brk 00 Halt program

Example programs

Hello World!\n

# just store all the ascii values in screen memory
sto 0100 48
sto 0101 65
sto 0102 6c
sto 0103 6c
sto 0104 6f
sto 0105 2c
sto 0106 20
sto 0107 57
sto 0108 6f
sto 0109 72
sto 010a 6c
sto 010b 64
sto 010c 21
brk
# brk only necessary if the next memory location is not zero

Output:

Program Counter:  0234
Zero Flag:          00
Carry Flag:         00
Stack Pointer:      00

+---------Screen Display---------+
|Hello, World!                   |
|                                |
|                                |
|                                |
|                                |
|                                |
|                                |
|                                |
+--------------------------------+

Clear screen

sto 1000 20
mov 0100 1000
inc 0206
jpz 0212
jmp 0204
brk
Output:
Program Counter:  0213
Zero Flag:          01
Carry Flag:         01
Stack Pointer:      00

External resources

  • NoRAL – Interpreter in Python 3