BITS 16
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
dumpmem:
|
|
; Dumps memory
|
|
; IN From-pointer in 'si'
|
|
; IN Amount of bytes do dump in 'cx'
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
pusha
|
|
;push ax
|
|
;push dx
|
|
mov si, start_sing
|
|
mov cx, 512
|
|
call printCRLF
|
|
shr cx, 1
|
|
xor dx, dx ; zero dx
|
|
.loop:
|
|
cmp dx, cx
|
|
jae .end
|
|
mov ax, word [esi + 2*edx]
|
|
call dumpax
|
|
mov ax, 0xe20
|
|
int 0x10
|
|
inc dx
|
|
jmp .loop
|
|
.end:
|
|
;pop dx
|
|
;pop ax
|
|
popa
|
|
ret
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
dumpax:
|
|
; Prints the contens of ax as a hexadecimal number
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
pusha ; save registers
|
|
mov dx, ax
|
|
mov ah, 0xE ; Teletype output
|
|
|
|
mov cx, 4 ; 4 nipples in a 16 bit word
|
|
.loop:
|
|
rol dx, 4 ; rotate to next nipple
|
|
mov al, dl ; we copy to al because we need to mask only the low 4 bits
|
|
and al, 1111b ; Do the masking
|
|
add al, '0' ; convert to ASCII
|
|
cmp al, '9' ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A'
|
|
jbe .skip ; -|-
|
|
add al, 7 ; -|-
|
|
.skip: ; -|-
|
|
mov bl, 0xe2 ;color
|
|
int 0x10 ; BIOS call 'output'
|
|
loop .loop
|
|
|
|
popa ; restore registers
|
|
ret
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
dumpax10:
|
|
; Prints the contens of ax as a decimal number
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
pusha
|
|
|
|
mov bx, 10 ; Divisor
|
|
|
|
mov cx, 5 ; Loop 5 times
|
|
.loop1: ; finds digits and pushes them to stack
|
|
xor dx, dx
|
|
div bx
|
|
add dl, '0'
|
|
push dx
|
|
loop .loop1
|
|
|
|
|
|
mov ah, 0xE
|
|
mov cx, 5 ; Loop 5 times
|
|
mov bl, '0'
|
|
|
|
.loop2: ; Pops from stack until it hits a non-'0' value. It then jumps to nonzero_nopop to print it.
|
|
pop dx
|
|
mov al, dl
|
|
cmp al, bl
|
|
jne .nonzero_nopop
|
|
loop .loop2
|
|
|
|
.nonzero_loop: ; Pops values from the stack and prints them.
|
|
pop dx
|
|
mov al, dl
|
|
.nonzero_nopop: ; Part of the loop that prints the value. Jump to here to print without popping on first iteration.
|
|
int 0x10
|
|
loop .nonzero_loop
|
|
|
|
popa
|
|
ret
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
keyprint:
|
|
; Enters a loop where the keycode of each pressed key is printed
|
|
; [ESC] exits the loop
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
pusha
|
|
.keyprint_loop:
|
|
mov ax, 0x1000 ; BIOS call to wait for key
|
|
int 0x16
|
|
cmp ax, 0x11b ; ESC key
|
|
je .end_keyprint
|
|
|
|
call dumpax
|
|
mov bx, ax
|
|
mov ax, 0xe20
|
|
int 0x10 ; print space
|
|
mov al, bl
|
|
int 0x10 ; print char
|
|
call printCRLF
|
|
jmp .keyprint_loop
|
|
.end_keyprint:
|
|
popa
|
|
ret
|