Need exemples of modular relocatable asm source

Here you can ask questions or provide insights about how to use efficiently 6502 assembly code on the Oric.
Post Reply
User avatar
norik
1st Star Corporal
Posts: 15
Joined: Wed May 24, 2006 8:46 am
Location: ZZ9 Plural Z Alpha, Earth, Armenia, Yerevan
Contact:

Need exemples of modular relocatable asm source

Post by norik » Thu Jan 25, 2007 1:04 pm

Hello :)
I know how to write in asm when I decide where to store variables etc.
Now I examples of asm code for modular programming using relocatable code.
for instance I need examples howto define hidden and exported variables in .data and .bss segments, I also want to have example of pointer to struct.
In other words I am very interested in examples of howto hide and export variables
encapsulated in .o relocatable. And how to use (import) that variables from another relocatable.
May be it will be easier for someone just translate the following oberon source to xa65 or ca65 asm syntax so I could understand :)

Code: Select all

MODULE M1; 
VAR a*,b,e- : SHORTINT; (* signed byte*) 
(* note that a is exported and could be seen rw from other module *) 
(* b is hidden*) 
(* e is exported read only*) 
PROCEDURE p*; (*this procedure is exported*) 
(*it could be called from other module *) 
VAR a, f : INTEGER; (* signed int *) 
BEGIN 
a := 5; (*assigning to local variable*) 
b := 7; 

END p; 

PROCEDURE p1; (* hidden procedure, cannot be called from outside *) 
BEGIN 

END; 

BEGIN 

a := 7; 
e := 9; 
END M1. 

------------------------------ 
MODULE M2; 
IMPORT M1; 

VAR a : INTEGER; 
BEGIN 

a := M1.a; 
M1.p; 

END M2

User avatar
Dbug
Site Admin
Posts: 2942
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Post by Dbug » Thu Jan 25, 2007 9:29 pm

Well, I'm using Xa (as a part of the OSDK), and I have no idea of how doing what you are talking about.

The only thing I'm using, is that if I want to see a label defined in an assembly code module from a C module, I need to prefix with an underscore.

For remaining thing, I use just automatical allocation using .zero, .text and .bss sections with .byt, .word, or .dsb or .dsw.

There is also a list of exported symbols in a text file, that can probably used to generate defines with adresses, that's doable...

If you were explaining what you want to do, perhaps we could find a way to do it.

User avatar
norik
1st Star Corporal
Posts: 15
Joined: Wed May 24, 2006 8:46 am
Location: ZZ9 Plural Z Alpha, Earth, Armenia, Yerevan
Contact:

Post by norik » Thu Jan 25, 2007 9:59 pm

to be honest I am writing a new compiler for Oric Atmos
The language is strong typed and modular
Now compiler generates code and calculates addresses of variables at compile time.
Compiler may be configured to use this or that area of memory to store variables.
I am yet not professional in writing compilers, I am just learning.
I can program in machine code, I can use xa65 for it but I do not understand how to produce relocatable code, how to deal with modules to have exported variables or to pass variable by reference to a function residing in an another object file using xa65!
Thank you

User avatar
Dbug
Site Admin
Posts: 2942
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Post by Dbug » Fri Jan 26, 2007 12:15 am

Why not just trying to get your compiler for your language to just produce a Xa (or other) compatible source code ?
Now compiler generates code and calculates addresses of variables at compile time.
Compiler may be configured to use this or that area of memory to store variables.
Does your compiler really needs to calculate adresses of variables ? Can it not work with labels and symbolic names ? That would be so much easier.

Typicaly it's what the Oric C compiler is doing. It generates some pseudo assembler language for a virtual 16 bits processor, this is then converted as 6502 assembler using macros. Not pretty, but it works really fine.

Advantage of that is that you get a monolithic program that can be made of heterogeneous parts, partly C, partly assembler, and why not partly your own language ? And if you follow the same parameter passing convention, you can even access the existing library of functions.
I can program in machine code, I can use xa65 for it but I do not understand how to produce relocatable code, how to deal with modules to have exported variables or to pass variable by reference to a function residing in an another object file using xa65!
Well, do you really need to get *modules*

