I'm reading NASM documentation and stuck upon the following code in section 3.2.5 TIMES: Repeating Instructions or Data
buffer: db 'hello, world'
times 64-$+buffer db ' '
They say this code will store exactly enough spaces to make the total length of buffer up to 64
. Unfortunately, I didn't get it at all. The expression 64-$+buffer
which is supposed to return a number seems very suspicious. So I want someone to explain the semantics if I didn't get right. My knowledge isn't enough to print the resulting number nor to check if the space was allocated as intended. Here is how I tried to de-parse it:
64-$+buffer
is an arithmetic expression returning a number$
is a current location which should be equal to 13buffer
is a labeled location and it equals to 0 if it's the very beginning of the section.data
. Otherwise, we quickly get a negative number (which I suppose isn't what intended here).
If the above is true, then we get a buffer filled by 64 space characters where the first 12 is hello, world
. Am I right?