Hi @all,

i'm programming an assembler and I have some problems with the translation of the jmps and offsets into bin. I know that there are 1 byte, 2 bytes and 4 bytes - jmps are.

In other words:
How can i find out how long the jmps (1,2 or 4 bytes long) are and translate this into bin.

I think it's easier to explain the jmps on this little program:

jmp EntryPoint
mystr db "Hello world$" <--
EntryPoint: mov AH,09h
mov DX,OFFSET mystr <--
int 21h
mov AH,4Ch
int 21h
END

I hope i explained my problem good enough...it's hard for me, because my English is not so good.
I hope this is the right category.
Posted on 2007-01-05 14:05:08 by Nils:D
You can do it in 2 phases (or 'passes'):
1) You compile the code and assume the all relative jumps are 4-byte wide.
2) You shorten the jumps which turned out to be shorter.
Posted on 2007-01-05 21:36:06 by ti_mo_n
Could you give me a more detailled explanation of your theory ?
Posted on 2007-01-10 14:49:59 by Nils:D
There are two ways. You can look up all of the opcodes between here and there, add them together, and see how far it is. Or, as previously suggested, compile and then see. In the old days, programms were done the previous way as there weren't compilers to do it! You had to sometimes assemble a few times to make sure all of the jumps were right. ;)
Posted on 2007-01-11 09:46:25 by Jeronimo0d0a
Ok, thx. I will try it :)
Posted on 2007-01-12 11:44:10 by Nils:D