English Amiga Board


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

 
 
Thread Tools
Old 26 December 2018, 22:16   #1
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
vasm/mot: data structures

I've been using RS to define some data structures, like this:
Code:
    EVEN
    rsReset                          ; start struct scrTxtMem
scrTxtMem_PtrTopBlank       rs.l 1   ; pointer to top blank
scrTxtMem_PtrTopOpen        rs.l 1   ; pointer to top open/visible area
scrTxtMem_PtrBottomBlank    rs.l 1   ; pointer to bottom blank
scrTxtMem_SizeOf            rs.w     ; end/size of struct scrTxtMem
This works as expected. Also see here: http://eab.abime.net/showthread.php?t=94746

I was doing this from memory recently, and assumed that I did not need to specify the number of parameters if I only wanted 1. So I assumed writing just
rs.l
was equivalent to writing
rs.l 1
. This is clearly not the case. I think it defaults to
rs.l 0
, but I'm not sure.

I've been looking in the manual for info on the syntax of the
rs.b|w|l
'directive' (?), but I can't seem to find much. I can info on the set/reset/clr directives for so/fo, and how rs is very similar, but nothing specific on defining the fields/properties of the rs/so/fo structure.

Am I missing something? And shouldn't it default to 1, instead of 0?
guy lateur is offline  
Old 27 December 2018, 00:55   #2
arcanist
Registered User
 
Join Date: Dec 2017
Location: Austin, TX
Age: 41
Posts: 405
I think this covers what the directive is actually doing:

Quote:
<label> rs.<size> <expression>

Works like the so directive, with the only difference that the offset symbol is named __RS.
Quote:
<label> so.<size> <expression>

Assigns the current value of the structure offset counter to <label>. Afterwards the counter is incremented by the instruction’s <size> multiplied by <expression>. Any valid M68k size extension is allowed for <size>: b, w, l, q, s, d, x, p. The offset counter can also be referenced directly under the name __SO.
The RS directive isn't specific to structures. It has other uses and so it's not too surprising the manual only defines the semantics of the label and how it's manipulated. The structure "fields" are just labels with convenient offsets from the base of the structure.

You're right that it doesn't clarify what happens when <expression> is omitted. It rather looks like the syntax should be rejected.
arcanist is offline  
Old 27 December 2018, 11:03   #3
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by arcanist View Post
I think this covers what the directive is actually doing:
<snip>
Hehe, I did find that first manual entry, that refers to the second one, which, for some reason, I did not see. I guess it was getting late and I was getting tired. I did search for so.b and so on, but not for so.<size>.

Quote:
Originally Posted by arcanist View Post
You're right that it doesn't clarify what happens when <expression> is omitted. It rather looks like the syntax should be rejected.
I agree that it would probably make more sense to have it throw an error when you leave out the <expression>, something Ă  la "you need to specify a number of instances for this field". Also, I'm not sure about why you'd ever want 0 instances of a field. Maybe to have it ready as a place holder, to be filled in later?

Anyway, thanks a lot for your help; I'm glad we've got this sorted out now. This had me bug hunting for a couple of hours yesterday..
guy lateur is offline  
Old 27 December 2018, 19:26   #4
Bruce Abbott
Registered User
 
Bruce Abbott's Avatar
 
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,546
Quote:
Originally Posted by guy lateur View Post
I agree that it would probably make more sense to have it throw an error when you leave out the <expression>,
Apparently not, because...

Quote:
vasm history
=============

- 1.7c (15.05.15)

o mot-syntax: Fixed RS.x without operand (same as RS.x 0).

Quote:
Originally Posted by guy lateur View Post
Also, I'm not sure about why you'd ever want 0 instances of a field. Maybe to have it ready as a place holder, to be filled in later?
Why have an 'RS.x' that creates zero 'instances' at all? Because often you need to know the size of a structure.

For a better understanding of what RS was designed to to, take a look at the structure macros it replaces. Here are some examples from exec/types.i:-

Code:
STRUCTURE MACRO          ; structure name, initial offset
\1        EQU   0
SOFFSET   SET   \2
          ENDM

ULONG     MACRO          ; unsigned long (32 bits)
\1        EQU   SOFFSET
SOFFSET   SET   SOFFSET+4
          ENDM

APTR      MACRO          ; untyped pointer (32 bits - all bits valid)
\1        EQU   SOFFSET
SOFFSET   SET   SOFFSET+4
          ENDM

STRUCT    MACRO          ; Define a sub-structure
\1        EQU   SOFFSET
SOFFSET   SET   SOFFSET+\2
          ENDM

LABEL     MACRO          ; Define a label without bumping the offset
\1        EQU   SOFFSET
          ENDM
The variable SOFFSET is manipulated by these macros in the same way that __RS is manipulated by the RS directives.

RS is more efficient than macros because the assembler has less to do, but I don't use it because:-

1. My standard header files are preassembled so there's no efficiency improvement.

2. Structure macros put more type information into the source, so you can see at a glance whether eg. your 4 byte entry is supposed to be an unsigned long or an address pointer.

3. Structure macros are closer in style to C structures, making it easier to port code from C to assembler.
Bruce Abbott is offline  
Old 27 December 2018, 20:00   #5
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by Bruce Abbott View Post
Why have an 'RS.x' that creates zero 'instances' at all? Because often you need to know the size of a structure.
Hmm, I also tend to have 1
scrTxtMem_SizeOf rs.w
at the end of my structures, but I usually have a lot more
scrTxtMem_x rs.w 1
in there, which still makes 0 the wrong default to pick, in my opinion/cases.

