We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Nandasm

From Esolang
Jump to navigation Jump to search

Nandasm is the assembly language from nandgame.

Instructions

There are two kinds of instruction:

ALU Instruction
[Destination =] [Source] [; Jump]
Data Instruction
A = [0~32767 number]

*A is a pointer pointing to address A.

Is it turing complete?

No. It limits memory addresses from 0 to 65535.

Examples

Rot13 program

##### MACRO BEGIN #####
macro stop
A=stop
stop:
JMP
endmacro
macro goto label
A=label
JMP
endmacro
macro init.stack
A=256
D=A
A=SP
*A=D
endmacro
macro push.D
A=SP
A=*A
*A=D
A=SP
*A=*A+1
endmacro
macro pop.D
A=SP
*A=*A-1
A=*A
D=*A
endmacro
macro pop.A
A=SP
*A=*A-1
A=*A
A=*A
endmacro
macro push.value value
A=value
D=A
push.D
endmacro
macro push.static address
A=address
D=*A
push.D
endmacro
macro pop.static address
pop.D
A=address
*A=D
endmacro
macro stk.cmp
pop.D
pop.A
D=A-D
A=GTTRUE
D;JGT
push.value 0
A=END
JMP
label GTTRUE
D=0
D=~D
push.D
label END
endmacro
macro stk.dup
pop.D
push.D
push.D
endmacro
macro stk.xor
pop.D
pop.A
D=D^A
push.D
endmacro
macro push.char
push.static 0x6000
endmacro
macro pop.char
pop.static 0x6002
endmacro
#####  MACRO END  #####
##### DEFINITION BEGIN #####
define TEMP 3417
#####  DEFINITION END  #####
# Boot machine
BOOT:
# init stack
init.stack
# getchar()
push.char
# check if it is EOF
stk.dup
D=0
D=~D
pop.A
D=D^A
A=HALT
D;JEQ
# isalpha_lower
stk.dup
push.value 96
stk.cmp
pop.static TEMP
stk.dup
push.value 122
stk.cmp
pop.D
A=TEMP
D=~D
D=D&*A
A=ISALPHA
D;JNE
# isalpha_upper
stk.dup
push.value 64
stk.cmp
pop.static TEMP
stk.dup
push.value 90
stk.cmp
pop.D
A=TEMP
D=~D
D=D&*A
A=ISALPHA
D;JNE
goto FINAL
# ROT13
ISALPHA:
# (x&31)^(((12+(x&31))%26)+1)
stk.dup
pop.static TEMP
A=31
D=A
A=TEMP
D,*A=D&*A
# Now TEMP stores (x&31)
A=12
D=D+A
BRUTE:
A=26
D=D-A
A=BRUTE
D;JGE
# +26+1=+27
A=27
D=D+A
A=TEMP
D=D^*A
# Final XOR
push.D
stk.xor
FINAL:
# putchar()
pop.char
# Reset
goto BOOT
# Halt
HALT:
stop

Note: Assumes 0x6000 for input, 0x6002 for output. If you want to run it on nandgame, please expand the macros manually.