flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > (for Tomasz) amazing! |
Author |
|
revolution 23 Jun 2010, 18:10
ouadji: fasm is split into two main parts to allow for more than 64kB code (to support the DOS version). That is why this manipulation is necessary.
|
|||
23 Jun 2010, 18:10 |
|
ouadji 23 Jun 2010, 18:25
ok! I had thought it. it's the only reason requiring this approach ! thank you revolution having said that, this below works too : Code: push dword[error] ret |
|||
23 Jun 2010, 18:25 |
|
LocoDelAssembly 23 Jun 2010, 18:56
ouadji, it is incorrect to assume that [esp]==error_handler is always true. The final address for error_handler at run-time may differ from that of the compile-time, but since labels will preserve their distance from each other that trick allows for the calculation of the correct target address.
Looks that you actually understood what I've said above but I'm repeating it because I don't know why you said your second code also works. |
|||
23 Jun 2010, 18:56 |
|
ouadji 23 Jun 2010, 19:18
Quote: it is incorrect to assume that [esp]==error_handler is always true. [esp] == error_handler ??? where ??? (sorry) i don't understand why you said "[esp] == error_handler" where ??? sorry LocoDelAssembly, but I don't see any differences between these two pieces of code : Code: 1) call A A: mov eax,[B] sub eax,A add [esp],eax ;[esp] = A + (B - A) => [esp] = B ret ;and 2) push dword[B] ; [esp] = B ret 1) == 2) |
|||
23 Jun 2010, 19:18 |
|
LocoDelAssembly 23 Jun 2010, 20:10
You are assuming that A and B are either in the compile-time addresses or the references to them fixed by some loader by applying relocations.
In this scenario only 1) will jump to B correctly: Code: mov esi, the_code mov edi, [unknown_pointer] mov ecx, the_code.end - the_code rep movsb mov edi, the_code mov ecx, the_code.end - the_code rep stosb jmp [unknown_pointer] the_code: ;1) call A A: mov eax,[B] sub eax,A add [esp],eax ;[esp] = A + (B - A) => [esp] = B ret ;and ;2) push dword[B] ; [esp] = B ret ; Will jump to garbage created by the rep stosb some_proc: xor eax, eax ret the_code.end: B dd some_proc |
|||
23 Jun 2010, 20:10 |
|
ouadji 23 Jun 2010, 20:36
Quote:
yes, indeed. Code: ... mov esi, the_code | ; ok, i understood ! mov edi, [unknown_pointer] | ;in this case, yes, of course, indeed!!! mov ecx, the_code.end - the_code | rep movsb | ... mov edi, the_code | mov ecx, the_code.end - the_code | aahhhhh !!!! bye bye rep stosb | In this scenario only 1) will jump to B correctly: and the correct address of [error], ok ! thank you LocoDelAssembly ! |
|||
23 Jun 2010, 20:36 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.