Binary/Hex file format¶
Input to the assembler is the assembly code file in .s file format. On successful compilation and linking, the following files are generated by the assembler:
- Binary code files for instructions and data in
.binformat, which may be decoded and loaded to instruction and data memories of a CPU to boot and execute. - Binary/Hex code text files for instructions and data in ASCII
.txtformat. This is human readable.
The .bin file contains the instructions to be executed/data symbols as a sequence of bytes in binary format.
The following example shows how an instruction binary file, sample_imem.bin, and a data binary file, sample_dmem.bin, are encoded. Big Endian format is used in the binary file.
// sample_imem.bin
<0xC0><0xC0><0xC0><0xC0> # Pre-amble marks the start
<0x00><0x00><0x00><0x28> # Program size = (no. of instr, N x 4) bytes
<baB3><baB2><baB1><baB0> # Base address of the program byte[3] to [0]
<inB3><inB2><inB1><inB0> # Instruction-1 byte[3] to [0]
<inB3><inB2><inB1><inB0> # Instruction-2 byte[3] to [0]
….
….
<inB3><inB2><inB1><inB0> # Instruction-N byte[3] to [0]
<0xE0><0xE0><0xE0><0xE0> # Post-amble marks the end
// sample_dmem.bin
<0xD0><0xD0><0xD0><0xD0> # Pre-amble marks the start
<0x00><0x00><0x00><0x28> # Data size = (no. of words, N x 4) bytes
<baB3><baB2><baB1><baB0> # Base address of the data section byte[3] to [0]
<wdB3><wdB2><wdB1><wdB0> # Word-1 byte[3] to [0]
<wdB3><wdB2><wdB1><wdB0> # Word-2 byte[3] to [0]
….
….
<wdB3><wdB2><wdB1><wdB0> # Word-N byte[3] to [0]
<0xE0><0xE0><0xE0><0xE0> # Post-amble marks the end