assemblyx86-16biostasmvideo-memory

How I can read a value from an address in the Bios Data Area correctly?


I'm trying to read the value 1000h which can be found in the address 0000h:044Ch and put it in the ax register by using the mov instruction. Every time I get back another value than the expected 1000h.

This is the instruction I use in TASM:

mov     ax, [word ptr 0000h:044Ch] 

I have checked the vaue in ax in the debugger.


Solution

  • You will have to set one of the segment registers to 0x0000 and then access the word at offset 044ch through that segment register. Something like this should work:

    xor ax, ax         ; XOR register with itself same as setting register to 0
    mov es, ax         ; ES = 0
    mov ax, [es:044ch] ; Get size of text video page of current display mode in bytes
    ; AX now has the 16-bit WORD value at 0000h:044ch
    
    shr ax, 4          ; Divide by 16 to get size in paragraphs
    add ax, 0b800h     ; Add to the base of text video memory segment to get page 1 segment
    
    ; Then you can put AX in a segment like ES to access text video memory
    mov es, ax         ; ES = segment of page 1 of current text video mode