Miscellaneous > 16 bit DOS Programming

What is $-msg

(1/4) > >>

Shintaro:
Hi,
Hopefully, I don't embarrass myself too much, what the heck is "$-msg". Is it a macro or something?
P.28 Advanced MSDOS Programming.

I searched through Ray Duncans Book but can't find anything. Is it some inbuild way to calculate the length of the string?



Using MASM 5.1



--- Code: ---stdin equ 0
stdout equ 1
tderr equ 2

cr equ 0dh
lf equ 0ah
_TEXT segment word public 'CODE'


 org 100h

 assume cs:_TEXT,ds:_TEXT,es:_TEXT,ss:_TEXT
print proc near

 mov ah,40h
 mov bx,stdout
 mov cx,msg_len
mov dx,offset msg
 int 21h

 mov ax,4c00h
 int 21h

print endp

msg db cr,lf

msg_len equ $-msg     ;<--------HERE


_TEXT ends

 end print

--- End code ---

Biterider:
Hi Shintaro
This line calculates the byte length of "msg" as the current position ($) on the selected section minus the starting address of "msg".

Biterider

Shintaro:
Is there a way I can see how this is working?
Because it is printing other garbage on the screen.

mineiro:
dollar sign means exact position, it's used when we need know sizeof data or code.
I used uasm assembler and dosbox in linux to test
uasm -bin test.asm
ren test.bin test.com
dosbox ./
test.com


--- Code: ---
stdin equ 0
stdout equ 1
tderr equ 2

cr equ 0dh
lf equ 0ah
_TEXT segment word public 'CODE'


org 100h

assume cs:_TEXT,ds:_TEXT,es:_TEXT,ss:_TEXT
print proc near

mov ah,40h
mov bx,stdout
mov cx,msg_len
mov dx,offset msg
int 21h

mov ah,40h
mov bx,stdout
mov cx,nop_size
mov dx,offset nope
int 21h


mov ax,4c00h
int 21h

print endp

msg db "hello world",cr,lf
msg_len equ $-msg     ;<--------HERE


nop_label:
nop
nop_size equ $-nop_label
nope db nop_size+"0",cr,lf     ;<---| To convert size to be printable I add a "0"


one db 1
two db 1
three db 1
sizeof_one_to_three equ $-one

_TEXT ends

end print


--- End code ---

mineiro:
You can calculate that by using 2 labels too:

code_start:                  ;code size
;program code instructions
code_end:

data_start:
;data types
data_end:

code_size equ code_end - code_start
data_size equ data_end - data_start
program_size equ code_size + data_size

PS:SHINTARO, edited after;
When I copied your source code from this board and pasted in a text editor, I perceived some strange chars in your source code. (one example is one byte before "org 100h").
Try using other text editor, your code it's working fine!!!.
Not sure how you're doing this, by ms-dos or windows. Copy my source code into notepad, save in target directory (folder) and should work too.

Navigation

[0] Message Index

[#] Next page

Go to full version