My questions are do you have any suggestions, and what resources are their for making the compiler? (books, tutorials, ...)
My current idea is:
Each operation is 16 bytes:
PIIIRRRRDDDDDDDD
P - Prefix, set special conditions on the instruction (for example, a call instruction could use an external prefix for functions in external files, a native prefix for functions written in the processor's bytecode, etc.)
I - Instruction, see below
R - register, most operations will need to use at least one register (similiar to a pointer). Function definitions can be addressed as a register.
D - either a 64 bit immediate value, or two 32 bit registers, depending on instruction and prefix.
My design for the interpreter is the following psuedocode (in nasm):
Code: Select all
dd instruction 0 ; to filled in at runtime
dd register 0
dq data 0
bytecode_interpret:
call load_next_instruction
mov eax, [instruction] ; read the instruction
and eax, 0xFFFFFF ; and just the instruction
cmp eax, <maxvalue> ; make sure it's a valid opcode
jg .error ; invalid opcode
shl eax, 1 ; two bytes per jump
add eax, instructions ; add offset to base address
call far cs:eax ; execute the instruction
.error:
;do something and end the program.
instructions:
jmp i1
jmp i2
...
i1:
; do something
retf
i2:
; do something else
retf
Code: Select all
-----------------------
| Header | 512 bytes
-----------------------
| Symbol table | length defined in header, defines registers needed at program start (such as main())
-----------------------
| Text section | contains definitions for code registers, read/execute only
-----------------------
| Data section | contains definitions for data registers, read/write unless otherwise specified
-----------------------
| Comments | contains comments and file attributes not needed for execution (Such as version, program name, etc.)
-----------------------