In HLL, I have these to be parsed (front-end):
IF a = 3 THEN
MSGBOX win
ELSE
IF b = 1 THEN
MSGBOX you lose
ELSE
MSGBOX You won
ENDIF
ENDIF
Then my back-end would generate:
CMP a, 3
JNE cond2
INVOKE MSGBOX, 'win'........
JMP nocond
cond2: CMP b, 1
JNE cond2b
INVOKE MSGBOX ' You lose'
JMP nocond
cond2b: INVOKE MSBOX 'You won'
nocond:
If I use FASM as back-end compiler, then it is end of story. But mine is not, it will generate the final EXE by itself, by computing RVA, e.g. distance of nocond: from different JMP location, depending on how many bytes in between.
E.g.
That's JMP 103 because of adjacent memory bytes.
JMP 102 would actually points to RET itself. Sometimes different CPU instructions may have bigger size.
E.g
JMP 104
MOV EBP,ESP
104:NOP
See, GOTO(JMP) need to skip 4 bytes for the label (104).
----
So how do I calculate the length of JMP (in bytes) for each of these conditional instruction? Do I need 2 pass, 3 pass,etc to first find out the size of code block in between as illustrated below?
e,g,
JMP target
xxxxx
xxxxx ;large codeblock
xxxxx
xxxxxx
target: <----
xxxxxx
Good news is I planning to revive my Sambal Compiler to support more features....