Linked Questions
15 questions linked to/from How to generate plain binaries like nasm -f bin with the GNU GAS assembler?
10 votes
3 answers
17k views
How to compile an assembly file to a raw binary (like DOS .com) format with GNU assembler (as)? [duplicate]
I want to compile this source code in Windows (It just an example): start: NOP NOP When I compile it with NASM or FASM, output file length is 2 bytes. But when I compile it with GNU assembler (as) ...
0 votes
0 answers
25 views
Can you define the ELF headers as you wish using GAS? [duplicate]
At the middle of this very good article: A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux, the author shows how to directly construct yourself the ELF headers: BITS 32 ...
43 votes
4 answers
53k views
Is there a way to get gcc to output raw binary?
Is there a set of command-line options that will convince gcc to produce a flat binary file from a self-contained source file? For example, suppose the contents of foo.c are static int f(int x) { ...
44 votes
4 answers
10k views
Observing stale instruction fetching on x86 with self-modifying code
I've been told and have read from Intel's manuals that it is possible to write instructions to memory, but the instruction prefetch queue has already fetched the stale instructions and will execute ...
14 votes
5 answers
13k views
How to disassemble 16-bit x86 boot sector code in GDB with "x/i $pc"? It gets treated as 32-bit
For example, with a boot sector that BIOS prints a to the screen main.asm: org 0x7c00 bits 16 cli mov ax, 0x0E61 int 0x10 hlt times 510 - ($-$$) db 0 dw 0xaa55 Then: nasm -o main.img main.asm qemu-...
8 votes
3 answers
34k views
How to convert ELF file to binary file?
My understanding is that a binary file is the hex-codes of the instructions of the processor (can be loaded into memory & start executing from entry point) and a ELF file is the same with NO-Fixed ...
6 votes
2 answers
10k views
Purest Way to Assemble/Compile a file With no other ELF/Object Bloat
I cannot believe how hard this seems to be. I am working from SPARC Solaris 8. and we have some kind of GNU-gcc (3.4.2) and 'as' assembler (Sun WorkShop 6 2003/12/18 Compiler Common 6.0). Anyways, I'...
6 votes
5 answers
4k views
Generating a pure (or flat) binary
How can you generate a flat binary that will run directly on the CPU? That is, without an Operating System; also called free standing environment code (see What is the name for a program running ...
5 votes
2 answers
1k views
What manages RAM?
When an assembly program is compiled and run on a machine without an operating system, how is a starting address in RAM chosen so that variables declared with data directives are allocated properly?
5 votes
2 answers
5k views
How do I produce plain binary from object files?
How should I produce raw binary file from two object (.o) files? I want the plain binary format produced by nasm -f bin when compiling a .asm file, but for .o files. By a plain binary, I mean a file ...
4 votes
1 answer
2k views
Is it possible to produce a plain binary file only using GNU Assembler on Mac OS X?
I wrote some assembly code for x86, and wanted to assemble it into plain binary file (not Mach-O) by just using Mac's default assembler (the 'as'). After several googlings and tries, I failed. ...
1 vote
1 answer
4k views
relocation R_X86_64_8 against undefined symbol `ELF' can not be used when making a PIE object
Having this in gas: .text .globl main main: xor %eax, %eax lea str(%rip), %rdi call printf call exit str: .byte 0x7F, "ELF", 1,1,1,0 I thought the .byte directive could be ...
4 votes
1 answer
708 views
How to use GNU Assembler (GAS) to create a hand-written ELF File from the corresponding .s file
Introduction I am trying to learn about ELF Files, and also experiment with them a little bit. Currently, I am following the tutorial here, which is about creating a tiny 32-bit ELF file that just ...
2 votes
1 answer
991 views
Assembly of PIC
The address of str is stored the stack(can use pop to fetch it, and it's position independent): .text str: .string "test\n" But now the address of str is not in the stack(can't use pop ...
1 vote
2 answers
307 views
Compiling assembly program to flat-form binary includes extraneous 'f' chars that don't exist in other formats
I'm working on a program written in assembly: xor eax, eax ; make eax equal to 0 push eax ; pushes null push 0x68732f2f ; pushes /sh (//) push 0x6e69622f ; pushes /bin mov ...