Direct video practice and Keyboard Operations

Slides:



Advertisements
Similar presentations
DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
Advertisements

There are two types of addressing schemes:
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
Video systems (continue). Practice Modify the program to get a string from a keyboard to display the input string on the middle of the screen with reverse.
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
Chapter 7 Programming with DOS and BIOS Function Calls Objectives: The use of DOS and BIOS function call How to read the PC’s keyboard How to send text.
8-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Kip Irvine: Assembly Language for Intel-Based Computers
Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.
Fundamentals of Assembly language
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Lab 5 Part C Write to the screen a character string that uses a ‘$’ to indicate the end of the string. Do not write the ‘$’ to the screen. Use DOS Interrupt.
ORG ; FOUR INT 21H and INT 10H Programming and Macros Dec Hex Bin
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
3.7 String Instructions Specifying the Operands’ Size and Address and the String Direction STRING = a data collection in memory. String ELEMENTS can be:
BIOS and DOS Programming in DOS INT 10 and 21H. Interrupts There are some extremely useful subroutines within BIOS or DOS that are available to the user.
1 Fundamental of Computer Suthida Chaichomchuen : SCC
Faculty of Engineering, Electrical Department,
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
Strings, Procedures and Macros
Executing and Linking an assembly program. Lesson plan Review Program logic and control Practice exercise Assembling, Linking and Executing Programs Practice.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
ICS312 Lecture13 String Instructions.
Processing String Data and Binary Data (continue)
Click to add Title Comunicación y Gerencia Click To add Subtitle Click to add Text Fundamentals of Assembly Language.
10H Interrupt. Option 0H – Sets video mode. Registers used: – AH = 0H – AL = Video Mode. 3H - CGA Color text of 80X25 7H - Monochrome text of 80X25 Ex:
String Instructions String instructions were designed to operate on large data structures. The SI and DI registers are used as pointers to the data structures.
EEL 3801 Part IV The Assembler. OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of.
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
Review of Assembly language. Recalling main concepts.
Microprocessors Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Control Structure vs. Assembly Language NASM. If-then-else If conditional then then_actions jump to endif else else_actions endif.
Khaled A. Al-Utaibi  Introduction  The MOV Instruction  The LEA Instruction  The Stack Instructions  The String Data Transfer.
Lecture 11 Text mode video
Lecture 6 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
BITS Pilani Pilani Campus Pawan Sharma Lecture /12/ EEE /INSTR/CS F241 ES C263 Microprocessor Programming and Interfacing.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
Chapter 8 String Operations. 8.1 Using String Instructions.
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
Format of Assembly language
Chapter Nov-2010
BYTE AND STRING MANIPULATON
Additional Assembly Programming Concepts
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
EE3541 Introduction to Microprocessors
Microprocessor and Assembly Language
INSTRUCTION SET.
Assembly Language Programming Part 2
ADDRESSING MODES.
(The Stack and Procedures)
9/17/2018 Kiến Trúc Máy Tính.
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Introduction to Assembly Language
Chapter 4 Data Movement Instructions
Lecture 1 Instruction set of 8086 Лектор: Люличева И.А. 1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
CS 301 Fall 2002 Computer Organization
(The Stack and Procedures)
Symbolic Instruction and Addressing
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Unit:08 Software Interrupts
Chapter 6 –Symbolic Instruction and Addressing
(The Stack and Procedures)
By Nasser Halasa Assembly Language.
Chapter 8: Instruction Set 8086 CPU Architecture
Presentation transcript:

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, (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

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

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

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

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

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

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

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

END MAIN ;End of program 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 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 ……… 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).

String operations

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

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

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

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

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

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

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

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

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

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

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

page 60,132 TITLE StringPractice StringReverse ; --------------------------------------------- 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, 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

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