English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 20 August 2017, 10:47   #1
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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)
jotd is offline  
Old 20 August 2017, 11:51   #2
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by jotd View Post
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?
Hi jotd, your code is incorrect.
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
ross is offline  
Old 20 August 2017, 13:43   #3
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
I suspected so. Thanks.

I could substract the size to A4 and add it just before unlk then.
jotd is offline  
Old 20 August 2017, 15:01   #4
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by jotd View Post
I suspected so. Thanks.

I could substract the size to A4 and add it just before unlk then.
Yes.

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)
You need to have a total control over subroutine call nesting!
LINK is for high level languages where the subroutine calls is not known at priori..

You even gain a spare A register

Bye,
ross
ross is offline  
Old 20 August 2017, 16:49   #5
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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.
jotd is offline  
Old 20 August 2017, 21:11   #6
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by jotd View Post
I was trying to use a structure linked to the stackframe but vasm refused to use NLONG, NSTRUCTURE,
What are NLONG and NSTRUCTURE? Macros? What are they doing?

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
phx is offline  
Old 20 August 2017, 23:36   #7
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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.
jotd is offline  
Old 21 August 2017, 11:41   #8
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by jotd View Post
NLONG & NSTRUCTURE are probably defined in some system define that I'm not including.
Not in any system includes I know. That's why I asked. Would be interesting to see what they are doing. I'm always interested in improving vasm's compatibility.
phx is offline  
Old 22 August 2017, 00:25   #9
Wepl
Moderator
 
Wepl's Avatar
 
Join Date: Nov 2001
Location: Germany
Posts: 866
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.
Wepl is offline  
Old 22 August 2017, 09:11   #10
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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.
jotd is offline  
Old 26 August 2017, 16:55   #11
Wepl
Moderator
 
Wepl's Avatar
 
Join Date: Nov 2001
Location: Germany
Posts: 866
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
is shorter than link/unlk + clear
Wepl is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:14.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08589 seconds with 15 queries