Assembly with %include at the top – Printing Outputs Unexpected Result: just an ” S”

You included stuff at the top of your bootloader, where it will executes first. Instead include extra functions where they aren’t in the main path of execution and are only reached by call. This should work, placing the %include directives where it’s safe to put extra function or data, just like if you were writing … Read more

How to force NASM to encode [1 + rax*2] as disp32 + index*2 instead of disp8 + base + index?

NOSPLIT: Similarly, NASM will split [eax*2] into [eax+eax] because that allows the offset field to be absent and space to be saved; in fact, it will also split [eax*2+offset] into [eax+eax+offset]. You can combat this behaviour by the use of the NOSPLIT keyword: [nosplit eax*2] will force [eax*2+0] to be generated literally. [nosplit eax*1] also … Read more

execute binary machine code from C

The code must be in a page with execute permission. By default, stack and read-write static data (like non-const globals) are in pages mapped without exec permission, for security reasons. The simplest way is to compile with gcc -z execstack, which links your program such that stack and global variables (static storage) get mapped in … Read more