What?
mov cx, 0
mov dx, 0
mov di, 0
CmpString:
mov [Value + 1], si
; what's in si? Baal knows!!!
; whatever it is, low byte goes in [value + 1]
; high byte scribbles on whatever's next,
; "string" (+ 0) in this case
add [Value + 1], cx
; starting with 0, this won't do any further harm.
; when cx becomes 1, "[value + 1]" becomes
; whatever was in the low byte of si... + 1.
; "[string + 0]" remains whatever was in si high byte.
mov ax, [Value + 1]
; mov si(?) + cx (0 or 1) into ax,
; which is never heard from again
mov bh, [String + di]
; start with high byte of whatever was in si
; when di =1, [string + 1] would be '$' - whoopee!
add cx, 1
add di, 1
cmp bh, '$'
; when di =1, this should be true (we never get there)
jne ValCompare
; if not, go where???
; if bh = '$':
add dx, 1
cmp dx, 2
; this will become true... if we ever make two more passes
je End
; if true, jump to "end" - which appears to
; fall off the end of your code
; if not true, attempt to execute "value" and "string",
; then fall of the end of your code.
Value:
db 0, 0
String:
db "$$HelloWorld$$"
End:
Dude! This "isn't even wrong"!
There's potential for confusion here. Nasm does, in fact, know $$ - outside of a quoted string - as a special symbol, "start of section" (address).
section .text
; "org 0" is Nasm's default, if you don't say
mov ax, $$
This will put 0 in ax. But...
org 100h ; or maybe 7C00h?
section .text
mov ax, $$
now ax is 100h (or 7C00h). But as part of a quoted string, '$$' is just the two ascii characters '$' - 24h in my ascii table.
mov ax, '$$'
ax is 2424h.
Start over!
; nasm -f bin -o myfile.com myfile.asm
org 100h ; test it as a .com file
section .data ; Nasm (-f bin) will move this after "section .text"
string0 db "$$Hello, World$$" ; this won't print anything!
string db "Hello, World$$" ; this should print
section .bss ; Nasm would move this after ".data"
; but we don't have any uninitialized data
section .text
mov si, string
call print_$$_terminated_string
ret ; return to dos
print_$$_terminated_string:
; expects: pointer to string in si
; returns: nothing useful
.top:
mov al, [si] ; or "lodsb"
inc si ; replaces these two instructions
cmp al, '$'
jne .print_char
cmp byte [si], '$' ; check next char
je .done
; if not, "fall through" and print the one we've got
.print_char:
int 29h ; or your preferred "print char in al"
jmp .top
.done:
ret
;-----------------------------
That's untested, and may be wrong, but it should be closer than what you've got (I hope).
Best,
Frank