MOV instruction doesn't copy the whole register into memory

81 Views Asked by At

Im writing a program in x86 assembly and assembling it using MASM

Im writing a 32bit value to EAX and then copying it into a memory location but it doesn't seem to copy the whole register, it only copies the first two bytes and then writes two 00 bytes in the memory and to the the upper two bytes of the EAX register.

Here's what i tried


.386
.model small, c


STACK_SEG SEGMENT STACK
    DB 100 DUP(?)
STACK_SEG ENDS

DATA_SEG SEGMENT USE16 'DATA'
    ARRAY DB 10000 DUP(0FFh)
DATA_SEG ENDS

.CODE
CODE_SEG SEGMENT USE16 'CODE'
ASSUME CS:CODE_SEG, DS:DATA_SEG

START:
MOV AX, DATA_SEG
MOV DS, AX
MAIN PROC
    LEA DI, ARRAY
    MOV EAX, 0FF010101h
    MOV [EDI], EAX
            
MAIN ENDP

MOV AX, 04C00h
INT 021h
CODE_SEG ENDS
END START

Any idea why it does this?

EDIT: I'm using DOSBox to run my code

1

There are 1 best solutions below

0
Blackwatch On

SOLVED: Apparently this is a known bug in the version of CodeView, the debugger that comes with DOS(DOSBox) which i was using, which causes the upper 16 bits in the general purpose 32 bit registers to get corrupted in single step mode.

See this question.