-
Notifications
You must be signed in to change notification settings - Fork 5
Syntax
EzASM syntax is fairly straightforward. Every line will start with an instruction
-- this will be what you are telling the program to do. The instruction is normally followed by an output
type argument (if applicable) and then input
argument type(s). Putting this together you will get something like the following:
-
instruction output input1 input2
for a binary operator -
instruction output input
for a unary operator -
instruction input-output
for certain unary operators
A list of instructions and their arguments can be found by following this link.
An output
or input
could be for example a register
. Registers are fast and easy data storage for operating on data, however they are limited in quantity. There are 40 registers which are meant for your use of reading from and writing to:
-
$t0 $t1 $t2 ... $t9
are the 10temporary
registers. These are meant for data which you are using to work with. -
$s0 $s1 $s2 ... $s9
are the 10saved
registers. These are meant for saving data between function calls which modify temporary data. -
$ft0 $ft1 $ft2 ... $ft9
are the 10temporary
floating point registers, similar to their$t0 - $t9
counterparts but for floats. -
$fs0 $fs1 $fs2 ... $fs9
are the 10saved
floating point registers, similar to their$s0 - $s9
counterparts but for floats.
The call of sub $t0 $t1 $t2
would subtract the value stored in $t2
from the value stored in $t1
and store it into $t0
.
Immediate values are hard-coded numbers which are loaded into the program. They are typed out the same way a number is normally typed out when programming and can only be used as an input
to an instruction
. It would not make sense to try to store data to a constant in your program.
The call of add $t1 14 50
would add the two immediate values 14
and 50
and store the result into the register $t1
.
There are also other ways to denote immediate values: hexadecimal and binary support is included in this language. Hexadecimal numbers are denoted by beginning the immediate with 0x
and can contain numbers 0
through f
; for example, the hexadecimal immediate 0xFF
would be equal to the decimal immediate 255
. Likewise, binary immediates begin with 0b
and can only contain the numbers 0
and 1
; for example, the binary immediate 0b1001
is equal to the decimal immediate 9
. Sometimes you may find that certain numbers you are working with are best denoted in hexadecimal or binary: you can use this feature to do so.
The call of mul $t2 0xF 0b10
would multiply the two immediate values 15
and 2
and store them into the register $t2
.
Immediates can also be negative: -10
is a valid immediate as well as -0xFF
and -0b1001
.
You can also use immediate floating point values with the other features of immediates: -10.3
is a valid floating point immediate, as well as 0x.d5
and 0b101.01
. It is important to note however that floating point and integer numbers cannot do arithmetic together normally. You will need to convert your floating point numbers to longs or your longs into floating point numbers to do arithmetic with them. This is because the two types of data are fundamentally stored differently in memory and interpreting float memory as an integer or vice versa will not give a meaningful number (usually).
Character literals, a single character enclosed by single-quotes (e.g., 'c'
) are also an input method in EzASM. The character is converted into its ASCII equivalent value and is then used as an integer.
The call of add $t3 '0' 3
will add the number 3
to the value of the ASCII representation of '0'
: 48
in decimal. This results in a value of 51
being stored into $t3
. 51
when interpreted as ASCII represents the character '3'
.
(This feature is not yet implemented.) String literals, any number of characters enclosed by double quotes (e.g., "Hello, world!"
) are an (unimplemented) input method in EzASM. Upon paring the string, the language will allocate memory outside of the typical stack and heap space in which to store the array of characters representing the string. The value given to your program will be the address
of this null-terminated string.
In the case of a string literal Hello, World!
, a block of memory of 14 words
will be allocated like the following:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 'H' | 'e' | 'l' | 'l' | 'o' | ',' | ' ' | 'W' | 'o' | 'r' | 'l' | 'd' | '!' | '\0'|
and the immediate value given to the program will be the address of the starting point of the string; in this scenario it would be wherever 'H' is stored in memory. Note that the 14th character of the string is allocated as a null byte (represented as '\0') which is just a byte full of zeroes.