News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

@NOSTORAGE question

Started by MickD, January 16, 2006, 04:40:16 AM

Previous topic - Next topic

MickD

Given the statement from AoA below -
Quote
readonly

   abcd: dword; @nostorage

         byte `a', `b', `c', `d';




In this example, abcd is a double word whose L.O. byte contains 97 (`a'), byte #1 contains 98 (`b'), byte #2 contains 99 (`c'), and the H.O. byte contains 100 (`d'). HLA does not reserve storage for the abcd variable, so HLA associates the following four bytes in memory (allocated by the BYTE directive) with abcd.

While HLA doesn't reserve storage for abcd, if I tried to access abcd later I 'could' get "abcd" if I wanted to by accessing the starting address of abcd and adding a byte value to the address to get the next value, is that correct.

What confuses me is later in the text this program sample -

program adrsExpressions;

#include( "stdlib.hhf" );

static

    i:  int8; @nostorage;
            byte 0, 1, 2, 3;

begin adrsExpressions;

    stdout.put
    (
        "i[0]=", i[0], nl,
        "i[1]=", i[1], nl,
        "i[2]=", i[2], nl,
        "i[3]=", i[3], nl
    );
end adrsExpressions;


only ant int8 is declared and seems to achieve the same thing (ie. supplies a starting address for the first variable to step from). Why would you bother to declare a dword in the first sample???

Thanks,
Mick.

Sevag.K

Quote from: MickD on January 16, 2006, 04:40:16 AM
While HLA doesn't reserve storage for abcd, if I tried to access abcd later I 'could' get "abcd" if I wanted to by accessing the starting address of abcd and adding a byte value to the address to get the next value, is that correct.

Sure, by 'byte value' I assume you mean size of byte which is 1.  HLA doesn't reserve storage, but you do as soon as you enter any data that follows a @nostorage declaration.

Quote
only ant int8 is declared and seems to achieve the same thing (ie. supplies a starting address for the first variable to step from). Why would you bother to declare a dword in the first sample???

Thanks,
Mick.

HLA treats the address label as whatever you declare, you could just as well declare it a byte if you so choose.  In the 1st example, declaring it a dword later allows you to do something like this:  mov ( abcd, eax); which will move the ascii representation of 'abcd' into eax, which you won't be able to do without coersion if you declared it a byte.



To get a better understanding, you can use a @nostorage as an anonymous union.  eg:

a_byte :byte;  @nostorage;
a_word :word; @nostorage;
a_dword :dword; @nostorage;
dword 0;


With the above, *you* have reserved 1 dword size of storage.  You can access this storage as either byte, word or dword depending on which address label you access.


MickD

Quote from: Sevag.K on January 16, 2006, 05:50:46 AM

....  HLA doesn't reserve storage, but you do as soon as you enter any data that follows a @nostorage declaration.


that's what I suspected otherwise you would probably end up with memory overlapping(?)

Quote

HLA treats the address label as whatever you declare, you could just as well declare it a byte if you so choose.  In the 1st example, declaring it a dword later allows you to do something like this:  mov ( abcd, eax); which will move the ascii representation of 'abcd' into eax, which you won't be able to do without coersion if you declared it a byte.

To get a better understanding, you can use a @nostorage as an anonymous union.  eg:

a_byte :byte;  @nostorage;
a_word :word; @nostorage;
a_dword :dword; @nostorage;
dword 0;


With the above, *you* have reserved 1 dword size of storage.  You can access this storage as either byte, word or dword depending on which address label you access.


got that, now it all makes sense,
thanks Sevag.K  :U