Skip to content

Instantly share code, notes, and snippets.

@growlnx
Last active March 9, 2020 01:25
Show Gist options
  • Save growlnx/445a1841f18af00465faf8e252effe9e to your computer and use it in GitHub Desktop.
Save growlnx/445a1841f18af00465faf8e252effe9e to your computer and use it in GitHub Desktop.
Simple Library for Bare Metal
;-------------------------------------------------------------------;
; ##:::::::: '########::'##::::'##:
; ##:::'##:: ##.... ##: ###::'###:
; ##::: ##:: ##:::: ##: ####'####:
; ##::: ##:: ########:: ## ### ##:
; #########: ##.... ##: ##. #: ##:
; ...... ##:: ##:::: ##: ##:.:: ##:
; :::::: ##:: ########:: ##:::: ##:
; ::::::..:::........:::..:::::..:: Simple Library for Bare Metal
;-------------------------------------------------------------------;
; Why a library for bare metal? Its just for study purposes
; References:
; http://stanislavs.org/helppc/idx_interrupt.html
;-------------------------------------------------------------------;
; TODO LIST
; [ ] - dinamic memory alocation (malloc like)
; [X] - clear the screen
; [X] - print char on terminal
; [X] - print cstring on terminal
; [ ] - print 8 bits integer on terminal
; [ ] - print 16 bits integer on terminal
; [ ] - print 32 bits integer on terminal
; [ ] - print 64 bits integer on terminal
; [ ] - print 8 bits float on terminal
; [ ] - print 16 bits float on terminal
; [ ] - print 32 bits float on terminal
; [ ] - print 64 bits float on terminal
; [ ] - convert integer to cstring
; [ ] - convert float to cstring
; [ ] - reverse cstring
; [ ] - resize cstring
; [ ] - concat cstring
; [ ] - replace cstring
; [X] - read keyboard input chr
; [ ] - read keyboard input until specified limit
; [ ] - read keyboard input until new line
; ------------------------------------------------------------------;
; ------------------------------------------------------------------;
; Name: clear
; Description: clear the screen using int 10h/0eh bios function
; Complexity: O(1)
; Arguments: null
; Return: null
; ------------------------------------------------------------------;
pchr:
mov ah, 0x00
mov al, 0x03
int 10h
ret
; ------------------------------------------------------------------;
; Name: pchr
; Description: print char on tty using int 10h/0eh bios function
; Arguments:
; - al: ascii char to be printed
; Return: null
; ------------------------------------------------------------------;
pchr:
mov ah, 0eh
int 10h
ret
; ------------------------------------------------------------------;
; Name: pcstr
; Description: print cstring on tty using int 10h/0eh bios function
; Arguments:
; - si: cstring pointer
; Return: null
; alert: if string does not have a 0 at end, this will run until find it
; ------------------------------------------------------------------;
pcstr:
mov ah, 0eh
pcstr_j1:
lodsb
or al, 0
jnz j2
ret
pcstr_j2:
int 10h
jmp pcstr_j1
; ------------------------------------------------------------------;
; Name: rchr
; Description: read char from keyboard input using 16h bios function
; Arguments: null
; Return:
; - al: ascii char read from keyboard
; alert: if string does not have a 0 at end, this will run until find it
; ------------------------------------------------------------------;
rchr:
mov ah, 0
int 16h
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment