News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Registars and Buffers

Started by Tipidy, May 17, 2009, 11:44:29 AM

Previous topic - Next topic

Tipidy

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.

Neil


travism

I thought it would be?

mov dword ptr [buffer], eax

starzboy

@travism
that is more appropriate, but if the buffer is a local dword then it is also fine :)

Neil

I assumed that random was a dword variable, we need a bit more information as to what it is.

dedndave

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

starzboy

Hey Neil
No offense intended brother.

Neil

None taken :bg, if Tipidy had posted a bit more code then we wouldn't be guessing ::) what exactly he means.

travism

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.