From: Mihai N. on
>> We had to walk barefoot through the snow to get our listings...

> Up hill, both ways.

And carrying the PC and the CRT on the back.
:-)

--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

From: Giovanni Dicanio on
"Mihai N." <nmihai_year_2000(a)yahoo.com> ha scritto nel messaggio
news:Xns9CC3F1BF9B8B2MihaiN(a)207.46.248.16...
>>> We had to walk barefoot through the snow to get our listings...
>
>> Up hill, both ways.
>
> And carrying the PC and the CRT on the back.
> :-)

:-))

G


From: Joseph M. Newcomer on
MASM 9.00,

Source file:

title
..686
..model flat
option casemap:none

Triple struct
x dd ?
y dd ?
z dd ?
Triple ends

_TEXT segment
_fetchZ proc

$t=4
_fetchZ endp
mov eax,$t[esp]
mov eax, offset [eax].Triple.z
ret
_TEXT ends
end
========
Command line (from build log)
========
ml.exe /c /Fo"Debug\fetcher.obj" /W3 /Zi /errorReport:prompt /Ta.\fetcher.asm

>------ Build started: Project: structExample, Configuration: Debug Win32 ------
1>Assembling...
1> Assembling: .\fetcher.asm
1>MASM : fatal error A1016: Internal error
1>Project : error PRJ0019: A tool returned an error code from "Assembling..."
========

It is called by a program of the form:

#include "Triple.h" // which defines typedef struct { int x; int y; int z; } Triple;

extern "C" int fetchZ(Triple & t);

int fetchZ0(Triple & t)
{
return t.z;
}


int _tmain(int argc, _TCHAR* argv[])
{
Triple t={1, 2, 3};
int z0 = fetchZ0(t);
_tprintf(_T("z0=%d\n"), z0);

int z = fetchZ(t);
_tprintf(_T("z=%d\n"), z);
return 0;
}

This is a trivial example that is supposed to demonstrate how structures
are accessed from an assembly code program; I've run through several variations of
the syntax trying to get it to not crash (and Vista doesn't disclose what "crash" means,
eternal damnation to the paternalistic idiot who thought we should be protected from
knowing
the truth). This was the latest.

The next example will be how to access a field in a array of objects. Then we will work
backwards
to C code showing what the C compiler does, using the C++ subroutine shown above, then
discuss H2INC, etc.

The idea is to show patterns of assembly code and patterns of the C compiler; among other
things,
it helps figure out whether a compiler or an assembly programmer wrote the code.

But programs should not fail if there is a syntax error. Apparently adding the word
"offset" (left over from a previous attempt) causes the error. I removed it, and it
worked. Comes from programming on painkillers.
joe


On Sat, 14 Nov 2009 23:09:54 -0600, "Liviu" <lab2k1(a)gmail.c0m> wrote:

>
>"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote...
>>
>> [...] Today's problem: how to use a struct declaration
>> when the pointer to the structure base is in a register.
>>
>> The construct
>> mov eax, [ecx].StructureName.field
>>
>> causes the assembler to "stop working" [...]
>
>That construct works with v6.15 as documented. What version are you
>using, and what's the full context, including the ml.exe command line?
>
>Liviu
>
>
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Giovanni Dicanio on
"Joseph M. Newcomer" <newcomer(a)flounder.com> ha scritto nel messaggio
news:vpb0g5dbvhlama9bski6dn60vldf3tc64b(a)4ax.com...

> MASM 9.00,
>
> Source file:
[...]
> _TEXT segment
> _fetchZ proc
>
> $t=4
> _fetchZ endp
> mov eax,$t[esp]
> mov eax, offset [eax].Triple.z
> ret

I don't understand that.
I thought you should put 'endp' after the 'ret' keyword to mark end of
procedure.
e.g

<code>

_fetchZ proc
$t=4
mov eax,$t[esp]
mov eax, offset [eax].Triple.z
ret
_fetchZ endp

</code>

Giovanni


From: Liviu on
"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote...
> MASM 9.00,
>[...]
> mov eax, offset [eax].Triple.z
>[...]
> Apparently adding the word "offset" (left over from a previous
> attempt) causes the error. I removed it, and it worked.

FWIW v6.15 terminates with the same A1016 on the (wrong) construct
above, but has the decency to at least log the exact line number.

> But programs should not fail if there is a syntax error.

MS agrees ;-) but hasn't fixed it, yet. Looks like the root bug was
reported (and acknowledged) for more than a year now.
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=356393

Liviu

P.S. Giovanni is right about the misplaced 'endp' though that happens to
not matter in this case (loosely speaking, it's more about source
organization and label scoping than actual code generation).