Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-04

object code: how to generate?

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

K Stol

Hello,

I'm trying to make a really simple compiler, and i'm getting there, but i have one problem. The program makes a tree of the program, so i can traverse it and generate program code. But i would like to generate the (binary) object code, so it can actually create .EXE files, which can be run under DOS / windows. I think i can find the hex-codes of the instructions, but how can i make a REAL executable, so i don't have to make an interpreter. I've heard of the PSP, the first 256 bytes of a program, but i don't know how to write that to a file, neither (or what it is, for that matter).

Do you think you could give me some help with this? Thanks in advance.

k stol

Reply by email

Alan Grimes
to K Stol
Show quoted text 7 lines
K Stol wrote: I'm trying to make a really simple compiler, and i'm getting there, but i have one problem. The program makes a tree of the program, so i I think i can find the hex-codes of the instructions, but how can i make a REAL executable, so i don't have to make an interpreter. I've heard of the PSP, the first 256 bytes of a program, but i don't know how to write that to a file, neither (or what it is, for that matter).

DOS supports two types of binaries.

-- Flat binaries ending with .com that are loaded at 0x100h. ( you can find interesting DOS data structures in the PSP!! =) (16-bit)

-- MZ executables, binaries that have an executable header with important inf0z. (16-bit)

DOS programs that use dos4gw are actually a format called "Linear Executable" -- 32 bit, that are linked to a 16-bit loader stub. -- freepascal uses a similar system.

(at the dos prompt, type "type myexe.exe".. the first two letters of the output is the type.)

Windows supports several other executable types such as "PE"

To link to binaries produced by other tools, you will need to output one of the standard executable formats, OMF, ELF, a.out, etc...

Do you think you could give me some help with this? Thanks in advance.

I'll try, but I have great difficulty with that...

om

If you get anywhere with this I will surely need your experience in developing my OS. =)

It feels good to be home on my 486. http://users.rcn.com/alangrimes/

Reply by email

Peter Vreman
to K Stol: I'm trying to make a really simple compiler, and i'm getting there, but i have one…
I'm trying to make a really simple compiler, and i'm getting there, but i have one problem. The program makes a tree of the program, so i can traverse it and generate program code. But i would like to generate the (binary) object code, so it can actually create .EXE files, which can be run under DOS / windows. I think i can find the hex-codes of the instructions, but how can i make a REAL executable, so i don't have to make an interpreter. I've heard of the PSP, the first 256 bytes of a program, but i don't know how to write that to a file, neither (or what it is, for that matter). Do you think you could give me some help with this? Thanks in advance.

There is somewhere on the net a book online called "linkers and loaders". And for the assembler part you can have a look at the sources of nasm.

Reply by email

Andreas K. Foerster
to K Stol: I'm trying to make a really simple compiler, and i'm getting there, but i have one…
K Stol wrote
I think i can find the hex-codes of the instructions, but how can i make a REAL executable, so i don't have to make an interpreter.

I don't know how far you are in programming, but creating a real compiler is a difficult thing.
But there are alternatives between a compiler and an interpreter.

Perhaps one of these is a solution for you:

1) You could make a converter to a programming language for wich you do have a complier. Examples for this are p2c, f2c, ...

2) Another interresting solution I found in the program BEC. It creates a pseudo-code and then it attaches the pseudo-code to the interpreter, so you just have one single executable. When you start the executable, you start the interpreter and this reads the pseudo-code from itself, ie. from the same file. But the enduser doesn't have to know about that. ;-)

btw. "pseudo-code" is simply the source code with the commands replaced by single bytes. Comments may be stripped away.

Tschuess Andreas

Reply by email