News:

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

MOV ADDR of a string constant to memory

Started by Yuri, August 13, 2009, 07:10:00 AM

Previous topic - Next topic

Yuri

Jeremy, I am here again with another question about immediate strings in code.

It's ok if I do this:

mov eax, addr "Hello"


But this doesn't work:

mov D[SomeLabel], addr "Hello"


Quote
Error!
Line 12 of assembler source file (addr.asm):-
Misplaced quoted string:-
mov D[SomeLabel], addr "Hello"

I see that the GoAsm manual discusses only moving such string pointers to registers. Does it mean that moving them to a memory location is impossible?

jorgon

This is not allowed within GoAsm syntax, although there is no technical reason why it is not allowed.
However, would there be any use for this? 
I have difficulty thinking when you would want to do this.

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

donkey

Hi Yuri,

You can do this...

push "Hello"
pop [SomeLabel]

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Yuri

Jeremy, this is certainly not a critical feature, and if you eventually find it worthless, I won't complain. However, the question came from my practice. I wanted to put a string pointer into a sructure that would later be passed to a function. If a string is used only once, it seems a bit overkill to create a label for it. At least when you are experimenting, writing code just to see if some idea will work, and so on. In general, this is a question of writing two lines of code instead of one, though you get the feeling that it's not logical. You can push and pop it as Edgar has advised, or move it through a register, but why not directly? This just seems not logical. I really like GoAsm and want it to be perfect in this respect too.  :wink

ecube

itd be useful is bypassing the redirection

mov eax,addr watever
mov [varx],eax

which becomes cumbersome when having to do that alot(which unfortunately I have with masm) but to me isn't a big deal. The structure thing Yuri mentioned with this is appealing though.

jorgon

Hi E^Cube

Just to check, you are aware that:-
MOV [varx],ADDR watever

is possible in GoAsm?

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

ecube

Quote from: jorgon on August 14, 2009, 06:50:51 PM
Hi E^Cube

Just to check, you are aware that:-
MOV [varx],ADDR watever

is possible in GoAsm?


Hello,
and Wow no I didn't, I thought that's what this topic was about, but I misread, thanks for the correction.

jorgon

Yes, because when you think of it, this instruction is simply moving a dword value (a 32-bit address) into an area of memory.
This is done by the assembler if possible, or by the linker.

This is why Yuri's request for MOV [varx],ADDR 'Hello what a nice day it is today' iis technically feasible.

GoAsm already supports MOV EAX,ADDR 'This morning I thought it was going to be a good day' but should it also support MOV [varx],'It was a dark day throughout, despite my best endeavours'
Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

jj2007

Quote from: Yuri on August 14, 2009, 12:45:30 PMI wanted to put a string pointer into a sructure that would later be passed to a function.

Not sure if this is helpful - this is the Masm way of inserting strings into a structure at assembly time:

include \masm32\include\masm32rt.inc

SomeStruct struct
    String1 DWORD ?
    String2 DWORD ?
SomeStruct ends

.data
MyStrings SomeStruct <Str1, Str2>
Str1 db "Hello A", 0
Str2 db "Hello B", 0

.code
start: mov esi, offset MyStrings
print [esi.SomeStruct.String1], 13, 10
print [esi.SomeStruct.String2], 13, 10
getkey
exit
end start

dedndave

you can also define the structure with default values
if those values remain unaltered in the declaration, the default assignment is used

;--------------------------------------------------------------------------

;frequency data structure definition

CPU_FREQUENCY_DATA STRUCT
  StrtInt dd INTRVAL-INDELTA
  DeltInt dd INDELTA
  LastClo dd ?
  LastChi dd ?
  LastTim dd 0
  PrioCls dd ?
  hProc   dd ?
  hThrd   dd ?
  RollDat dd 2*(ROLLQTY-1) dup(0)
CPU_FREQUENCY_DATA ENDS

;--------------------------------------------------------------------------

        .DATA

CpuFrequencyData CPU_FREQUENCY_DATA <>

Yuri

Quote from: jorgon on August 14, 2009, 08:26:00 PM
GoAsm already supports MOV EAX,ADDR 'This morning I thought it was going to be a good day' but should it also support MOV [varx],'It was a dark day throughout, despite my best endeavours'

I still believe it should. We all know that constants can be moved to memory directly. But here we meet a constant that can not. It is surprising and leaves you with a feeling of some incompleteness in GoAsm.

jj2007 and Dave — thanks, but no, I meant operation at run time. I call one function that fills a structure with some values, then I change several fields of the structure and call another function, passing the structure to it.

I am not saying that I don't know how to accomplish this. I can simply declare a label for the string and move the ADDR of the label. But GoAsm already goes farther and facilitates string operations so you can do without labels:

mov eax, addr "Hello"
mov [Struct.Field], eax

; or

push "Hello"
pop [Struct.Field]


My question was why not directly:

mov D[Struct.Field], addr "Hello"


This would only be logical. Why stop one step before the end of the way?