-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.s
executable file
·150 lines (138 loc) · 2.19 KB
/
display.s
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
CharsDisplayed:
.byte 0
PutCarriageReturn:
call DisplayMessage
.byte 13
.byte 10
.byte 0
ret
DisplaySignedAX:
movb CharsDisplayed,#0
or ax,ax
jns DisplayAXInDecimal
push ax
movb al,#'-'
call DisplayCharacter
pop ax
neg ax
call DisplayAXInDecimal
neg ax
ret
DisplayAXInDecimal:
movb CharsDisplayed,#0
push ax
push dx
push cx
push bx
mov cx,#10
mov bx,#0
MoreDigitsToBeFound:
xor dx,dx
div cx
push dx
inc bx
or ax,ax
jnz MoreDigitsToBeFound
MoreDigitsToBeDisplayed:
pop ax
call DisplayDecimalDigit
dec bx
jnz MoreDigitsToBeDisplayed
pop bx
pop cx
pop dx
pop ax
ret
DisplayMessage:
movb CharsDisplayed,#0
push bp
mov bp,sp
push bx
push dx
push ax
mov bx,2[bp]
MoreCharsToBeDisplayed:
movb al,[bx]
inc bx
orb al,al
jz MessageEnded
call DisplayCharacter
jmps MoreCharsToBeDisplayed
MessageEnded:
mov 2[bp],bx
pop ax
pop dx
pop bx
pop bp
ret
DisplayOtherMessage:
movb CharsDisplayed,#0
push bx
push ax
StillMoreOtherChars:
movb al,[bx]
inc bx
orb al,al
jz OtherMessageEnded
call DisplayCharacter
jmps StillMoreOtherChars
OtherMessageEnded:
pop ax
pop bx
ret
PadWithSpaces:
push ax
cmpb al,CharsDisplayed
jc PaddedWithSpaces
jz PaddedWithSpaces
movb ah,al
movb al,#' '
MorePaddingRequired:
call DisplayCharacter
cmpb ah,CharsDisplayed
jnz MorePaddingRequired
PaddedWithSpaces:
pop ax
ret
DisplayDecimalDigit:
push ax
andb al,#0x0F
addb al,#'0'
call DisplayCharacter
pop ax
ret
DisplayRegister:
push cx
movb ch,#4
DisplayRegisterMore:
rol ax
rol ax
rol ax
rol ax
call DisplayHexDigit
decb ch
jnz DisplayRegisterMore
pop cx
ret
HexDigitTable:
.ascii "0123456789ABCDEF"
DisplayHexDigit:
push ax
push bx
andb al,#15
mov bx,#HexDigitTable
xlat
call DisplayCharacter
pop bx
pop ax
ret
DisplayCharacter:
push ax
push dx
movb dl,al
movb ah,#2
int #0x21
incb CharsDisplayed
pop dx
pop ax
ret