Btw, another reason for having 0 instances could be to have multiple names for the same field. Maybe to help some kind of memory usage optimisation or something? Just thinking out loud, here..

Quote:
Originally Posted by Bruce Abbott View Post
For a better understanding of what RS was designed to to, take a look at the structure macros it replaces.
Thanks for the example and reasoning, I'll look into that.
guy lateur is offline  
Old 28 December 2018, 20:11   #6
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by guy lateur View Post
I agree that it would probably make more sense to have it throw an error when you leave out the <expression>
Oh. Hmm...
It's always good when such a topic comes up here, because it makes me think about my decisions from the past again.

In fact, there should be an error! At least in Devpac-compatibility mode. Leaving the expression away was a shortcut, which I introduced in the PhxAss assembler many decades ago. And with vasm 1.7c I probably decided to make vasm behave the same, because some of my own sources depend on it.

But it never worked like this in any other assembler. Neither in Devpac, nor AsmOne, AsmPro, Barfly, SNMA, etc...

So I guess I will make it a vasm feature, which is disabled with -devpac compatibility option. Too bad I just tagged the V1.8e release for tomorrow.


Quote:
Originally Posted by Bruce Abbott View Post
Why have an 'RS.x' that creates zero 'instances' at all? Because often you need to know the size of a structure.
Exactly! It was needed for every structure I defined, so I decided at some point that I would like to leave the '0' away.
phx is offline  
Old 28 December 2018, 21:06   #7
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by phx View Post
But it never worked like this in any other assembler. Neither in Devpac, nor AsmOne, AsmPro, Barfly, SNMA, etc...

So I guess I will make it a vasm feature, which is disabled with -devpac compatibility option.
Please let me understand this correctly: you are going to change the -devpac compatible behaviour to throw an error when the size is not specified? So I won't notice this change unless I specify -devpac compatibility? Is this correct?

Btw, my source still compiles with -devpac compatibility (phew!), but it throws quite a few warnings about data auto-alignment -- which are probably suppressable, though..

Quote:
Originally Posted by phx View Post
Too bad I just tagged the V1.8e release for tomorrow.
Don't worry about this not getting into 1.8e release. We're lucky enough to have you consider these kinds of questions, about decisions made tens of years ago (!), and update vasm where appropriate. Not a lot of dev environments come with this kind of support, I think..
guy lateur is offline  
Old 28 December 2018, 22:47   #8
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by guy lateur View Post
Please let me understand this correctly: you are going to change the -devpac compatible behaviour to throw an error when the size is not specified?
Yes. Because real Devpac does the same.

Quote:
So I won't notice this change unless I specify -devpac compatibility? Is this correct?
Correct.

Quote:
Btw, my source still compiles with -devpac compatibility (phew!), but it throws quite a few warnings about data auto-alignment -- which are probably suppressable, though..
Be careful here! That could be bad data alignments in your source. Something like...
Code:
        even
        dc.b    1
label:
        dc.w    2
...would be assembled by vasm in default mode without warning and does exactly what is written in the source: it writes the word $0002 at an unaligned address. When you access the word at "label" on the 68000 or 68010 your program will cause an alignment exception (AKA address error, Guru #3).

Devpac has auto-alignment enabled. But unlike the real Devpac vasm warns about all those auto-alignments, so you can check and fix them.
phx is offline  
Old 29 December 2018, 20:43   #9
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by phx View Post
Be careful here! That could be bad data alignments in your source.
Quote:
Originally Posted by phx View Post
Devpac has auto-alignment enabled. But unlike the real Devpac vasm warns about all those auto-alignments, so you can check and fix them.
Ok, thanks for the heads up. It seems I'm lucky to be targeting and testing on an A1200/020, then..

So I guess I should probably have devpac compatibility turned on at all times? It feels a bit weird, though, because it says in the manual that 'Only directives known to Devpac are recognized', which feels like a step back with respect to the more modern developments of vasm. Or will I just be getting the best of both worlds in that case?
guy lateur is offline  
Old 29 December 2018, 21:47   #10
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by guy lateur View Post
Ok, thanks for the heads up. It seems I'm lucky to be targeting and testing on an A1200/020, then..
Or rather unlucky that the bugs haven been hidden so long. Except you don't care for 68000 compatibility.

Quote:
So I guess I should probably have devpac compatibility turned on at all times?
No. It just exists for assembling old sources, or to test compatibility when you want to guarantee that it assembles the same on Devpac.
Most (all?) Devpac features can be enabled in standard vasm mode with options or directives. Automatic data alignments just need the -align option.
phx is offline  
Old 29 December 2018, 22:15   #11
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by phx View Post
No. It just exists for assembling old sources, or to test compatibility when you want to guarantee that it assembles the same on Devpac.
Ok I see, then I probably will have not much use for it, as I don't have any old sources to compile, and I don't see any requirement to compile my source with Devpac. At least not for now..

Quote:
Originally Posted by phx View Post
Most (all?) Devpac features can be enabled in standard vasm mode with options or directives. Automatic data alignments just need the -align option.
Alright, got it, thanks!
guy lateur 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
vasm/mot: structure guy lateur Coders. Asm / Hardware 20 05 January 2020 00:01
vasm/mot: include failed error message guy lateur Coders. Asm / Hardware 6 23 December 2018 20:29
some starglider 2 data structures ara Coders. General 11 11 March 2011 19:56
Memory Data Structures Zetr0 support.Hardware 7 30 September 2007 17:38
IFF/ILBM structures .... freddix Coders. General 7 18 September 2006 09:54

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 16:45.

Top

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