Presentation is loading. Please wait.

Presentation is loading. Please wait.

Direct video practice and Keyboard Operations

Similar presentations


Presentation on theme: "Direct video practice and Keyboard Operations"— Presentation transcript:

1 Direct video practice and Keyboard Operations

2 Midterm Avg: 182/195 (93%)

3 Midterm 1.1. For the data bits 01001001, the parity bit is (a) 0 (b) 1
(c) irrelevant (d) unknown

4 Midterm 1.2. The data segment contains (a) read-only memory,
(b) the machine instructions that are to execute, (c) a program's defined data, constants, and work areas, (d) values that a program needs to save temporarily.

5 Midterm 1.3. The binary representation for decimal 117 is
a c b d

6 Midterm 1.5 Which of the following is an invalid name?
a. _hello b. #hello c. $hello d. hello

7 Midterm 1.6. Which one of the following statements is invalid?
(a) MOV AL,035AH (b) MOV CX,035AH (c) MOV AX,035AH (d) MOV DI,035AH

8 Midterm 1.7. INT 21H function 09H for displaying requires defining a display string in the data area, immediately followed by this character: (b) & (c) $ (d) _

9 Midterm 1.8 Given DATSG is the name of the data segment. The instruction MOV DS,DATSG is a correct instruction to initialize the address of the data segment in the DS register. a. True b. False

10 Midterm 1.9 Identify the following colors in the attribute byte : (a) Blue foreground and black background (b) Blue foreground and white background (c) White foreground and blue background (d) Black foreground and blue background

11 Midterm 1.10 In what significant way do the following MOV instructions differ in execution MOV DX,AC24H MOV DX,[AC24]H a. The first MOV moves immediate value AC24H to DX while the second MOV moves AC24H to location specified by DS:DX b. The first MOV moves immediate value AC24H to DX while the second MOV moves the contents of locations AC24H and AC25H to DX. c. The first MOV moves immediate value AC24H to location specified by DS:DX while the second MOV moves the content of locations AC24H and AC25H to DX d. The first MOV moves immediate value AC24H to DX while the second MOV moves the content of locations AC24H to DX.

12 Midterm 1. The _code____ segment contains the machine instructions that are to execute. The _data____ segment contains a program's defined data, constants, and work areas. The _stack_____ contains any data and addresses that you need to save temporarily. 2. The _IP__ register contains the offset address of the instruction that is to execute next and is associated with the _CS__ register that addresses the code segment.

13 Midterm 3. The LOOP instruction requires an initial value in the _CX__ register. For each iteration, LOOP deducts 1 from this value; if it is __zero____, control drops through to the following instruction, and if it is __non zero_____, control jumps to the operand address. 4. For INT 21H function 0AH, the area for keyboard input requires definition of a _parameter list__. The first byte contains maximum number of character entered_. The second byte is for the operation to store the _actual number of character entered___. The third byte begins a field that is to contain _entered characters______________________.

14 Midterm 5. A RET instruction that returns from a near procedure pops the original value from the stack into the IP___ register and increments the _SP__ register by 2. 6. For screen clearing or scrolling, use BIOS INT _10H__ and insert function _06H__ in AH

15 Midterm 7. The first byte of an instruction is the _operation_; the other bytes are _operands__, which reference an immediate value, register, or memory location. 8. On loading an .EXE program into memory for execution, the loader stores the address of the PSP in the _DS___ and _ES___ registers, the address of the stack in the __SS__ register, and the size of the stack in the ___SP_ register.

16 Midterm 9. The BIOS Data Area begins in low memory at segment address __40[0] H______ 10. The statement DB 0 defines one _byte___ initialized with a _zero___ value.

17 Midterm III. 1. SS: 2A600H + 100H 2A700H -> SS: 2A70H CS: 2A600H

18 Midterm III. 1. c. ES: 2A60H d. SP: 0030H

19 Midterm III. 2 a. b H + 011AH = 352CH BH BL 34H 12H BH BL 35H 2CH

20 Midterm III. 2 c. 0134 0135 2CH 35H

21 Midterm 3. WORD3: 10*30 = 300 4. CX = 5 AX = 10 CX = 4 AX = 20

22 Direct Video Display Fastest way to display text or graphic characters is to transfer them directly to video display area The address of page 0 for mode 3 is B800[0]H. Each character require two bytes (one for representing the character itself and one for its attribute) Moving a pair of character:attribute into video area of the active page will cause the character appear immediately on screen

