Skip to content

Instantly share code, notes, and snippets.

@neuro-sys
Created March 13, 2019 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuro-sys/14c5930ea47b4733737668d95c4ea402 to your computer and use it in GitHub Desktop.
Save neuro-sys/14c5930ea47b4733737668d95c4ea402 to your computer and use it in GitHub Desktop.
; nasm mode13.asm -fbin -omode13.com
SECTION .text
org 100h
start: mov dx, filenamez
mov al, 0
call openfile
jnc fileopened
mov dx, filenotopeneds
call printstr
jmp filedone
fileopened: mov dx, fileopeneds
call printstr
filedone: call waitkey
call exit
jmp $
waitkey: mov ax, 0
int 16h ; Wait for keyboard
ret
exit: mov ax, 3h
int 10h ; Switch to text mode
int 20h ; Terminate
ret
; Print $ terminated string at ds:dx
printstr: mov ah, 9
int 21h
ret
; cx = x, dx = y
; color holds palette index
putpixel: mov ax, 0xa000
mov es, ax
mov ax, dx
mov bx, dx
shl ax, 8
shl bx, 6
add ax, bx
add ax, cx
mov di, ax
mov al, byte [color]
mov [es:di], al
ret
; al = access mode (0, 1, 2)/(read/write/read&write)
; ds:dx = pointer to asciiz file name
; returns ax for file handle
openfile: mov ah, 0x3d
int 21h
ret
SECTION .bss
color: resb 1
SECTION .data
filenamez: db "mode13.asm", 0
fileopeneds: db "File successfully opened.$", 0
filenotopeneds: db "Failed to open file.$", 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment