TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: FERNANDO ARIEL GONT
from: JOHN STEPHENSON
date: 1998-03-18 10:18:00
subject: Problem to make a compil

 FAG> I want to make an ASM compiler for a microprocessor. I want to start
 FAG> with one for the 6809.
 FAG> I think (and hope) it won't be too hard, but the fact is that I have
 FAG> one problem:
 FAG> Suppose I want to make a compiler for the 80x86, and I have to compile
 FAG> code such as:
 FAG> mov ax, 5633h
 FAG> jmp yeah
 FAG> mov bx, 7896h
 FAG> yeah:
 FAG> mov cx, 4543h
 FAG> Well, I don't know how to code the "jmp" instruction, as I don't have
 FAG> the address that equals "yeah" label.
 
One way is to go along, and when you see "yeah", push it onto a list
as a point to go back and patch the code. I'll show you:
What you read               What you do
~~~~~~~~~~~~~               ~~~~~~~~~~~
mov ax, 5633h           ->  B8 33 56
jmp yeah                ->  EB ??
                            [store this as an unresolved jump to "yeah"]
mov bx, 7896h           ->  BB 96 78
yeah:                   ->  [find any unresolved "yeah" jumps, and fill out 
                             correct jump information, in this case 3 bytes
                             later, so ?? -> 03]
mov cx, 4543h           ->  B9 43 45
So, you end up with:
B8 33 56 EB 03 BB 96 78 B9 43 45
If you see a later "yeah", you'll have the "yeah" symbol information saying
where yeah refers to. I hope that you're writing this compiler in a high
level language (ie Pascal or C)!
 FAG> I think I should compile the code in several steps
In this case it's not necessary. However, if you want to put in "smart"
jumps, then you'll have to link. Basically, you create an object file,
then put all of the jumps together and write your optimized .com file.
The problem arises because there is more than one way to jump. You can
jmp using either a one byte relative address, a two byte relative address,
or a four byte absolute address.
Good luck putting together such a compiler. They get very tricky.
 
 FAG>, but I don't know
 FAG> the best way to do it, and besides I have some ideas, I would like to
 FAG> know how compilers solve this problem...
 
I'm in the process of trying to write a high-level single-pass compiler. 
If anyone knows anything on compilers, I'd love to talk to them.
 FAG> I'd like to hear your better ideas to do it, would also be pleased if
 FAG> you'd have any internet addresses about how to make compilers (.PDF,
 FAG> .TXT, .DOC, .HTM, .WHATEVER).
 
Same here. Make sure to pass along any info to me. I know that there are
computer books available on the subject, but they also carry high prices.
Hope it was helpful.
                                       - DarkFire 
[John Stephenson (an INTP), Fingerprint: 66BE3A3B6EEE9A5B-48001A32901ECA21]
[Composed at 3:31:34p on 1998-03-18 (UTC) using PGPWave v1.24a Beta]
--- Maximus 2.01wb
---------------
* Origin: *Synthesis* Kingston, Ont., Canada! (1:249/127)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.