/
print.asm
97 lines (72 loc) · 1.97 KB
/
print.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
; this example shows how to print string.
; the string is defined just after the call instruction.
; this example does not use emu8086.inc library.
name "print"
org 100h
; set these values to registers for no particular reason,
; we just want to check that the procedure does not destroy them.
mov si, 1234h
mov ax, 9876h
; 0Dh,0Ah - is the code
; for standard new
; line characters:
; 0Dh - carriage return.
; 0Ah - new line.
call printme
db 'hello', 0
; gets here after print:
mov cx, 1
call printme
db ' world!', 0Dh,0Ah, 0
; gets here after print:
mov cx, 2
call printme
db 'hi there!', 0Ah
db "what's up?", 0Dh,0Ah
db 'printing!', 0
; printme returns here:
xor cx, cx
call printme
db 0xd,0xa,"press any key...", 0
; wat for any key....
mov ah, 0
int 16h
ret ; return to os.
;*******************************
; this procedure prints a null terminated
; string at current cursor position.
; the zero terminated string should
; be defined just after
; the call. for example:
;
; call printme
; db 'hello world!', 0
;
; address of string is stored in the
; stack as return address.
; procedure updates value in the
; stack to make return
; after string definition.
printme:
mov cs:temp1, si ; protect si register.
pop si ; get return address (ip).
push ax ; store ax register.
next_char:
mov al, cs:[si]
inc si ; next byte.
cmp al, 0
jz printed
mov ah, 0eh ; teletype function.
int 10h
jmp next_char ; loop.
printed:
pop ax ; re-store ax register.
; si should point to next command after
; the call instruction and string definition:
push si ; save new return address into the stack.
mov si, cs:temp1 ; re-store si register.
ret
; variable to store original
; value of si register.
temp1 dw ?
;*******************************