Problem with asm and short

Tom S h3r3tic at remove.mat.uni.torun.pl
Sun Jun 25 13:34:35 PDT 2006


Ary Manzana wrote:
> asm {
> mov EAX, s;
> mov ECX, [EAX];
> mov a, ECX;
> }
> 
> should output 1, but it outputs 131073 (garbage). However, if instead of [EAX]
> you write [EAX + 4] it outputs 3 (and with [EAX + 2] garbage again). Am I doing
> something wrong or this is a bug?
> 
> If the array is of ints, the programs works OK.

Shorts are 16bit, ECX is 32bit. 'mov ECX, [EAX]' copies 32bits from the 
[EAX] address to ECX, while you should only copy 16 (a short/word).

Try this:

asm {
     mov EAX, s;
     xor ECX, ECX;
     mov CX, [EAX];
     mov a, ECX;
}


-- 
Tomasz Stachowiak  /+ a.k.a. h3r3tic +/



More information about the Digitalmars-d-bugs mailing list