1 | ; File name : prntdos.asm
|
---|
2 | ; Project name : Print library
|
---|
3 | ; Created date : 7.12.2009
|
---|
4 | ; Last update : 7.12.2009
|
---|
5 | ; Author : Tomi Tilli
|
---|
6 | ; Description : ASM library to for character and string
|
---|
7 | ; printing using DOS.
|
---|
8 |
|
---|
9 | ;--------------- Equates -----------------------------
|
---|
10 |
|
---|
11 | ; Int 21h (DOS) functions
|
---|
12 | FN_DOS_WR_CHAR_STDOUT EQU 02h ; Write Character to Standard Output
|
---|
13 | FN_DOS_WR_STR_STDOUT EQU 09h ; Write String to Standard Output
|
---|
14 |
|
---|
15 |
|
---|
16 | ;-------------- Public functions ---------------------
|
---|
17 | ; Section containing code
|
---|
18 | SECTION .text
|
---|
19 |
|
---|
20 | ;--------------------------------------------------------------------
|
---|
21 | ; Prints character. All character printing functions must
|
---|
22 | ; use this macro to print characters (so printing implementation
|
---|
23 | ; can be easily modified when needed).
|
---|
24 | ;
|
---|
25 | ; PRINT_CHAR
|
---|
26 | ; Parameters:
|
---|
27 | ; DL: Character to print
|
---|
28 | ; Returns:
|
---|
29 | ; Nothing
|
---|
30 | ; Corrupts registers:
|
---|
31 | ; AX
|
---|
32 | ;--------------------------------------------------------------------
|
---|
33 | %macro PRINT_CHAR 0
|
---|
34 | mov ah, FN_DOS_WR_CHAR_STDOUT
|
---|
35 | int 21h
|
---|
36 | %endmacro
|
---|
37 |
|
---|
38 |
|
---|
39 | ;--------------------------------------------------------------------
|
---|
40 | ; Prints string. All string printing functions must
|
---|
41 | ; use this macro to print strings (so printing implementation
|
---|
42 | ; can be easily modified when needed).
|
---|
43 | ;
|
---|
44 | ; PRINT_STR
|
---|
45 | ; Parameters:
|
---|
46 | ; DS:DX: Ptr to '$' terminated string
|
---|
47 | ; Returns:
|
---|
48 | ; Nothing
|
---|
49 | ; Corrupts registers:
|
---|
50 | ; AX
|
---|
51 | ;--------------------------------------------------------------------
|
---|
52 | %macro PRINT_STR 0
|
---|
53 | mov ah, FN_DOS_WR_STR_STDOUT
|
---|
54 | int 21h
|
---|
55 | %endmacro
|
---|
56 |
|
---|
57 |
|
---|
58 | ;--------------------------------------------------------------------
|
---|
59 | ; Prints string and returns number of characters printed.
|
---|
60 | ; All string printing functions must use this macro to print strings
|
---|
61 | ; (so printing implementation can be easily modified when needed).
|
---|
62 | ;
|
---|
63 | ; PRINT_STR_LEN
|
---|
64 | ; Parameters:
|
---|
65 | ; DS:DX: Ptr to STOP terminated string
|
---|
66 | ; Returns:
|
---|
67 | ; DX: Number of characters printed
|
---|
68 | ; Corrupts registers:
|
---|
69 | ; AX
|
---|
70 | ;--------------------------------------------------------------------
|
---|
71 | %macro PRINT_STR_LEN 0
|
---|
72 | call Print_DosCharStr
|
---|
73 | %endmacro
|
---|
74 |
|
---|
75 | ALIGN JUMP_ALIGN
|
---|
76 | Print_DosCharStr:
|
---|
77 | push si
|
---|
78 | push cx
|
---|
79 | mov si, dx ; Load offset to string
|
---|
80 | xor cx, cx ; Zero character counter
|
---|
81 | cld ; LODSB to increment SI
|
---|
82 | ALIGN JUMP_ALIGN
|
---|
83 | .CharLoop:
|
---|
84 | lodsb ; Load from [DS:SI] to AL
|
---|
85 | cmp al, STOP ; End of string?
|
---|
86 | je .Return ; If so, return
|
---|
87 | mov dl, al ; Copy char to DL
|
---|
88 | PRINT_CHAR
|
---|
89 | inc cx ; Increment characters printed
|
---|
90 | jmp .CharLoop ; Loop while characters left
|
---|
91 | ALIGN JUMP_ALIGN
|
---|
92 | .Return:
|
---|
93 | mov dx, cx ; Copy chars printed to DX
|
---|
94 | pop cx
|
---|
95 | pop si
|
---|
96 | ret
|
---|