23 Direct Video Display 80 columns (0-79) 25 rows (0-24)
Hint: Similar to the use one dimension array to represent this area. Each element put in this area takes 2 bytes. We start this array from 0 Example: ES:[00] = 48H ES:[01] = 1FH (0,0) MOV ES:[00], 48H MOV ES:[01], 1FH

24 Direct Video Display (0,39) ES:[78] = 48H ES:[79] = 0FH
MOV ES:[78], 48H MOV ES:[79], 0FH (1,0) (1,39) MOV ES:[160], 48H MOV ES:[161], 0FH MOV ES:[238], 48H MOV ES:[239], 0FH ES:[160] = 48H ES:[161] = 0FH ES:[238] = 48H ES:[239] = 0FH

25 Example of direct video display
MOV AX, 0B800h MOV ES, AX ; print message using ES ; as segment: MOV ES:[00h], 48h ;H MOV ES:[02H], 45h ;E MOV ES:[04H], 4ch ;L MOV ES:[06H], 4ch ;L MOV ES:[08H], 4fh ;O

26 Example of direct video display

27 Example of direct video display
MOV AX, 0B800H MOV ES, AX MOV AX, 0003H ; Set the current video mode to text mode INT 10H ; INT 10H, function 00H (mode=03H is standard text) MOV AX, 0500H ; Set the active page = 00 INT 10H CALL DISPLAY

28 Example of direct video display
DISPLAY PROC NEAR mov cx,25 ;vertical line mov di,0 again1: mov es:[di],48h mov es:[di+1],4eh add di,80 loop again1 DISPLAY ENDP

29 Direct Video Display

30 Direct video display Practice
1. Open your browser and open this page: C:\emu8086\documentation\8086_instruction_set.html And C:\emu8086\documentation\8086_and_dos_interrupts.html 2. Open your emu8086 software 3. Cut and paste (or type) the following code (as shown in the next page) and save as directvideo.asm

31 END MAIN ;End of program
page 60,132 TITLE VideoPractice DirectDisplay ; STACK SEGMENT PARA STACK 'Stack' DW DUP(0) STACK ENDS ; DATASEG SEGMENT PARA 'Data' ; Please insert your data declaration here DATASEG ENDS CODESEG SEGMENT PARA 'Code' MAIN PROC FAR MOV AX, 0B800H MOV ES, AX ; Please enter your code here MOV AX,4C00H ;exit procedure INT 21H MAIN ENDP CODESEG ENDS END MAIN ;End of program

32 Direct video display Practice
4. Modify your code so that it performs the following tasks: Draw horizontal line (40 character E) on the screen using direct video display 5. Compile and run your code. It should look something like:

33 Coding MOV AX, 0B800h MOV ES, AX mov cx,40 ;horizontal line mov di,0
again2: mov es:[di],45h mov es:[di+1],5eh add di,2 loop again2

34 Lesson plan Brief go over keyboard operations
Focus on String operation

35 Keyboard Operations Keyboard provides three basic types of keys:
Standard characters: A-Z, a-z,0-9,%,$,#. Extended function key: Function keys: F1,F2..Shift-F1.. Numeric keypad keys: Home,End, Arrows, Page Up, Page Down. Special keys Alt, Ctrl, and Shift

36 INT 21H Functions Direct keyboard input no echo:
if there is no character in the keyboard buffer, the function waits until any key is pressed. Example: example: MOV AH, 7 INT 21H

37 INT 21H Function 0BH: Check Keyboard status:
Return FFH in AL if an input character is available in the keyboard buffer and Return 00H if no character is available MOV AH, 7 INT 21H MOV AH, 0BH CMP AL, 00H JE PRINTLABEL JMP CONT PRINTLABEL: ………….. CONT:……

38 INT 21H Function 0Ch - flush keyboard buffer and read standard input. Example: MOV AH, 0CH MOV AL, 07H INT 21H

39 Keyboard buffer BIOS Data Area starts at 40:1EH
INT 09H is automatically executed when you press a key. This interrupt points to an interrupt-handling routines in ROM BIOS. The BIOS routine reads the scan code and compares it with entries in a scan code table for the associate ASCII character

40 BIOS INT 09H and the keyboard buffer
When we press a key, the keyboard processor automatically generates its scan code and issue INT 09H When we release the key with one-half second, it generates a second scan code to tell the interrupt routine that you have released the key.

41 Address 41AH: current head of the buffer, the next position for INT 16H is to get a character entered from the keyboard 41CH: current tail of the buffer. The next position for INT 09H to store a character entered from the keyboard 41EH: beginning of the keyboard buffer itself.

42 INT 16H operations for keyboard
INT 16H is the basic BIOS keyboard operation used extensively by software developers

