I am working on an embedded systems project and have run into an issue of the compiler being programatically embedded in the Paradigm C++ IDE. I would like to be able to automate building.
The processor is the AMD186ES. I am not working with the OS - just baremetal stuff. I need to generate real-mode 16-bit 8086 machine code from C++.
My googling indicates that G++ can build such code.
My questions are:
Can g++ be configured to build this machine code?
Are there other C++ compilers that can do it as well?
I am currently using gnu as
(part of binutils and the assembler used for gcc) and I have successfully been assembling 16bit assembly code with the following:
as <file>
ld --oformat binary -Ttext 0x0 -e start <file>
with my assembly files starting out with:
.code16
.globl start
.text
start:
since its plain binary omitting the lines,
.globl start
start:
will simply yield an warning, even though flat binaries need no entry point.
something I learned the hard way;
-Ttext 0x0
is critical, otherwise the .text
segment is pushed outside of 16bit addressing range (don't ask me why)
I am personally still learning assembly, so this is just my way, not necessarily the best way.
EDIT: If you are writing boot code, you should change
-Ttext 0x0
to
-Ttext 0x7c00
this will offset your memory addresses by 0x7c00
since boot code is usually loaded at 0x7c00
by the BIOS.