0

I'm trying to check the length of a string, its the most simple way there is but for some reason it says the the length of the string is 14h

org 100h

mov cl,len
mov si,offset src
mov di,offset dst
rep movsb
mov ah,0
int 16h
ret   

src DB 'abcdefghi$'
dst DB 10 dup(0)  
len DB EQU $-src
4
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by dheaven
0

it says the the length of the string is 14h

src DB 'abcdefghi$'
dst DB 10 dup(0)  
len DB EQU $-src

Yes, that's exactly what should happen.
A $ sign at the line 3 is an assembly pointer, and its goal is to trace addresses at which the code is currently assembled. When assembler start processing a directive at line 1, that is when it encounters the src label, $ and src have the same value. When assembler is done with line 1, that is after it allocated 10 bytes, $ increases by 10. After assembler is done with line 2, $ is increased one more time by the amount allocated there, and becomes src + 10 + 10. At line 3, a $-src expression obviously yields 20.
Don't confuse the assembly pointer with the '$' in your src.

0

If you are really just after the length, try this and the length will be stored in DI:

mov si,offset src
mov di,offset len
sub di, si
int 20h

src DB 'abcdefghi'
len DB '$'
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.