0% found this document useful (0 votes)
29 views31 pages

Assembly - Chapter - 12 - Updated - Part - 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views31 pages

Assembly - Chapter - 12 - Updated - Part - 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Chapter no.

12
Part 2

Text Display and


Keyboard
Programming
Engr. Fiaz Khan

Engr. Muhammad Fiaz 1


INT 10H
•Directly writing to the screen buffer is tedious for controlling the
display.
•INT 10h (video interrupt) is used for easier screen control.
•Functions of INT 10h are selected by placing the function
number in the AH register.

Engr. Muhammad Fiaz 2


INT 10H
•Directly writing to the screen buffer is tedious for controlling the
display.
•INT 10h (video interrupt) is used for easier screen control.
•Functions of INT 10h are selected by placing the function
number in the AH register.

Engr. Muhammad Fiaz 3


Engr. Muhammad Fiaz 4
Engr. Muhammad Fiaz 5
; Example 12.1: Set the VGA adapter for 80 x 25 color text display

.model small ; Specify the memory model


.stack ; Define the stack segment
.data ; Begin the data segment
; No data required for this program

.code ; Begin the code segment


main proc ; Define the main procedure

; Set the display mode to 80x25 color text


MOV AH, 0 ; Function 0 - Set video mode
MOV AL, 3 ; Mode 3 - 80x25 color text display
INT 10h ; Call BIOS interrupt to set the display mode

; Exit the program


MOV AH, 4Ch ; Function to terminate the program
INT 21h ; Call DOS interrupt to terminate

main endp ; End of the main procedure


end main ; End of the program

Engr. Muhammad Fiaz 6


Engr. Muhammad Fiaz 7
Engr. Muhammad Fiaz 8
MODEL SMALL
.STACK 100H

.CODE
MAIN PROC
; Set the cursor size
MOV AH, 1 ; Function 1 - Set cursor size
MOV CH, 0 ; Starting row (top of the cursor)
MOV CL, 13 ; Ending row (bottom of the cursor)
INT 10h ; Call BIOS interrupt to set cursor size

; Exit program
MOV AH, 4CH ; DOS terminate program function
INT 21h ; Call DOS interrupt

MAIN ENDP
END MAIN
Engr. Muhammad Fiaz 9
Engr. Muhammad Fiaz 10
Engr. Muhammad Fiaz 11
.MODEL SMALL
.STACK 100H

.CODE
MAIN PROC
; Set up video segment (optional for text mode operations)
MOV AX, 0B800h ; Video memory segment for color text mode
MOV DS, AX ; Load AX into DS (if needed for direct memory
access)

; Move cursor to the center of the screen (Row 12, Column 39)
MOV AH, 2 ; Function 2 - Set cursor position
XOR BH, BH ; Page 0 (clear BH to 0)
MOV DX, 0C27h ; Row 12 (0Ch), Column 39 (27h)
INT 10h ; Call BIOS interrupt to move the cursor

; Exit program
MOV AH, 4CH ; DOS terminate program function
INT 21h ; Call DOS interrupt

MAIN ENDP
END MAIN
Engr. Muhammad Fiaz 12
Engr. Muhammad Fiaz 13
Engr. Muhammad Fiaz 14
.model small
.stack 100h
.data
msg db 'Current cursor position: Row = ', 0
row db 0
msg2 db ', Column = ', 0
col db 0
newline db 13, 10, '$' ; Carriage return and line feed for new line
.code
main proc
mov ax, @data
mov ds, ax

; Request cursor position


mov ah, 03h ; Function: Read Cursor Position
xor bh, bh ; Page number 0
int 10h ; BIOS video service

; Store cursor position


mov row, dh ; Store row number
mov col, dl ; Store column number

Engr. Muhammad Fiaz 15


; Print message and cursor position
lea dx, msg
mov ah, 09h
int 21h ; DOS interrupt to print message

; Convert row to ASCII and print


mov al, row
add al, 30h ; Convert to ASCII
mov dl, al
mov ah, 02h
int 21h ; DOS interrupt to print character

lea dx, msg2


mov ah, 09h
int 21h ; DOS interrupt to print message

; Convert column to ASCII and print


mov al, col
add al, 30h ; Convert to ASCII
mov dl, al
mov ah, 02h
int 21h ; DOS interrupt to print character

lea dx, newline


