@iansjack: Yes, you are right, those are relevant.
macros.inc
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; macros
;
%ifndef MACROS__INC
%define MACROS__INC
%define zero(x) xor x, x
%macro write 1
mov si, %1
call near print_str
%endmacro
%endif
consts.inc
Code:
;;; Constants related to the text console
%ifndef CONSTS__INC
%define CONSTS__INC
;;; character constants
NULL equ 0x00 ;; end of string marker
CR equ 0x0D ;; carriage return
LF equ 0x0A ;; line feed
ascii_zero equ 0x30
ascii_upper_A equ 0x41
ascii_lower_a equ 0x61
%endif
simple_print_text_code.inc
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; routine for printing strings
%ifndef SIMPLE_TEXT_PRINT_CODE__INC
%define SIMPLE_TEXT_PRINT_CODE__INC
%include "macros.inc"
;;; print_str - prints the string point to by SI
;;; Inputs:
;;; ES:SI - string to print
print_str:
pusha
mov ah, ttype ; set function to 'teletype mode'
zero(bx)
mov cx, 1
.print_char:
lodsb ; update byte to print
cmp al, NULL ; test that it isn't NULL
jz short .endstr
int VBIOS ; put character in AL at next cursor position
jmp short .print_char
.endstr:
popa
ret
%endif
print_hex_code.inc
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; routine for printing integer values in hex
%ifndef PRINT_HEX_CODE__INC
%define PRINT_HEX_CODE__INC
%include "consts.inc"
%include "macros.inc"
%include "simple_text_print_code.inc"
;;; convert_hex - convert one byte to hexidecimal value
;;; Based on code from the _AMD Athlon Optimization Guide_, p. 84
;;; (http://www.bartol.udel.edu/mri/sam/Athlon_code_optimization_guide.pdf)
;;; Input:
;;; AL = byte to convert
;;; ES = segment where buffer resides
;;; SI = buffer to write to
;;; Output:
;;; [SI] = written buffer
convert_hex:
push bx
mov bl, al
.hi_nibble:
shr al, 4 ; convert the high nibble first
cmp al, 10 ; if x is less than 10, set carry flag
sbb al, 0x69 ; 0..9 –> 96h, Ah..Fh –> A1h...A6h
das ;0..9: subtract 66h, Ah..Fh: Sub. 60h
mov [si], al ;save conversion in SI
.lo_nibble:
inc si
mov al, bl
and al, 0x0F ; clear high nibble
cmp al, 10 ; if x is less than 10, set carry flag
sbb al, 0x69 ; 0..9 –> 96h, Ah..Fh –> A1h...A6h
das ;0..9: subtract 66h, Ah..Fh: Sub. 60h
mov [si], al ;save conversion in SI
pop bx
ret
;;; print_hex_byte - convert a byte to hex anbd print it to console
;;; convert_hex - convert one byte to hexidecimal value ;
;;; Input:
;;; AL = byte to print
;;; ES = segment where buffer resides
;;; SI = buffer to print
;;; Output:
;;; screen
;;; Clobbers:
;;; AL, SI
print_hex_byte:
mov si, word hex_buffer
call near convert_hex
mov si, word hex_buffer
call near print_str
ret
;;; print_hex_word - convert a word to hex and print it to console
;;; Input:
;;; AX = word to print
;;; ES = segment where buffer resides
;;; SI = buffer to print
;;; Output:
;;; screen
;;; Clobbers:
;;; AL, SI
print_hex_word:
xchg ah, al
call near print_hex_byte
xchg ah, al
call near print_hex_byte
ret
;;; print_hex_seg_offset - print a segment:offset pair
;;; Input:
;;; GS = segment
;;; AX = offset
;;; Clobbers:
;;; AL, SI
print_hex_seg_offset:
push ax
mov ax, gs
call near print_hex_word
mov si, colon
call near print_str
pop ax
call near print_hex_word
ret
hex_buffer db 0, 0, NULL ; two bytes, plus null delim
colon db ':', NULL
align 4
%endif
print_hex_long.inc
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; routine for printing doubleword and quadword integer values in hex
%ifndef PRINT_HEX_LONG_CODE__INC
%define PRINT_HEX_LONG_CODE__INC
%include "consts.inc"
%include "macros.inc"
%include "simple_text_print_code.inc"
%include "print_hex_code.inc"
print_hex_dword:
;;; print_hex_dword - convert a doubleword to hex and print it to console
;;; Input:
;;; [DI] = word to print
;;; ES = segment where buffer resides
;;; SI = buffer to print
;;; Output:
;;; screen
;;; Clobbers:
;;; AX, SI
mov ax, [di+2]
call print_hex_word
mov ax, [di]
call print_hex_word
ret
print_hex_qword:
;;; print_hex_qword - convert a quad word to hex and print it to console
;;; Input:
;;; [DI] = word to print
;;; ES = segment where buffer resides
;;; SI = buffer to print
;;; Output:
;;; screen
;;; Clobbers:
;;; AX, SI
mov ax, [di+6]
call print_hex_word
mov ax, [di+4]
call print_hex_word
mov ax, [di+2]
call print_hex_word
mov ax, [di]
call print_hex_word
ret
%endif