寻找16位x86编译器 [英] Looking for 16-bit x86 compiler
问题描述
我正在编写一个嵌入式系统项目,遇到编译器被编程嵌入到Paradigm C ++ IDE中的问题。我希望能够自动化构建。
处理器是AMD186ES。我不是与操作系统 - 只是baremetal的东西。
我需要从C ++生成实模式16位8086机器代码。
我的Google搜寻表示G ++可以建立这类程式码。
我的问题是:
可以将g ++配置为构建此机器代码吗?
是否还有其他C ++编译器可以做到这一点?
gnu as
(一部分binutils和汇编器用于gcc),我已经成功地汇编了16位汇编代码,如下:
as< file>
ld --oformat binary -Ttext 0x0 -e start< file>
用我的汇编文件开头:
.code16
.globl start
.text
start:
因为它的纯二进制省略了行,
.globl start
开始:
只会产生警告,即使平面二进制不需要入口点。
我学到了很难的方法;
-Ttext 0x0
是至关重要的,否则 .text
段被推出16位寻址范围之外(不要问我为什么)
我个人还在学习汇编,所以这只是我的方式,
如果您正在编写引导代码,则应该更改 -Ttext 0x0
到
-Ttext 0x7c00
这将通过 0x7c00
来抵消内存地址,因为引导代码通常加载在 0x7c00
。
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.
这篇关于寻找16位x86编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!