News:

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

why allocated non-named blocks

Started by thomas_remkus, January 22, 2007, 04:11:07 PM

Previous topic - Next topic

thomas_remkus

In the documentation for MASM I see:

signedexp       SWORD   4*3         ; Initialize signed word to 12
empty           QWORD   0           ; Initialize qword to 0
                BYTE    1,2,3,4,5,6 ; Initialize six unnamed bytes
long            DWORD   4294967295  ; Initialize doubleword to 4,294,967,295


Why would I want to initialize six (or any) unnamed bytes? Is this just used for alignment?

stanhebben

The six unnamed bytes are unnamed, but can be accessed by adding 8 to the address of empty.

movzx eax, byte ptr [empty + 8]

will put 1 in eax.

thomas_remkus

Why would this be any advantage? Is there a penalty for giving memory labels (meaning, giving a name to a memory block)?

Tedd

It means you don't have to think of labels for those bytes :lol
More usefully, if you have a long list of numbers and don't want to have to fit it all on one line (masm has a limit anyway), then you can span it across multiple statements - without needing to name each one.

The names only exist as far as the assembler (and linker, sometimes) is concerned, to make the references easier to read (for humans), once the program is assembled the labels disappear -- they're substituted for the offsets of the positions they represent.
(On the other hand, each label will add to the symbol table, which can increase assembly time, but a few extra labels isn't going to make much difference.)
No snowflake in an avalanche feels responsible.

ramguru

Quote from: thomas_remkus on January 22, 2007, 04:11:07 PM
Why would I want to initialize six (or any) unnamed bytes? Is this just used for alignment?

It can help to write unconditioned/branchless code. I always take advantage of tables and arrays for that purpose.

thomas_remkus

Oh "snap"! Unconditioned code ... I'm just not ready for that. But thanks for the hint just in case that's something I need to look at one day.

hutch--

thomas,

Its very simple really, with initialised data you only need to know the start address or what is commonly called a data label. You can write data like this.


txt db "This is a "
    db "text",0


Beware of running data as code because later Windows OS versions have data execution prevention to block a particular type of exploit so its not a reliable technique any longer.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php