mov ah, 09h
Engr. Muhammad Fiaz 16
int 21h ; DOS interrupt to print new line
; Check if at the top of the screen
or dh, dh ; Test row number
jz exit ; If at the top, exit

; Move cursor up one row


mov ah, 02h ; Function: Set Cursor Position
dec dh ; Move up one row
int 10h ; BIOS video service

exit:
mov ah, 4Ch ; Function: Terminate program
int 21h ; DOS interrupt

main endp
end main

Engr. Muhammad Fiaz 17


Engr. Muhammad Fiaz 18
Engr. Muhammad Fiaz 19
.model small
.stack 100h

.data
; No data section required for this program.

.code
main proc
MOV AX, @data ; Initialize the data segment
MOV DS, AX

; Select active display page


MOV AH, 5 ; Function 5 - Select active display page
MOV AL, 1 ; Page 1 (set as the active display page)
INT 10h ; Call BIOS interrupt to select the display page

; Exit program
MOV AH, 4Ch ; DOS interrupt to terminate the program
INT 21h ; Terminate program

main endp
Engr. Muhammad Fiaz 20
end main
Set Al = 1, select the page 1
Set al = 0,select the page 0
Change these values for different results

Engr. Muhammad Fiaz 21


Engr. Muhammad Fiaz 22
.MODEL SMALL
.STACK 100H

.CODE
MAIN PROC
; Set up video segment
MOV AX, 0B800h ; Video memory segment for color text mode
MOV DS, AX ; Load AX into DS

; Scroll up function to clear the screen


MOV AH, 6 ; Function 6 - Scroll up
XOR AL, AL ; Clear entire screen (0 lines preserved)
XOR CX, CX ; Upper-left corner (Row 0, Column 0)
MOV DX, 184Fh ; Lower-right corner (Row 24, Column 79)
MOV BH, 7 ; Normal video attribute (white text on black
background)
INT 10h ; Call BIOS interrupt to perform the scroll

; Exit program
MOV AH, 4CH ; DOS terminate program function
INT 21h ; Call DOS interrupt

MAIN ENDP Engr. Muhammad Fiaz 23


END MAIN
Engr. Muhammad Fiaz 24
Engr. Muhammad Fiaz 25
.model small
.stack 100h
.data
.code
main proc
mov ax, @data
mov ds, ax

; Set up the scroll parameters


mov ah, 07h ; Function: Scroll the Screen or a Window Down
mov al, 35 ; Number of lines to scroll (1 line in this example)
mov bh, 07h ; Attribute for blank lines (white on black in this
example)
mov ch, 5 ; Upper left row of the window (example value)
mov cl, 10 ; Upper left column of the window (example value)
mov dh, 20 ; Lower right row of the window (example value)
mov dl, 70 ; Lower right column of the window (example value)

; Scroll the screen or window down


int 10h ; BIOS video service

; Terminate program
mov ah, 4Ch ; Function: Terminate program
int 21h ; DOS interrupt

main endp Engr. Muhammad Fiaz 26


Engr. Muhammad Fiaz 27
Engr. Muhammad Fiaz 28
.model small
.stack 100h

.data
; No data section required for this program.

.code
main proc
MOV AX, @data ; Initialize the data segment
MOV DS, AX

; Get the current video mode and active page


MOV AH, 0Fh ; Function 0Fh - Get current video mode
INT 10h ; Call BIOS interrupt, BH = active page

; Change the display page


MOV AL, BH ; Move the current active page to AL
XOR AL, 1 ; Toggle bit 0 to switch between page 0 and page 1
MOV AH, 5 ; Function 5 - Select active display page
INT 10h ; Call BIOS interrupt to set the new active page

; Exit program
MOV AH, 4Ch ; DOS interrupt to terminate the program
INT 21h ; Terminate program

main endp
end main

Engr. Muhammad Fiaz 29


Engr. Muhammad Fiaz 30
ENGR. MUHAMMAD FIAZ
LECTURER COMPUTER SCIENCE

TELF/EF SET / ACEPT CERTIFIED

MICROSOFT ACADEMY TRAINER

ORACLE CERTIFIED PROFESSIONAL

GOOGLE CERTIFIED PROFESSIONAL

THANK YOU! Lahore, Pakistan

+92-320-7617-093

[email protected]
Do you have any questions?
https://www.linkedin/in/fiazofficials

Engr. Muhammad Fiaz 31

You might also like