NoRAL

From Esolang
Jump to navigation Jump to 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
  • Immediate: 1 byte (sto)
  • Indirect: mvi

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 = m2(immediate byte)
Z
sub 11 m1 = m1 - m2 - carry
CZ
inc 12 m1 += 1
CZ
dec 13 m1 -= 1
CZ
mvi 14 m1(absolute) = m2(indirect)
Z
get 15 input decimal number mod 256
Z
dsp 16 display program state during execution
brk 00 Halt program

The command DAT is also a thing but it just stores a byte directly into memory (like .byte in other assembly languages).

If you want, you can also write "mem" followed by an address. This will mean that all the following instructions will be stored at that address and onwards until the next "mem" command. At the beginning of the file, it is like the first line is "mem 0200" even though you don't need to type that.
Both are optional for an implementation to implement but I would say they are pretty easy to do.
TheCoderPro (talk) 23:55, 2 August 2020 (UTC)

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

Truth Machine

get 0100
jpz 0211
sto 0100 31
inc 0208
dsp
jmp 0206
sto 0100 30
dsp
brk

External resources