Reputation: 5585
The following code compiles and runs fine on Xubuntu 16.04 with these commands in bash shell
nasm blue.asm -fbin -oblue.com
dosbox ./blue.com -exit
The problem I'm having is on line 20
mov al, 1;byte [blue]
where if I use this instead
mov al, byte [blue]
the program draws a sort of burgundy to the screen instead of blue. It works normally for using 1 which is the color code in the 8-bit palette here https://en.wikipedia.org/wiki/BIOS_color_attributes
Here's the full code, feel free to let me know if anything else is wrong with it though.
org 00h
bits 16
section .data
blue: db 1
section .text
MAIN:
AsyncKeyInput:
mov al, 13h
int 10h
; Segment a000h
mov ax, 0a000h
mov es, ax
; Offset 0
xor di, di
mov al, 1;byte [blue]
; Looplength (320*200)/2 = 7d00
mov cx, 7d00h
hplot:
mov [ es: di], al ;set pixel to colour
inc di ;move to next pixel
loop hplot
mov ah, 1 ;Get the State of the keyboard buffer
int 16h ;key press
jz AsyncKeyInput ;if not zero then exit the program
;exit program
mov eax, 1
mov ebx, 0
int 0x80
ret
Upvotes: 2
Views: 156
Reputation: 5585
The solution to the problem is to properly set the program segment prefix to org 100h
for com programs. Here's the corrected code below.
org 100h
bits 16
section .data
blue: db 1h
section .text
MAIN:
AsyncKeyInput:
mov al, 13h
int 10h
; Segment a000h
mov ax, 0a000h
mov es, ax
; Offset 0
xor di, di
xor eax, eax
mov al, byte [blue]
; Looplength (320*200)/2 = 7d00
mov cx, 7d00h
hplot:
mov [ es: di], al ;set pixel to colour
inc di ;move to next pixel
loop hplot
mov ah, 1 ;Get the State of the keyboard buffer
int 16h ;key press
jz AsyncKeyInput ;if not zero then exit the program
;text mode
mov ax, 0003h
int 10h
ret
Upvotes: 2