Stack-Langc compiler written in Rust to translate the given simple postfix expression into Stack-VM binary.
First 2 bits distinguishes between data and instruction.
bits | Type |
---|---|
00 | Data (Positive number) |
01 | Operation Instruction (OI) |
10 | Data (negative number) |
11 | undefined |
0x40000001 ADD
0x40000010 SUB
0x40000011 MUL
0x40000100 DIV
0x40000000 HALT
All program must end with HALT
instruction.
cargo run source_file_name
or stack-langc source_file_name
output generated by this will be writtent to file called a.out in current working directory.
Create file called program.vm
as follows
32 22 +
#order of evaluation Left to Right (ans=54)
compile the program using stack-langc
, it will generate instruction as follows
Hex word | VM Value |
---|---|
0x00000020 | Data (32 in decimal) |
0x00000016 | Data (22 in decimal) |
0x40000001 | OI (ADD) |
0x40000000 | OI (HALT) |