Click to See Complete Forum and Search --> : confused about registers


lmpb17
December 4th, 2008, 04:07 PM
Im a little confused. What happens to a register after a value has been moved out? Also what happens to an array after a value has been switched out?

for example:

.data
arrD DWORD 1,2,3
.code
mov eax, arrD ; eax=1
xchg eax, [arrD+4] ; eax=2
mov arrD,eax ; arrD=2,1,3


What is the value of eax at the end of this? Is it dereferenced and therefore null or is it still equal to 2.

After the xchg step, is the array = 0,1,3?

dnapcex
December 6th, 2008, 03:10 AM
Hello, Impd17
.data
arrD DWORD 1,2,3
---->DWORD is a kind of datatypes which occupies 4 bytes.
---->It means that:
---->arrD byte 1,0,0,0,2,0,0,0,3,0,0,0
.code
mov eax, arrD ; eax=1
---->EAX = [arrD + 0] = (1,0,0,0)
---->EAX is 32bit-register(32/8=4B,1Byte = 8bit)
---->Intel CPU use little endian for saving data:
---->byte Decimal:1->Hex:0x01
---->word Decimal:1->Hex:0x0100
---->word Decimal:256->Hex:0x0001
---->dword Decimal:1->Hex:0x01000000
---->now EAX=0x01
xchg eax, [arrD+4] ; eax=2
---->Exchange EAX and [arrD + 4(byte)]
---->past EAX = 0x01 [arrD + 4] = 0x02000000
---->now EAX = 0x02 [arrD + 4] = 0x01000000 arrD = 1,0,0,0,1,0,0,0,3,0,0,0
mov arrD,eax ; arrD=2,1,3
---->past EAX = 0x02
---->now EAX = 0x02 [arrD + 0] = 0x02000000 arrD = 2,0,0,0,1,0,0,0,3,0,0,0