Search code examples
assemblymasm

Assembly $ character semnification


I have a difficult exam (for me :D ) and can't find the signification of '$' character. As an example, I have the next code:

DATA    SEGMENT
vector  db    00h,10h,20h,30h,40h
        db    50h,60h,70h,80h,90h   
lv      equ   ($ - vector)/TYPE vector 

Can someone tell me which is the value of lv?


Solution

  • The $ contains the address where the current instruction will be.

    The value of lv will be the number of items in the vector data. The expression ($ - vector) calculates the number of bytes from the vector label to the place in the code where the $ is used, i.e. where lv is declared.

    The length is divided by the size of the data used in vector. If you had ten words instead of bytes, then lv would still be 10, as the 20 bytes that it occupies would be divided by 2.