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

Recommended Answers

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 …

Jump to Post

All 3 Replies

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.

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 '$'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.