[Assembly] String and Struct issues

Started by
4 comments, last by DreadPirateRyu 14 years, 6 months ago
First, I would like to know if it possible to do something like: mov foo, "Bar" at all. Been wanting to do that for a while but it always gives me an error and I haven't been able to find any examples. Second, a problem with some code that should be working (basically copied it from a book).
Room Struct
     descrip BYTE 100 DUP(?)
     east DWORD ?
     ;etc
Room ENDS

.data
testRoom Room<"A simple room.">
And this is giving me the error: error A2177: nested structure improperly initialized. Any help you can give me with this would be REALLY appreciated.
Advertisement
FIX: A2138, A2036 or Hang, Init Nested Structure Array

MASM version 6.1 generates the following error message when an application attempts to initialize an array of nested structures:
error A2177: nested structure improperly initialized



mov foo, "Bar"

Have you considered going with old fashioned C instead of MASM?

char *foo = "Bar";

You can find a free ide and compiler here. There are others available on the www too.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Unfortunately, I can't use C or anything like that, this is for a project for an Assembly course, which is using MASM.
Also, I just checked my version of MASM, and it says I have version 8.0.50720, it says it got fixed in version 6.1, so I would assume it wouldn't apply anymore.
Also, I should have done this from the beginning, but here's a code paste including the nested structures if it'll help at all: http://codepad.org/fngNxQ30
Also also, just trying something like mov foo, "bar" doesn't like to work. The code:
mov testRoom.descrip, "A simple room."
coughs the error "error A2084: constant value too large" back into my face.
well,if you want to copy string "Bar" to the element descrip then you can do something like this...
and btw you cant do direct mem to mem copy in asm...

.686.model flat,stdcalloption casemap:noneinclude kernel32.incincludelib kernel32.libRoom Struct     descrip BYTE 100 DUP (?)     east DWORD ?Room ENDS.datatestroom Room <"A Simple Room",10>bar byte "Bar",0.data?.codestart:		mov ecx,lengthof bar	mov esi,offset bar	mov edi,offset testroom.descrip	rep movsb		invoke ExitProcess,0end start


btw check this forum
You can't use 'mov' to copy strings around, because they aren't single elements of memory. You need to have some kind of loop to copy a byte (or word, if you're sufficiently clever) at a time. It's analogous to how assigning a pointer in C doesn't actually copy the string, which is why the C standard library provides strcpy().
Sorry for taking so long to respond, but thank you very much for all the help and advice you've been giving me. I'm definitely going to sign up at the masm forums and see if I can get some help over there.

This topic is closed to new replies.

Advertisement