20 August 2017, 10:47 | #1 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,370
|
LINK instruction hell
Hi,
I was trying to use a structure linked to the stackframe but vasm refused to use NLONG, NSTRUCTURE, ... so I adapted to use only positive offsets. Now the code runs but I hope it's not out of luck: Is the code below correct? (offsets of struct should be positive?) note the minus sign when linking, then I should have my structure ahead of A4? or below? Code:
GL EQUR A4 ;a4 ptr to Globals STRUCTURE Globals,0 ULONG gl_chipptr ULONG gl_fastptr ULONG gl_hunk_align ULONG gl_create_segments ULONG gl_exec_file_location ULONG gl_default_reloc_address ULONG gl_exec_file_size ULONG gl_exec_mapped_size ULONG gl_default_output_address LABEL gl_SIZEOF ... link GL,#-gl_SIZEOF ; clear structure memory is that OK? move.l GL,A3 move.l #gl_SIZEOF/4-1,d1 .clr clr.l (a3)+ dbf d1,.clr ... ; store some pointer in an offset, is that OK? move.l (A1)+,(gl_chipptr,GL) |
20 August 2017, 11:51 | #2 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,491
|
Quote:
LINK instruction is like: LINK a4,#-x = move.l a4,-(a7); movea.l a7,a4; lea -x(a7),a7. So to get access to local variable you need negative offset (and positive for stack parameters, if you have some). Regards the CLR is up to you (LINK do not clear anything so surely you get undefined stack space). Bye, ross |
|
20 August 2017, 13:43 | #3 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,370
|
I suspected so. Thanks.
I could substract the size to A4 and add it just before unlk then. |
20 August 2017, 15:01 | #4 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,491
|
Quote:
However there is an alternative that I often use: directly use A7 as the BASE register. So simply: Code:
lea -gl_SIZEOF(a7),a7 if needed { move.l a7,A3 move.l #gl_SIZEOF/4-1,d1 .clr clr.l (a3)+ dbf d1,.clr } ... move.l (A1)+,(gl_chipptr,a7) LINK is for high level languages where the subroutine calls is not known at priori.. You even gain a spare A register Bye, ross |
|
20 August 2017, 16:49 | #5 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,370
|
thanks but I'm performing the LINK in the main routine, then I'm calling several subroutines, so that won't work. Thanks for the help with LINK. Helpful.
|
20 August 2017, 21:11 | #6 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,545
|
Quote:
The FO directive (Frame Offset) can be used for negative offsets. For example: Code:
rsreset a fo.l 1 b fo.w 1 c fo.b 1 sizeof fo.b 0 |
|
20 August 2017, 23:36 | #7 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,370
|
NLONG & NSTRUCTURE are probably defined in some system define that I'm not including. They probably negate the value of ULONG & STRUCTURE so they're compatible with the way LINK works.
fo directive: really interesting, didn't know that. PS: your assembler is a godsend. |
21 August 2017, 11:41 | #8 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,545
|
|
22 August 2017, 00:25 | #9 |
Moderator
Join Date: Nov 2001
Location: Germany
Posts: 876
|
hi jotd, you maybe saw the N* macros in some of my sources, you can find the include file for example in the whdload_dev archive (WHDLoad/Src/macros/ntypes.i).
It defines most of the exec/types.i with negative offsets to be used with link/unlk. BTW: if you need to clear the variables link/unlk will not save code anymore, in this case you can use the clear code to decrement a7 and use a normal structure with positive offsets. then also the first variable can be accessed without offset (a7). Last edited by Wepl; 22 August 2017 at 00:32. |
22 August 2017, 09:11 | #10 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,370
|
yes, it was from your "RELOC" executable.
"if you need to clear the variables link/unlk will not save code anymore": what? Yes, I could clear A7 until I get the required size, then assign A4 or A5 to this value. Pop in the end. I'll end up throwing that LINK stuff away, not really useful for hand-written asm. |
26 August 2017, 16:55 | #11 |
Moderator
Join Date: Nov 2001
Location: Germany
Posts: 876
|
Why do you need to use a different base register then a7?
Are you calling your functions with registers on the stack? In this case it may be a bit uncomfortable. Code:
STRUCTURE bla,0 WORD bla_bum ... ALIGNLONG LABEL bla_SIZEOF _func movem.l rl,-(a7) moveq #bla_SIZEOF/4-1,dx .clr clr.l -(a7) dbf dx,.clr move #33,(bla_bum,a7) add.w #bla_SIZEOF,a7 movem.l (a7)+,rl rts |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Hell Hell Hell why i continue have core dump on qemu-uae! | tlosm | support.FS-UAE | 7 | 02 January 2019 01:23 |
Question about the TAS instruction. | Thorham | Coders. General | 7 | 03 April 2011 13:12 |
Please help me: one by one instruction needed | JewStrangler | support.WinUAE | 15 | 20 September 2010 18:55 |
$48e70000 instruction | Asman | Coders. General | 5 | 10 February 2006 23:00 |
|
|