gcc语言编译原理_CompilingBinaryFilesUsingACompiler

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Making plain binaryfiles using a C compiler(i386+)

Cornelis Frank

April10,2000

I wrote this article because there isn’t much information on the Internet concerning this topic and I needed this for the EduOS project.

No liability is assumed for incidental or consequential damages in connection with or arising out of use of the information or programs contained herein.

So if you blow up your computer because of my bad“English”that’s your problem not mine. 1Which tools do you need?

An i386PC or higher.

A Linux distribution like Red Hat or Slackware.

GNU GCC compiler.This C compiler usually comes with Linux.To check if you’re having GCC type the following at the prompt:

gcc--version

This should give an output like:

2.7.2.3

The number probably will not match the above one,but that doesn’t really matter.

The binutils for Linux.

NASM Version0.97or higher.The Netwide Assembler,NASM,is an80x86assembler designed for portability and modularity.It supports a range of objectfile formats,including Linux‘a.out’and ELF,NetBSD/FreeBSD,COFF,Microsoft16-bit OBJ and Win32.It will also output plain binaryfiles.Its syntax is designed to be simple and easy to understand, similar to Intel’s but less complex.It supports Pentium,P6and MMX opcodes,and has macro capability.

Normally you don’t have NASM on your system.Download it from:

/pub/Linux/devel/lang/assemblers/

A text editor like pico or emacs.

1See also:Intel Architecture Software Developer’s Manual,V olume1:Basic Architecture,1.4.1.Bit and Byte Order

2See also:Intel Architecture Software Developer’s Manual,V olume1:Basic Architecture,4.2.2.Stack Alignment

0000000021

1111111121

000000002

010

Wherein x stands for a number represented in base x.Notice also that negative numbers are characterized by having the high bit on.Of course you don’t have to do the conversion to a negative version of a certain number yourself.The IA-32architecture has a specific instruction for this,called NEG.Table1shows us the two’s complement representation of a char.The advantage

Range

unsigned12825501127

3See also:Intel Architecture Software Developer’s Manual,V olume1:Basic Architecture,6.3.2.1.Type Conver-sion Instructions

4See also:Intel Architecture Software Developer’s Manual,V olume1:Basic Architecture,3.3.Memory Organi-zation

5See also:Intel Architecture Software Developer’s Manual,V olume3:System Programming Guide,Chapter3: Protected-mode memory management

6Source:A Book on C,fourth edition,A.10.Variable Arguments

相关文档
最新文档