Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

Somebody can explain me these lines ?

C++
buffer: db 'hello, world'
times 64-$+buffer db '_'


result : "hello, world____________________________________________________"

I understand these lines below, it makes sense (addresse where we stand minus addresse of the beginning of the program = size of the program in bytes) :

C++
times 510 - ($-$$) db 0


But in the first expression how $+buffer can make 52 ?? i just don't get it why a + not a - ?

Thanks for help by advance :)

What I have tried:

i have tried to fine some explanation on google or whatever but without any success
Posted
Updated 3-Aug-16 23:46pm
v4

1 solution

C++
buffer: db 'hello, world'
times 64-$+buffer db '_'

Assume the location of buffer is 1000, then the location of times (identified by the $ sign) is 1012.
So:
64 - 1012 = -948
-948 + 1000 = 52

The expression effectively calculates the number of dashes to add to the previous string to make a total of 64 characters.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900