I am trying to make a custom cursor for my 32-bit OS and would like to know how to offset a memory address (0xb800 for text) by a variable (0xb8000+XVAR). I tried the following but the text just diapered off my screen:
mov al, ' '
mov ah, 0xff
mov edx, 0xb8000+160*3
add edx, CURSORX
mov word [edx], ax
For anyone that needs to know, this is what it looks like without trying to offset:
And this is what it looks like when I try to offset:
Best regards, Markian.
The
add edx, CURSORXinstruction is adding the offset address of the CURSORX variable! To add the value of your variable proper, you must use the square brackets in NASM.If the
mov word [edx], axinstruction works fine (you say without theaddit does), it is because the DS segment register is 0. Because your code snippet solely depends on the DS segment register (which is 0), make sure that the offset that NASM gives to the CURSORX variable is also relative to that same zero.If this is bootloader code and you used an
[ORG 0x7C00]directive, all would have been fine (segment-wise).But if you have used
[ORG 0], then makeES=0x07C0and use a segment override onadd edx, [es:CURSORX].In comments you mention that CURSORX is a byte. You need to extend the byte before using it in the dword-sized addition.
And if your 'cursor offset' is expressed in characters, then don't forget to double it before using, because of how the text video memory is organized (character byte, attribute byte)