Simon
Simon

Reputation: 2733

Assembly code explanation

I stumbled upon a problem that I cannot fix nor can I find a solution in the web. I've got a simple code fragment in MASM

abc dw 254, 255, 256
(...)
mov eax, dword PTR abc + 1

When I debug this code, after doing to second line, my eax register shows 0000FF00 and I have no idea why. I know that dword ptr means the number should be treated as a 32bit number and I have defined a the 16bit sequences. Could anyone explain this to me?

Upvotes: 0

Views: 177

Answers (1)

Michael
Michael

Reputation: 58517

When I debug this code, after doing to second line, my eax register shows 0000FF00

The code is loading a DWORD (4 bytes) into EAX from the address starting at abc + 1.

Let's write out the array contents in hex:

00FEh, 00FFh, 0100h

Or, expressed as bytes:

0FEh, 00h, 0FFh, 00h, 00h, 01h

So you get the DWORD formed by 00h, 0FFh, 00h, 00h, which when interpreted as a little-endian DWORD is 0000FF00h.

Upvotes: 2

Related Questions