The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Rainstorm on November 06, 2006, 05:39:57 PM

Title: Question about this code(HLReference)
Post by: Rainstorm on November 06, 2006, 05:39:57 PM
hi,..

the following code works proper..but i have a question.
lcase$ works on a zero-terminated-string.
here the variable night doesn't contain a zero-terminated-string. - so how come it
works proper then ?
(night    db "PIXIE",0    --would be a zero-terminated-string..right ?)

    .data
night    db "PIXIE"
; -------------------------------------------------------------------------

    .code
start:
mov  ebx, lcase$(offset night)

print ebx,13,10

inkey
exit
end start


Thankyou.
Title: Re: Question about this code(HLReference)
Post by: dsouza123 on November 06, 2006, 09:21:29 PM
Uninitialized memory can have any byte value including a 0,
there must have been 0 byte in this case so it worked this time,
but it could just as well been some other random bytes and
your string would have a bunch of garbage characters following
the real text string.
Title: Re: Question about this code(HLReference)
Post by: ic2 on November 07, 2006, 02:03:46 AM
There should be no following characters (garbage) unless you have another string other than *code* in front of it. Is this not correct?

Place other strings around it and see what happen...
Title: Re: Question about this code(HLReference)
Post by: hutch-- on November 07, 2006, 02:11:42 AM
Rainstorm,

Microsoft have a humerous way of describing this situation, they refer to the results as "Undefined" which mean anything from random garbage to system crashes. The masm32 string library procedures all expect zero terminated strings so you should normally use them. What has probably happened is the initialised data section was filled with zeros.
Title: Re: Question about this code(HLReference)
Post by: Rainstorm on November 07, 2006, 05:39:58 AM
hi,

So, is it automatically reading one byte more from memory ?
(..as the reason is, that the initialised data section is filled with 0s)
Since if it wasn't doing that, the other bytes being a 0 wouldn't have made a diff.
am i right ?

Is it in this instruction that it is reading one byte beyond the variable,  night ?

mov  ebx, lcase$(offset night)
______________

hutch wrote..
QuoteThe masm32 string library procedures all expect zero terminated strings so you should normally use them...
- I was gonna ask that next just to be sure.

.. since in the help file for some functions like add$ & istring (for example) it
just says 'string' , while for other functions..'zero-terminated-string' is. explicitly mentioned.
___________________

ic2 wrote...
QuotePlace other strings around it and see what happen...
I tried 2 things

mov  ebx, left$(lcase$(offset night),3)   - here it returned the right result 'pix'

mov  ebx, right$(lcase$(offset night),3)   - that just returned 'e' insstead of 'xie'

why is it reading from beyond the defined variable in this case ?

Thanks all..

Rainstorm.

Title: Re: Question about this code(HLReference)
Post by: Rainstorm on November 08, 2006, 08:36:58 PM
can someone clarify this for me.

why does it read beyond the variable size in a decleration like the following

night    db "PIXIE"

is it because, the memory is read in Dword chunks ?

t y
Title: Re: Question about this code(HLReference)
Post by: Relvinian on November 08, 2006, 09:11:09 PM
Quote from: Rainstorm on November 08, 2006, 08:36:58 PM
can someone clarify this for me.

why does it read beyond the variable size in a decleration like the following

night    db "PIXIE"

is it because, the memory is read in Dword chunks ?

t y

Just taking a guess because I don't know what your code is doing, but here goes:
Try adding a NULL terminator to the end of your string definition, like this:

night  db "PIXIE", 0


See if that helps...If not, post the segment of code you are using your string in and I'll be able to answer more correctly.

Relvinian
Title: Re: Question about this code(HLReference)
Post by: kermit on November 08, 2006, 10:05:09 PM
Quotewhy does it read beyond the variable size in a decleration like the following

night    db "PIXIE"

is it because, the memory is read in Dword chunks ?

no, its because the "machine" just doesn't know the actual length of ur variable. it takes one byte after the other from this address until it gets a 0 byte.
if u want to see what happens u might want to use a debugger, i tried ollydbg http://www.ollydbg.de/ which works nice for 32 bit code.

greetz,

kermit
Title: Re: Question about this code(HLReference)
Post by: Rainstorm on November 09, 2006, 03:32:18 AM
Kermit, thanks so much for the explanation & clearing that up for me.. :-)

-