Author Topic: The symbol $$ is always gives me the value zero...  (Read 9431 times)

Offline nasmkid

  • Jr. Member
  • *
  • Posts: 3
The symbol $$ is always gives me the value zero...
« on: November 21, 2010, 06:37:24 PM »
The symbol "$$" always gives value 0

Code: [Select]
[ORG 0]
jmp 07C0h:start     ; initialize CS:IP values (go to code segment 0x07C0)

SECTION .text
start:
   ; Update the segment registers
   mov ax, 0x7C0      ; 0x7C0 is code segment address, same initiated to other registers
   mov ds, ax
   mov es, ax
   mov ss, ax

   mov si, hello      ; print hello string on the screen

   cld         ; clear direction flag (set DF = 0) to increment SI register

   .l1:
      lodsb      ; load [SI] contents in to AL register and increment SI = SI + 1
      cmp al, 0      ; compare 0 (null) is received
      je .l2

      mov ah, 0Eh
      int 10h

      jmp .l1      ; continue to lable 'lbl_1'

   .l2:


   hello db 'Welcome hello world', 0

   times 510-($-$$) db 0
   dw 0AA55h
when it will give different value? any example please..

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: The symbol $$ is always gives me the value zero...
« Reply #1 on: November 21, 2010, 06:59:29 PM »
"$$" refers to the start of the section. With "org 0", this will be zero. What do you want it to be?

Best,
Frank


Offline cm

  • Jr. Member
  • *
  • Posts: 65
Re: The symbol $$ is always gives me the value zero...
« Reply #2 on: November 21, 2010, 07:29:10 PM »
The symbol "$$" always gives value 0

[...]

when it will give different value? any example please..

Assemble this and look at the output and list file.

Code: [Select]
    ; Note that in all these examples, you can replace $$ by $.
    ; They are the same for the first (pseudo-)instruction in a section.
    ; For all other instructions in the same section, $ is higher than $$.

  org 100h
  dw $$
    ; dw will write the word 100h, as the section (and file)
    ; really starts there in case of "org 100h"

  section foo align=16
  dw $$
    ; dw will write the word 110h, as the section "foo"
    ; will be behind the (default) section ".text"

  section bar align=16 vstart=38
  dw $$
    ; dw will write the word 38 ( = 26h), as that is the "virtual"
    ; start address used for calculations here. "align=16"
    ; matters only for the alignment inside the file; the
    ; virtual address is not affected by this attribute.

Some other things: In the bin output format, the labels section.NAME.start and section.NAME.vstart are defined by the (internal) linker, where NAME is the actual name. (That means, section.bar.start and section.bar.vstart are defined for the section named bar. That confused me early on as it isn't documented well.) section.NAME.vstart equals $$ if you are in the section named NAME; that label is therefore useful for getting another section's $$ without switching to that other section. section.NAME.start is later resolved as the same numeric value as section.NAME.vstart unless any of the vstart=, vfollows= and valign= attributes are used. These attributes can be used to make the "virtual" start address differ from the real start address. (The real start address is closely related to the actual offset in the file; it just considers the "org" offset too.)
C. Masloch