5iasm
Jump to navigation
Jump to search
- This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
5iasm stands for "5 Instruction ASseMbly language". Like the name suggests, it has 5 commands.
Instructions
Mnemonic | Meaning | What it does |
---|---|---|
inc [register] |
INCrement | Increments a register |
dec [register] |
DECrement | Decrements a register |
jmp [line]/[label] |
JuMP | Jumps to a line or a label |
isz [register] |
Instruction Skip if Zero | Skips the next instruction if register is 0 |
stp |
SToP | Halts |
The first line in program is line 1.
There are 10 registers : A
,B
,C
,D
,E
,F
,G
,H
,X
, and Y
.
There are three special registers:
Name | Action on read (by isz) | Action on write(by inc or dec) |
---|---|---|
I |
Prompts one-character input (like brainfuck.) EOF=0 | Acts like a normal register but is set to the last inputted value after input. |
O |
Returns 1 | Prints its contents as a Unicode character |
N |
Returns 0 | After operation,if the contents is divisible by 3, enable I/O. This is used to output higher ASCII values without printing the lower values |
Labels and comments
To define a label:
label:
To jump to a label:
jmp label
Comments:
;comments are prepended with semicolons
Examples
Addition
; Clear C clearC: isz C jmp decC jmp clearX decC: dec C jmp clearC ; Clear X clearX: isz X jmp decX jmp processA decX: dec X jmp clearX ; Copy A to X and C processA: isz A jmp inc jmp restoreA inc: dec A inc X inc C jmp processA ; Now A is in X and C, but A=0 ; Now restore A from X restoreA: isz X jmp incA jmp processB incA: inc A dec X jmp restoreA ; Now we copy the value from B to X and C ; X is 0, so it becomes a backup copy again. ; And in C is the sum afterwards. processB: isz B jmp inc2 jmp restoreB inc2: dec B inc X inc C jmp processB ; We restore the value in B from X. restoreB: isz X jmp incB jmp done incB: inc B dec X jmp restoreB ; Done. done: stp
Cat Program
A perpetually repeating cat program shall be demonstrated below:
repeat_program: ; Query input. isz I ; Disable input/output. inc N ; Handle special case of EOF input, which omits copying to the ; output register. isz I jmp copy_input_to_output jmp print_input ; Copy input register value to output register. ; The register 'A' applies itself to an adminicular role, employed ; for a conditional skipping via 'isz A' during the 'O' register's ; resetting to zero (0). copy_input_to_output: inc O inc A dec I isz I jmp copy_input_to_output ; Adjust for supernumerary output register incrementation. dec O dec A print_input: ; Enable input/output. dec N ; Print input stored in output register. inc O inc A ; Disable input/output. inc N ; Reset output register to zero. reset_output_register: dec O dec A isz A jmp reset_output_register ; Enable input/output. dec N jmp repeat_program
Interpreter
- Common Lisp implementation of the 5iasm programming language.