Hi,
I have a main programme in assembly, and I wish to add some functions with integer arithmetics, easier coded in C possibly (or Pascal).
I use mainly `GST Assembler' (first prog I had on my QL) and just started looking into `GST C'. Assembly has now some unresolved labels, thats where the `C' functions should go.
Is there any general recipe how to merge a final binary through a linker?
Many thanks
Tomas
Link ASM and C code
Re: Link ASM and C code
Hi,
I resorted to `ASM' coding only. `C' might still be a better option for porting code from high level languages. To make assembly easier, I use `named' local variables on the stack de/allocated with link..unlk pair of calls. Hope is reasonable, and correct.
EDIT offsets have to be negative, as stack grows down
EDIT $00 seems wrong, has to be -$02 for cf_x0, last word on the stack
Tomas
I resorted to `ASM' coding only. `C' might still be a better option for porting code from high level languages. To make assembly easier, I use `named' local variables on the stack de/allocated with link..unlk pair of calls. Hope is reasonable, and correct.
EDIT offsets have to be negative, as stack grows down
EDIT $00 seems wrong, has to be -$02 for cf_x0, last word on the stack
Code: Select all
circf link a4,#-14 ;locals cf
cf_x0 equ -$02
cf_y0 equ -$04
cf_col equ -$06
cf_r equ -$08 ;radius
cf_x equ -$0a
cf_y equ -$0c
cf_r2 equ -$0e ;rad square
move.w d1,cf_x0(a4) ;save locals
move.w d2,cf_y0(a4)
...
unlk a4
rts
Last edited by tcat on Mon Jun 03, 2019 10:58 am, edited 3 times in total.
-
- Font of All Knowledge
- Posts: 3994
- Joined: Mon Dec 20, 2010 11:40 am
- Location: Sunny Runcorn, Cheshire, UK
Re: Link ASM and C code
Hi Tomas,
I would think you need to compile the Pascal or C programme to an object code module, then use the Linker to link all the object code modules to a single binary file.
I would think you need to compile the Pascal or C programme to an object code module, then use the Linker to link all the object code modules to a single binary file.
Regards,
Derek
Derek
- janbredenbeek
- Super Gold Card
- Posts: 633
- Joined: Wed Jan 21, 2015 4:54 pm
- Location: Hilversum, The Netherlands
Re: Link ASM and C code
It's much easier to code the main program in C and the timing-critical routines in assembly than the other way round. The C program needs libraries and startup code to initialise registers and variables where the libraries depend upon. Also a main() function MUST be present since the startup code will eventually call this to execute the main program, and the linker will complain when it's not there.tcat wrote:Hi,
I have a main programme in assembly, and I wish to add some functions with integer arithmetics, easier coded in C possibly (or Pascal).
I use mainly `GST Assembler' (first prog I had on my QL) and just started looking into `GST C'. Assembly has now some unresolved labels, thats where the `C' functions should go.
Is there any general recipe how to merge a final binary through a linker?
Thinking of it, it would be best to call the assembly from the main() function and call the C functions back from there. This requires certain registers to be preserved - the QC manual has a quite extensive section on interfacing with assembly.
Jan.
Re: Link ASM and C code
That's actually true for C68, which uses a relocating loader and extensive startup code. GST C, being a "small C" derivate, is much simpler. As long as you don't use any library functions, you don't even need to link with C startup code, but can directly create _asm, then _rel files with the C compiler. You can treat such _rel files with C origin just like standard assembler files.janbredenbeek wrote:It's much easier to code the main program in C and the timing-critical routines in assembly than the other way round.tcat wrote:Hi,
I have a main program in assembly, and I wish to add some functions with integer arithmetics, easier coded in C possibly (or Pascal).
If you don't use the C startup code and runtimes in your C program, you also don't need a main() function.janbredenbeek wrote: The C program needs libraries and startup code to initialise registers and variables where the libraries depend upon. Also a main() function MUST be present since the startup code will eventually call this to execute the main program, and the linker will complain when it's not there..
(Admitted, the C code isn't much more comfortable to write then than assembly)
Tobias
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Re: Link ASM and C code
Gents,
Thanks.
I seem getting a lot of advice. Honestly I have not tried linking various `_rel' object files. An intersting exercise I wish to do anyway. `C' runtime and some std lib may seem an overhead for a small project such as this one of mine.
I was also thinking to link various `_bin', or `_rel' produced by the assembler itself, as I have quite a few lables in the source already, making code modular can help to resolve duplicates.
Many thanks.
Tomas
Thanks.
I seem getting a lot of advice. Honestly I have not tried linking various `_rel' object files. An intersting exercise I wish to do anyway. `C' runtime and some std lib may seem an overhead for a small project such as this one of mine.
I was also thinking to link various `_bin', or `_rel' produced by the assembler itself, as I have quite a few lables in the source already, making code modular can help to resolve duplicates.
Many thanks.
Tomas