flat assembler
Message board for the users of flat assembler.
Index
> Projects and Ideas > Implementing PIC. |
Author |
|
sid123 01 Jul 2014, 16:56
Hi,
I've got out of ideas here, but I've been thinking of implementing a relocatable format for my Virtual machine. It's a RISC machine, and therefore the instructions are very simple. I've used FASM with macros as the assembler for my Virtual Machine. Right now my format looks like this: https://github.com/Benderx2/FVM/blob/master/include/fvm/fv11/fv11.h I'm confused as to how implement such a format. How is this exactly done? How do other formats implement it? For example I could think of implementing something like this: Code: LOAD_R0 data ADDR R0, LP --> Load Address Register But this method is very space consuming and is senseless, in my VM Opcode's are 4-bytes, and hence I'm looking for a way to reduce instructions. (The VM is quite capable BTW, so anything can be done, from memory, I/O, calculating pi , sin x, cos x and whatnot) Ideas? _________________ "Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X XD |
|||
01 Jul 2014, 16:56 |
|
evk1 01 Jul 2014, 18:49
In the most common situations instructions which can access program counter register are used to implement PIC. In this case code reads address of current instruction and calculates data or function address using it.
Code: ;ARM code add r0,pc,data1-$-8 data1: Code: ;x86 code call l1 ;push address of l1 to the stack l1: pop eax add eax,data1-l1 data1: There is also an interesting PIC implementation in the ELF for MIPS architecture. According to procedure call standard position independent code should load a function address to the t9 register before calling it, so callee can calculate address of any varriable or function by adding its offset to the content of t9 register. Code: ;MIPS code function_entry: addiu $v0,$t9,data1-function_entry data1: _________________ Sorry for my English |
|||
01 Jul 2014, 18:49 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.