I have been playing around a bit with NASM assembly and directly working with the BIOS from the boot sector but I'm not able to define a variable like I'd usually do with NASM.
When I try to define and use a variable like usually
BALL_X dw 0x140
BALL_Y dw 0xF0
[...]
mov cx, [BALL_X]
mov dx, [BALL_Y]
it just doesn't seem to return/contain any value, though the assembler doesn't complain either when assembling it.
I've also tried it with and without the
section .data
and section .text
but that doesn't seem to change anything either.
The only way I've got it to work is by manually assigning a name to an address and then assigning the values separately
BALL_X equ $
BALL_Y equ $
[...]
mov word[BALL_X], 0x140
mov word[BALL_Y], 0xF0
I've been searching for a solution on the internet but I'm struggling to find anything about how to get this to work properly, as the second method seems like a bit of a hack to me.
In case the entire code snippet helps(of the last thing I tried):
mov word[BALL_X], 0x140
mov word[BALL_Y], 0xF0
main:
mov ah, 0x00 ;Set video mode
mov al, 0x12 ;640x480 16 color graphics
int 0x10 ;Interrupt
mov ah, 0x0B ;Set background color
mov bh, 0x00 ;Set background color
mov bl, 0x00 ;Black
int 0x10 ;Interrupt
mov ah, 0x0C ;Write pixel
mov al, 0x0F ;White
mov bh, 0x00 ;Page number
mov cx, [BALL_X] ;X
mov dx, [BALL_Y] ;Y
int 0x10 ;Interrupt
jmp exit
exit:
jmp $
BALL_X equ $
BALL_Y equ $
times 510-($-$$) db 0 ;padding
db 0x55, 0xAA ;magic bytes to make it bootable