An interpreter with assembly like syntax.
- Download links
- How to use?
- The test files
- Source files
- How to code?
- More notes
- Delimiting characters
- Strings
- List of all errors
- List of all warnings
- How this interpreter works?
- Contribute
- Code of conduct
- Checkout out our latest release here. You'll find installation instructions there.
- Download a ZIP file from here.
- Or get an executable from bin.
- Execute as
asm path/to/file
whereasm
is the command (or the path to the binary executable). - Enter
asm --help
orasm -h
for help text.
- libheaders.h Declaration of stuffs from library headers.
- headers.h Declaration of project specific functions, types and macros.
- global.c Global variable declarations.
- main.c Main and CLI argument evaluation functions.
- misc.c General functions.
- input.c File handling and input functions.
- output.c Contains functions centered around displaying text.
- interpreter.c Interpreter functions.
Usage:
asm [filepath]
asm [OPTION]
asm [OPTION] [filepath]
Options: |
-h, --help | Display this message
-l, --labels | Display declared labels in tabular form
-c, --console | Console mode to execute codes from stdin
-v, --version | Display version information
-d, --dev | Developer mode to debug interpreter I/O
Operands: |
%x | Indicates register 'x'
&ad | Indicates address 'ad' of RAM
$no | Decimal or hex literal 'no'
ptr | RAM data pointer
Escape sequences: |
\" | Quote escape
\t | Tab escape
\n | Newline feed escape
\r | Carriage return escape
\b or \<space> | Space escape
\<any character> | Same as writing without '\'
Registers: |
operand, x = a to d | For storage
RAM: |
Default 1 cell | Address 0 i.e. `&0`
Variable cells | For storage (32 Bits per cell)
Number of RAM cells can be changed using opcode `ram`.
Mnemonics: |
#!/path/to/asm | Execute asm script directly from shell
# comment | Single line comment
/*comment*/ | Multi line comment
Label: | Labels
set op1 op2 | Set op1 to value of op2
add op1 op2 | Add op2 to op1 and store in op1
sub op1 op2 | Subtract op2 from op1 and store in op1
mul op1 op2 | Multiply op1 by op2 and store in op1
div op1 op2 | Divide op1 by op2 and store in op1
mod op1 op2 | Mod op1 by op2 and store in op1
ieq op1 op2 | If operands are equal, set FLAG true
ige op1 op2 | If op1 is greater or equal, set FLAG true
ile op1 op2 | If op1 is lesser or equal, set FLAG true
igt op1 op2 | If op1 is greater, set FLAG true
ilt op1 op2 | If op1 is lesser, set FLAG true
and op1 op2 | Set op1 to AND value of operands
or op1 op2 | Set op1 to OR value of operands
xor op1 op2 | Set op1 to XOR value of operands
com opn | Set operand to its 32 bit 1's complement
jmp lbl | Jump (unconditional) to a line after lbl
jit lbl | Jump if (FLAG) true to line after lbl
jif lbl | Jump if (FLAG) false to line after lbl
call lbl | Call label as function
calt lbl | Call label as function if FLAG true
calf lbl | Call label as function if FLAG false
ram opn | Resize total RAM to 'opn' int sized cells
inp opn | Input to operand
prn opn | Print operand as number
prc opn | Print operand as char
prs "str" | Print str as string
nwl | Print new line character
ret | Return from function
hlp | Display help text (only console mode)
end | End execution
NOTE: $20 will be parsed as decimal. For hex, use $0x20. This is
not necessary for $0a. Same goes for &. Also, 'ptr' can be
modified as $ptr and used as &ptr.
- Interpreter uses a top-to-bottom code interpretation.
- All codes are read directly from file buffer instead of a string.
- Jump and function calls are disabled in console mode.
- Opcode
inv
exists but has been deprecated sincejif
got introduced alongsidejit
. - Although both
jumps
andcalls
operate onlabels
, usingret
after ajump
will terminate current function. - If
ret
is used without acall
, program will simply quit. - Strings are supported as an operand only by
prs
. hlp
is activated only inconsole
mode.- Not having
end
causes error5
.
Tabs, spaces, commas, newlines, carriage returns and semicolons are used to delimit parts of the code. In reality, these characters are ignored.
1. "set" %a "$5"
The above code is valid. This code sets register a
to decimal 5
.
2. set "%a $5"
The 2nd code is invalid.
Output:
ERR> [LINE: 2] Invalid operand '%a $5' for opcode 'set'
The trouble is that the delimiting space b/w the two
operands of set
doesn't get ignored and the whole
thing hence becomes a single operand.
LBL CODE ERROR
E1 1 Too many or too few CLI arguments
E2 2 No file path entered
E3 3 Invalid option
E4 4 Can't read file
E5 5 Unexpected EOF
E6 6 Invalid new line escape seq
E7 7 Invalid carriage return escape seq
E8 8 Input exceeded limit or too long
E9 9 Invalid register name
E10 10 Invalid RAM address
E11 11 Address out of bounds
E12 12 Invalid literal
E13 13 Can't assign to literal
E14 14 Invalid operand
E15 15 Duplicate labels
E16 16 No such label
E17 17 Can't divide by zero
E18 18 Invalid decimal input
E19 19 Invalid opcode
E20 20 Failed to allocate memory
LBL WARNING
W1 Dev mode
W2 Opcode is disabled
W3 Opcode is deprecated