Message board for the users of flat assembler.
> Linux > fasm as 64-bit ELF executable
Goto page 1, 2 Next
While 64-bit systems are in general capable of running a 32-bit executables, there are some Linux builds out there that have this feature disabled in the kernel. This makes it impossible to run fasm on such machines without writing a 64-bit version from scratch. Or does it?
I've been thinking about this for a few years already, and I had some ideas on how to run fasm's core in "use64" setting. Now I finally decided to confront my ideas with reality.
The trick lies in the fact that 32-bit addressing is still available in long mode. As long as the address fits in 32 bits, [ebx] can be used instead of [rbx] and the instruction is going to be correctly encoded and executed. Therefore it should suffice to ensure that all memory allocated for fasm's use lies in the low 4G of addressing space. And fortunately sys_brk, which fasm's Linux interface uses to pre-allocate all the memory that fasm is going to use, appears to do exactly that - it grows the program segment (which we can put at a low address) so the allocated memory should stay in the low addressing.
But there is another problem - there is no 32-bit PUSH/POP in long mode. These two instructions need to be replaced with macros that emulate 32-bit stack. For example "push eax" has to become: