June 25, 2006
I think this program:

----------------------------
import std.stdio;

void main() {

short* s = new short[3];
s[0] = 1;
s[1] = 2;
s[2] = 3;

int a = 0;

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

writefln("%s", a);
}
----------------------------

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.


June 25, 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 +/