Title: More about procedures and Video Processing
1More about proceduresand Video Processing
2Lesson plan
- Review existing concepts
- More about procedures and boolean expression
- Video processing
3Review
- Procedure
- name PROC the code of the procedure
...RETname ENDP - Calling a procedure
- CALL ltname of the proceduregt
- Address of the next instruction will be pushed
onto STACK
4More about procedures
- Passing parameters
- Are very similar to the concept of passing
parameters in C/C and Java - A program may pass parameters by
- Value
- Reference
5Passing parameters by value
- Parameters are the actual data item.
- Passing value in register
- Store values being passed in registers
- Call the procedure
- Example
- MOV AX, operand1
- MOV BX, operand2
- CALL MULTIPROC
-
- MULTIPROC PROC
- MUL BX
- RET
- MULTIPROC ENDP
MULTIPROC(operand1,operand)
6Passing parameters by value
- Passing value in STACK
- Push values being passed in STACK
- Call the procedure
- Pop values from STACK
- Example
- PUSH operand1
- PUSH operand2
- CALL MULTIPROC
-
- MULTIPROC PROC
- PUSH BP
- MOV BP, SP
- MOV AX, BP8
- MUL WORD PTR BP4
- POP BP
- RET
- MULTIPROC ENDP
MULTIPROC(operand1,operand)
7Passing parameters by value
- Passing value in STACK
- Address the limitations in terms of number of
registers - More complicated because we need indirect
addressing to access the stack (use of BP) -
8Passing parameters by value
- Operand1 DW 10 (0AH)
- Operand2 DW 2 (02H)
- PUSH BP to save its content
9Passing parameters by value
- MOV BP, SP
- MOV AX, BP8
- MUL WORD PTR BP4
- POP BP
-
10Passing parameters by value
- MOV BP, SP
- MOV AX, BP8
- MUL WORD PTR BP4
- POP BP
-
11Passing parameters by Reference
- Instead of passing values, we pass the address
using register or stack
LEA SI, operand1 LEA DI, operand2 CALL
MULTIPROC MULTIPROC PROC MOV AX, SI MUL
DI RET MULTIPROC ENDP
MULTIPROC(operand1, operand2)
12Passing parameters by Reference
- Instead of passing values, we pass the address
using register or stack
PUSH OFFSET operand1 PUSH OFFSET operand2
CALL MULTIPROC MULTIPROC PROC
PUSH BP MOV BP, SP MOV BX, BP6 MOV
DI,BP4 MOV AX, BX MUL WORD PTR
DI POP BP RET 4 MULTIPROC ENDP
MULTIPROC(operand1, operand2)
13Video processing
- Use INT instruction to handle inputs and outputs
- INT 10H screen handling
- INT 21H for displaying screen output
- Main idea
- Insert a value in AH register which is used to
identify the type of service the interrupt needs
to perform
14Screen features
- 25 rows (0-24) and 80 columns (0-79)
(0,79)
(0,0)
(24,0)
(24,79)
15Screen features
- Cursor location
- Upper left corner Row 0, Column 0
- Upper right corner Row 0, Column 79
- Lower left corner Row 24, Column 0
- Lower right corner Row 24, Column 79
- Center Row 12, Column 39
16Screen features
- Video Display Area
- Text mode 4KB in BIOS (2K for characters and 2K
for attributes) - Pages 0 to 7
- INT 10H Set cursor (AH 02H)
- INT 10H Clear Scroll screen (AH 06H)
17Screen features
- Setting cursor
- INT 10H function 02H tells BIOS to set the
cursor - Step 1 Determine the row and column that we
want to set our cursor at. E.g row 12, column
40) - Step 2 Load 02H to AH. Load page to BH, Row
to DH, and Column to DL - Step 3 Call INT 10H function
18Screen features
- Example Set cursor at (12,40)
- MOV AH, 02H
- MOV BH, 0 page to BH
- MOV DH, 12 row to DH
- MOV DL, 40 column to DL
- INT 10H
19Screen features
- Clear Scrolling screen
- INT 10H function 06H tells BIOS to clear or
scroll screen - Step 1 Load 06H to AH
- Step 2Determine number of lines to scroll
- Step 3Determine the attributes of the screen
(background and foreground colors). Load them
into BH - Step 4 Load the starting rowcolumn to CX
- Step 5 Load the ending rowcolumn to DX
- Step 6 Call INT 10H
20Screen features
- Example
- MOV AH, 06H
- MOV BH, 71H
- MOV CX, 0000H Row0, Column 0
- MOV DX, 184FH Row24 (18H), Column 79(4FH)
- INT 10H
21Screen features
- Attribute byte in text mode determines the
characteristics of each displayed characters
710111 0001 (White background and Blue
foreground)
22Screen features
- INT 21H
- Display ASCII characters (02H)
- Display string (09H or 40H)
- Get input from keyboard (0AH or 3FH)
23Screen features
- Display a character
- Step 1 Set AH 02H
- Step 2 Load the character to DL
- Step 3 Call INT 21H to display the character
24Screen features
- Example
- MOV AH, 02H
- MOV DL, C
- INT 21H
25Practice
- Clear screen
- Set cursor to the middle of screen
- Display the characters (5) in
- CHAR_TBL DB A ,B, C, D, E
- at the middle of the screen
26Answer for Practice
- LEA BX,CHAR_TBL
- MOV CX,5
- L10
- MOV AH, 02H
- MOV DL, BX
- INT 21H
- INC BX element of CHAR_TBL
- LOOP L10
27INT 21H displaying screen
- INT 21H, function 09H display a string which is
followed by the dollar() sign - Step 1 Declare a string, which is followed by
dollar sign - Step 2 Set DS to the beginning address of data
segment. And set AH 09H - Step 3 Load offset of the string to DX
- Step 4 Call INT 21H
28INT 21H displaying screen
- Example
- message db "Hello everybody! I am learning
assembly language!"," - mov ah,09 move 9 to AH
- lea dx,message
- int 21h
29INT 21H displaying screen
- INT 21H, function 40H
- Use file handles to process display operations
- Procedure
- Step 1 Set AH40H
- Step 2 Set BX file handle (of screen)
- Step 3 Set CX number of characters to display
- Step 4 Set DX Offset Address of display area
- Step 5 Call INT 21H
30INT 21H displaying screen
- File handle is a number used to refer to a
specific device - Handle Device
- 00 Input (keyboard)
- 01 Output (screen)
- 04 Printer
31INT 21H displaying screen
- Example
- message db Hello, 0DH, 0AH
- MOV AH,40H move 40H to AH
- MOV BX, 01
- MOV CX, 7
- lea dx,message
- int 21h
32Practice
- Display COMPSCI 271 using INT 21H
- function 40H and INT 21H function 09H
33INT 21H for keyboards
- INT 21H function
- 0AH input from keyboard
- 3FH input from keyboard
34INT 21H for keyboards
- INT 21H function 0AH
- Step 1Set AH 0AH
- Step 2 Load offset address of the parameter list
into DX - Step 3 Call INT 21H
-
35INT 21H for keyboards
- Parameter list is a structure which consists of
- ltName of parameter listgt LABEL BYTE
- ltVariable represents maximum number of input
charactersgt DB ltvaluegt - ltVariable represents actual number of input
charactersgt DB ltvaluegt - ltVariable to contain typed charactersgt
36INT 21H for keyboards
- Example
- Para_list label byte
- max_len DB 100
- act_len DB ?
- input DB 100 DUP( )
- MOV AH, 0AH
- LEA DX, Para_list
- INT 21H
37INT 21H for keyboards
- Example
- Assume the input string is CS271
- act_len 5
- input CS271
- MOV BH, 00
- MOV BL, ACT_LEN
- MOV INPUTBX,
CS271
38INT 21H function 3F
- This uses file handles to request keyboard input
- Step 1 Set AH 3FH
- Step 2 Set BX00H (file handle 00 represents
keyboard) - Step 3 Set CX maximum number of character to
accept - Step 4 Load offset address of area for entering
characters to DX
39INT 21H function 3F
- Example
- input DB 100 DUP( )
- MOV AH, 3FH
- MOV BX, 00H
- MOV CX, 100
- LEA DX, input
- INT 21H
40INT 21H function 3F
- Example (not available in EMU8086)
- input DB 100 DUP( )
- MOV AH, 3FH
- MOV BX, 00H
- MOV CX, 100
- LEA DX, input
- INT 21H
41Practice
- Write a program to read a string (length lt 50)
from keyboard - Output the string on the screen at (12,40)
42Project 2
43Adavanced Screen Processing
- Explore INT 10H to
- Set video mode
- Display attribute or character at cursor position