43 INT 16H operations for keyboard
INT 16h / AH = 00h - get keystroke from keyboard (no echo). return: AH = BIOS scan code. AL = ASCII character. MOV AH, 00H INT 16H

44 Example MOV AH, 00H INT 16H CMP AL,'c' JE PRINTPROMPT JMP CONT
……… CONT:

45 INT 16H INT 16h / AH = 01h - check for keystroke in the keyboard buffer. return: ZF = 1 if keystroke is not available. ZF = 0 if keystroke available. AH = BIOS scan code. AL = ASCII character. (if a keystroke is present, it is not removed from the keyboard buffer).

46 String operations

47 Processing String Data
Two ways to code string instructions 1. Address of Operands are implied E.g: MOVS BYTE1, BYTE2 Need to have: BYTE1 is stored at ES:DI BYTE2 is stored at ES:SI

48 Processing String Data
Two ways to code string instructions 2. Move the addresses of operands in DI and SI and use the instruction without OPERANDS E.g: LEA DI, BYTE2; BYTE2 at ES:DI LEA SI, BYTE1; BYTE1 at DS:SI MOVSB ; MOVE BYTE2 to BYTE1

49 String operations Don’t forget to initialize the DS and ES by:
MOV AX, DATASEG MOV DS, AX MOV ES, AX

50 MOVSB Copy byte at DS:[SI] to ES:[DI]. Update SI and DI.
if DF = 0 then SI = SI + 1 DI = DI + 1 else SI = SI - 1 DI = DI - 1

51 MOVSB Example: a1 DB 5 DUP('&') a2 DB 5 DUP(' ') LEA SI, a1 LEA DI, a2
MOV CX, 5 REP MOVSB

52 Repeat String Prefix (REP)
Repeat following MOVSB, MOVSW, LODSB, LODSW, STOSB, STOSW instructions CX times. check_cx: if CX <> 0 then do following chain instruction Decrease CX = CX - 1 go back to check_cx else exit

53 MOVSW Copy word at DS:[SI] to ES:[DI]. Update SI and DI. ES:[DI] = DS:[SI] if DF = 0 then SI = SI + 2 DI = DI + 2 else SI = SI - 2 DI = DI - 2

54 Example a1 DW 5 DUP('&') a2 DW 5 DUP(' ') LEA SI, a1 LEA DI, a2
MOV CX, 5 REP MOVSW

55 LODSB Load byte at DS:[SI] into AL. Update SI. AL = DS:[SI]
if DF = 0 then SI = SI + 1 else SI = SI - 1

56 Example SRC_STR DB 'NEWYORK' DES_STR DB 7 DUP (' ') LEA SI, SRC_STR
String reverse SRC_STR DB 'NEWYORK' DES_STR DB 7 DUP (' ') LEA SI, SRC_STR LEA DI, DES_STR+6 MOV CX, 7 L10: LODSB MOV [DI], AL DEC DI LOOP L10

57 STOB Store byte in AL into ES:[DI]. Update DI. Algorithm: ES:[DI] = AL
if DF = 0 then DI = DI + 1 else DI = DI - 1

58 Example LEA DI, a1 MOV AL, 12h MOV CX, 5 REP STOSB

59 COMPSB Compare bytes: ES:[DI] from DS:[SI]. DS:[SI] - ES:[DI]
set flags according to result: OF, SF, ZF, AF, PF, CF if DF = 0 then SI = SI + 1 DI = DI + 1 else SI = SI - 1 DI = DI - 1

60 Lab/Practice 1. Open your browser and open this page:
C:\emu8086\documentation\8086_instruction_set.html And C:\emu8086\documentation\8086_and_dos_interrupts.html 2. Open your emu8086 software 3. Cut and paste (or type) the following code (as shown in the next page) and save reverse.asm

61 page 60,132 TITLE StringPractice StringReverse ; STACK SEGMENT PARA STACK 'Stack' DW DUP(0) STACK ENDS ; DATASEG SEGMENT PARA 'Data' ; Please insert your data declaration here DATASEG ENDS CODESEG SEGMENT PARA 'Code' MAIN PROC FAR MOV AX, DATASEG MOV DS, AX MOV ES, AX ; Please enter your code here MOV AX,4C00H ;exit procedure INT 21H MAIN ENDP CODESEG ENDS END MAIN ;End of program

62 Lab/Practice 4. Insert the code to:
- Read a string from keyboard (INT 21H, 0AH). Max typed characters = 50 - Reverse that string using the string operations learned today. (see code for reversing a string) 5. Compile and run the code


Download ppt "Direct video practice and Keyboard Operations"

Similar presentations


Ads by Google