620 likes | 763 Views
Direct video practice and Keyboard Operations. Midterm. Avg: 182/195 (93%). Midterm. 1.1. For the data bits 01001001, the parity bit is (a) 0 (b) 1 (c) irrelevant (d) unknown. Midterm. 1.2. The data segment contains (a) read-only memory,
E N D
Midterm • Avg: 182/195 (93%)
Midterm 1.1. For the data bits 01001001, the parity bit is (a) 0 (b) 1 (c) irrelevant (d) unknown
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.
Midterm 1.3. The binary representation for decimal 117 is a. 01110101 c. 01111011 b. 01110011 d. 01100101
Midterm 1.5 Which of the following is an invalid name? a. _hello b. #hello c. $hello d. hello
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
Midterm 1.7. INT 21H function 09H for displaying requires defining a display string in the data area, immediately followed by this character: (a) @ (b) & (c) $ (d) _
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
Midterm 1.9 Identify the following colors in the attribute byte 00000001: (a) Blue foreground and black background (b) Blue foreground and white background (c) White foreground and blue background (d) Black foreground and blue background
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.
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.
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______________________.
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
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.
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.
Midterm III. 1. • SS: 2A600H + 100H 2A700H -> SS: 2A70H • CS: 2A600H + 100H 30H 40H 2A770H -> CS: 2A77H
Midterm III. 1. c. ES: 2A60H d. SP: 0030H
Midterm III. 2 a. b. 3412H + 011AH = 352CH BL BH 34H 12H BL BH 35H 2CH
Midterm III. 2 c. 0135 0134 2CH 35H
Midterm 3. WORD3: 10*30 = 300 4. CX = 5 AX = 10 CX = 4 AX = 20 CX = 3 AX = 30 CX = 2 AX = 40 CX = 1 AX = 50
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
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
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
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
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
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
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
page 60,132 TITLE VideoPractice DirectDisplay ; --------------------------------------------- STACK SEGMENT PARA STACK 'Stack' DW 32 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
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:
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
Lesson plan • Brief go over keyboard operations • Focus on String operation
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
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
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 INT 21H CMP AL, 00H JE PRINTLABEL JMP CONT PRINTLABEL: ………….. CONT:……
INT 21H • Function 0Ch - flush keyboard buffer and read standard input.Example: MOV AH, 0CH MOV AL, 07H INT 21H
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
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.
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.
INT 16H operations for keyboard • INT 16H is the basic BIOS keyboard operation used extensively by software developers
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
Example MOV AH, 00H INT 16H CMP AL,'c' JE PRINTPROMPT JMP CONT PRINTPROMPT: ……… CONT:
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).
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
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
String operations • Don’t forget to initialize the DS and ES by: • MOV AX, DATASEG • MOV DS, AX • MOV ES, AX
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