CC65 generates real objects files, that are then linked together to produce the final executable.

The choice made in the OSDK is to get everything generated as 6502 assembler source files that are just merged together in one single "linked.s" file that then get assembled with XA.

It's so much more practical.

I understand that the requirement for object files and libraries and linker are important for real languages on real machines on real big projects, but on the Oric the size of the biggest possible project is so small, that seriously having real linkers is not that interesting. I can see the intellectual satisfaction, but I can hardly see any practical adventage.

User avatar
norik
1st Star Corporal
Posts: 15
Joined: Wed May 24, 2006 8:46 am
Location: ZZ9 Plural Z Alpha, Earth, Armenia, Yerevan
Contact:

Post by norik » Fri Jan 26, 2007 9:03 am

Dbug wrote:Why not just trying to get your compiler for your language to just produce a Xa (or other) compatible source code ?
this is what I am trying to do.
Now compiler generates code and calculates addresses of variables at compile time.
Compiler may be configured to use this or that area of memory to store variables.
Does your compiler really needs to calculate adresses of variables ? Can it not work with labels and symbolic names ? That would be so much easier.
I know that compile time calculations isn't a good idea. it complicates implementation of modular language.
Typicaly it's what the Oric C compiler is doing. It generates some pseudo assembler language for a virtual 16 bits processor, this is then converted as 6502 assembler using macros. Not pretty, but it works really fine.
Yes, I have read paper about lcc implementation ;)
I want to implement easily portable compiler without an intermeddiate representation :)
Advantage of that is that you get a monolithic program that can be made of heterogeneous parts, partly C, partly assembler, and why not partly your own language ? And if you follow the same parameter passing convention, you can even access the existing library of functions.
I am planning to support C calling conventions as well to have a possibility to link with lcc and cc65 generated object files. But now it is not the first problem I have :)
Besides, my compiler will support inline asm code, it is necessary to implement fast and small standard library :)
I can program in machine code, I can use xa65 for it but I do not understand how to produce relocatable code, how to deal with modules to have exported variables or to pass variable by reference to a function residing in an another object file using xa65!
Well, do you really need to get *modules*
CC65 generates real objects files, that are then linked together to produce the final executable.
The choice made in the OSDK is to get everything generated as 6502 assembler source files that are just merged together in one single "linked.s" file that then get assembled with XA.
I want to implement real separate compilation with type checking across module boundaries.
But my first problem is difficulties to work with modern asm, i. e. produce relocatable obj.
In the future I'll discuss some code templates. as I have been written machine code without an assemblers it is somewhat hard to start working with them. I need help and/or in even very simple things: how to allocate variable without knowing its exact address.
Anyway in the future I want to generate object file immeditially with one pass compiler. But not now :)

User avatar
norik
1st Star Corporal
Posts: 15
Joined: Wed May 24, 2006 8:46 am
Location: ZZ9 Plural Z Alpha, Earth, Armenia, Yerevan
Contact:

Post by norik » Tue Jan 30, 2007 10:30 am

ok, I found out how to do what I want but with ca65 not xa65 :)
This night my compiler generated its first ca65 code ;)
Thank you very much.
Hope soon I will consider compiler working and ready to publish ;)

User avatar
Dbug
Site Admin
Posts: 2942
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Post by Dbug » Tue Jan 30, 2007 4:02 pm

Code: Select all

I need help and/or in even very simple things: how to allocate variable without knowing its exact address. 
With XA you have the choice between using .byte/.word or .dsb/.dsw

The first category allocates room and set values in one go:

Code: Select all

TablePrimes
   .byte  2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61
   .byte  67,71,73,79,83,89,97,101,103,107,109,113
The second category allows you to reserve room:

Code: Select all

Buffer
   .dsb 23    ; Reserve 23 bytes

Post Reply