-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbios_video_mode.asm
More file actions
178 lines (154 loc) · 4.84 KB
/
Copy pathbios_video_mode.asm
File metadata and controls
178 lines (154 loc) · 4.84 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
; =============================================================================
; TITLE: BIOS Set Video Mode
; DESCRIPTION: Demonstrates how to switch video modes via BIOS (INT 10h).
; Switches to 80x25 Color Text Mode (Mode 03h).
; AUTHOR: Amey Thakur (https://github.com/Amey-Thakur)
; REPOSITORY: https://github.com/Amey-Thakur/8086-ASSEMBLY-LANGUAGE-PROGRAMS
; LICENSE: MIT License
; =============================================================================
.MODEL SMALL
.STACK 100H
; -----------------------------------------------------------------------------
; CODE SEGMENT
; -----------------------------------------------------------------------------
.CODE
MAIN PROC
; --- Step 1: Set Video Mode (INT 10h / AH=00h) ---
; AL = Video Mode
; 03h = 80x25 Text (Color) - Default DOS Mode
; 13h = 320x200 Graphics (256 Colors)
MOV AH, 00H
MOV AL, 03H
INT 10H
; --- Step 2: Exit ---
; Note: Switching modes typically clears the screen.
; -------------------------------------------------------------------------
; WHAT THIS PROGRAM COMPUTED
;
; The work above leaves its answer in the registers. Printing them is what
; makes the program demonstrate itself instead of needing a debugger.
; -------------------------------------------------------------------------
CALL RPT_REGISTERS
MOV AH, 4CH
INT 21H
MAIN ENDP
; -----------------------------------------------------------------------------
; THE REPORT
;
; Everything below belongs to the report added so this program shows its result
; rather than leaving it in the registers for a debugger to find. The strings
; sit here beside the code that uses them, which is legal: the assembler places
; every declaration in the data image wherever it is written.
; -----------------------------------------------------------------------------
RPT_HEAD DB 0DH, 0AH, 'Registers when the program finished:', 0DH, 0AH, '$'
RPT_N_AX DB ' AX = ', '$'
RPT_N_BX DB ' BX = ', '$'
RPT_N_CX DB ' CX = ', '$'
RPT_N_DX DB ' DX = ', '$'
RPT_NL DB 0DH, 0AH, '$'
; -----------------------------------------------------------------------------
; RPT_REGISTERS
;
; Prints the four general registers as they were on entry.
;
; They are pushed first and read back through BP, because printing needs AX for
; the value and DX for the message. Reading them any later would report the
; state of the printer rather than the state of the program.
; -----------------------------------------------------------------------------
RPT_REGISTERS PROC
PUSH DX
PUSH CX
PUSH BX
PUSH AX
PUSH BP
MOV BP, SP
; The program may have pointed DS somewhere of its own, at a video segment
; or at segment zero, and the strings below live in the data image. SEG
; gives their segment whatever the program left in DS.
PUSH DS
MOV AX, SEG RPT_HEAD
MOV DS, AX
LEA DX, RPT_HEAD
CALL RPT_SAY
LEA DX, RPT_N_AX
CALL RPT_SAY
MOV AX, [BP+2]
CALL RPT_DECIMAL
LEA DX, RPT_N_BX
CALL RPT_SAY
MOV AX, [BP+4]
CALL RPT_DECIMAL
LEA DX, RPT_N_CX
CALL RPT_SAY
MOV AX, [BP+6]
CALL RPT_DECIMAL
LEA DX, RPT_N_DX
CALL RPT_SAY
MOV AX, [BP+8]
CALL RPT_DECIMAL
LEA DX, RPT_NL
CALL RPT_SAY
POP DS
POP BP
POP AX
POP BX
POP CX
POP DX
RET
RPT_REGISTERS ENDP
; -----------------------------------------------------------------------------
; RPT_DECIMAL
;
; Prints the unsigned value in AX as decimal, lowest digit last.
; -----------------------------------------------------------------------------
RPT_DECIMAL PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
XOR CX, CX
MOV BX, 10
RPT_SPLIT:
XOR DX, DX
DIV BX
PUSH DX
INC CX
CMP AX, 0
JNE RPT_SPLIT
RPT_EMIT:
POP DX
ADD DL, '0'
MOV AH, 02H
INT 21H
LOOP RPT_EMIT
POP DX
POP CX
POP BX
POP AX
RET
RPT_DECIMAL ENDP
; -----------------------------------------------------------------------------
; RPT_SAY
;
; Prints the dollar terminated string at DS:DX, leaving AX alone.
; -----------------------------------------------------------------------------
RPT_SAY PROC
PUSH AX
MOV AH, 09H
INT 21H
POP AX
RET
RPT_SAY ENDP
END MAIN
; =============================================================================
; TECHNICAL NOTES & ARCHITECTURAL INSIGHTS
; =============================================================================
; 1. VIDEO MODES:
; - Mode 03h: Standard Text Mode (80 columns, 25 rows).
; - Mode 13h: VGA Graphics (320x200).
;
; 2. SIDE EFFECTS:
; Setting the video mode resets the video controller, clears video memory,
; resets the cursor to (0,0), and loads the default font. It is the standard
; way to "Clear Screen".
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =