flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > mov eax, [variable]

Author
Thread Post new topic Reply to topic
Mino



Joined: 14 Jan 2018
Posts: 127

mov eax, [variable]

Hello,
it's all in the title, I think, but basically here it is:

Code:

text db 'Hello'0
...
mov eax, [text]



This is not working. This is normal, eax is not a registry with enough size to contain a type db. But... it would suit me well if there was a solution, I tried with other registers, and it never works. Unless I want to move a type dd, or dw, into a registry.
Did you have a solution for me Very Happy ?

_________________
The best way to predict the future is to invent it.
Post 26 Feb 2018, 21:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15817
Location: Misner space

What do you consider to be "working"?

After the instruction has executed EAX contains 0x6c6c6548, but you'll need and override to get that:

Code:
mov eax,dword[text]

Perhaps instead you want to use the address of the text?

Code:
mov eax,text

Post 26 Feb 2018, 22:54
View user's profile Send private message Visit poster's website Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 78

Salut, mino!

Code:
test db 'Hello',0
...
mov eaxdword [text]; eax=0x6C6C6548='lleH'

While I typed the text revolution already answered
Post 27 Feb 2018, 02:08
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 242
Location: Belarus

Re: mov eax, [variable]


Mino wrote:
eax is not a registry with enough size to contain a type db


You should also stop thinking in terms of types. DB is not a type but a directive that just makes an assembler put some data into output file as a sequence of bytes.

EAX is definitely large enough to hold a byte. Even four of them. revolution and Mikl___ gave you two possible solutions. I’ll give you one more. Which one suits you depends on what you need and we can suggest hundreds of such solutions. To let us know that you need to express your wishes in terms of bytes and pointers.


Code:
movzx eax, [text]


copies the first character (byte) of the string into eax (zero-extending it).


Code:
mov eaxdword [text]


copies four characters of the string into eax. Which is not particularly useful for processing the string character-by-character, but as we don’t know what you actually need it might work as well.


Code:
mov eaxtext


puts the address (offset) of the string into eax.
Post 27 Feb 2018, 07:14
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 127

Thank you very much for your answers!
Actually, I'm trying to do that:


Code:

write:
    cinvoke printfeax
    ret

main:
    push eax
    mov eaxecx

    mov eaxdword [text]    ; I tried that solution there.
    push eax
    call write

    invoke ExitProcess0




But it still doesn't work...
I imagine you understand the purpose of

Code:
mov eax [text]


_________________
The best way to predict the future is to invent it.
Post 27 Feb 2018, 07:29
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 242
Location: Belarus


Mino wrote:
Thank you very much for your answers!
Actually, I'm trying to do that:


Code:

write:
    cinvoke printfeax
    ret

main:
    push eax
    mov eaxecx

    mov eaxdword [text]    ; I tried that solution there.
    push eax
    call write

    invoke ExitProcess0




But it still doesn't work...
I imagine you understand the purpose of

Code:
mov eax [text]



You should pass the address of the string. See my explanation of the meaning of the three solutions you’ve been supplied with and choose the one that suits this need.
Post 27 Feb 2018, 13:29
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 127

Thank you for your answers. Indeed, I had tested several times the code that met my needs:

Code:

mov eaxtext



And it works perfectly!
I just have one last question:
how useful this solution is:

Quote:

mov eax, dword [text]


You said it would copy the first 4 characters, but I don't know what it's for. Would you enlighten me Very Happy ?

_________________
The best way to predict the future is to invent it.
Post 27 Feb 2018, 15:09
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 242
Location: Belarus


Mino wrote:
You said it would copy the first 4 characters, but I don't know what it's for. Would you enlighten me Very Happy ?


The first thing a can think of is some kind of copying or maybe certain cases when you’re not interested in the contents of the string itself but want to treat it as a set of bytes and perform some transformations (calculate a hash, for example).

In case the string is Unicode (Windows-style) I can imagine this as one of possible solutions to exchange characters in pairs: the first with the second, the 3rd with the 4th, etc.


Code:
...
mov eaxdword [str]
rol eax16
mov dword [str], eax
...



Something like that, although in this case string-handling instructions could be a better idea.
Post 27 Feb 2018, 21:21
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 127

Thank you, I can see better what it is now!
Post 28 Feb 2018, 16:08
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.