The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Tipidy on May 17, 2009, 11:44:29 AM

Title: Registars and Buffers
Post by: Tipidy on May 17, 2009, 11:44:29 AM
Hi all,

I have a quick question, whats wrong with this code below:


invoke lstrlen addr username
; eax now holds the number of characters in the username
mov dword ptr [eax], offset random


As you might of noticed, I want to move the value of eax into a buffer. I am having troubles finding the correct code, can someone please help me out?

Cheers, Tipidy.
Title: Re: Registars and Buffers
Post by: Neil on May 17, 2009, 12:35:07 PM
mov buffer,eax
Title: Re: Registars and Buffers
Post by: travism on May 17, 2009, 01:06:02 PM
I thought it would be?

mov dword ptr [buffer], eax
Title: Re: Registars and Buffers
Post by: starzboy on May 17, 2009, 01:15:57 PM
@travism
that is more appropriate, but if the buffer is a local dword then it is also fine :)
Title: Re: Registars and Buffers
Post by: Neil on May 17, 2009, 01:55:29 PM
I assumed that random was a dword variable, we need a bit more information as to what it is.
Title: Re: Registars and Buffers
Post by: dedndave on May 17, 2009, 02:38:04 PM
mov dword ptr [buffer], eax

generally, if the size is defined by a register (eax in this case), a ptr is not needed
if it were an immediate value, then you would want one

mov buffer,eax - the assembler knows it is a dword because of the size of eax
mov dword ptr buffer,27h - the assembler does not know the width of 27h (27h could be a byte, word, or dword)

although, if buffer is defined as a dword, it may know - don't trust it

cmp word ptr [esi],27h - in this case, [esi] could be any size - so could 27h - so a ptr is needed
Title: Re: Registars and Buffers
Post by: starzboy on May 17, 2009, 02:44:42 PM
Hey Neil
No offense intended brother.
Title: Re: Registars and Buffers
Post by: Neil on May 17, 2009, 03:05:00 PM
None taken :bg, if Tipidy had posted a bit more code then we wouldn't be guessing ::) what exactly he means.
Title: Re: Registars and Buffers
Post by: travism on May 17, 2009, 03:50:42 PM
Quote from: dedndave on May 17, 2009, 02:38:04 PM
mov dword ptr [buffer], eax

generally, if the size is defined by a register (eax in this case), a ptr is not needed
if it were an immediate value, then you would want one

mov buffer,eax - the assembler knows it is a dword because of the size of eax
mov dword ptr buffer,27h - the assembler does not know the width of 27h (27h could be a byte, word, or dword)

although, if buffer is defined as a dword, it may know - don't trust it

cmp word ptr [esi],27h - in this case, [esi] could be any size - so could 27h - so a ptr is needed

Hey thanks for the explanation on that :) Im sure he should get it now.