21/11/2005CAP2411 Input & Output Instructions CPU communicates with the peripherals through I/O registers called I/O ports. There are 2 instructions, IN.

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

ICS312 Set 6 Operands. Basic Operand Types (1) Register Operands. An operand that refers to a register. MOV AX, BX ; moves contents of register BX to.
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Direct video practice and Keyboard Operations
Assembly Language for Intel-Based Computers Chapter 15: BIOS-Level Programming (c) Pearson Education, All rights reserved. You may modify and.
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.
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
8.4 Instruction Execution Times TOBIN PROC FAR SUB AX,AX MOV DX,AX MOV CX,4 NEXTD: PUSH CX SUB BP,BP MOV CX,4 GETNUM: RCL BX,1 RCL BP,1 LOOP GETNUM.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
BR 6/001 Ways to Handle I/O (Input/Ouput) For Output –Use Irvine16 Functions Writechar, WriteBin, WriteInt, Writehex, Writestring –Use DOS (Int 21h) Functions.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#6)
Assembly Programming Timothy C. Rice Jr., MIT. OUTLINE Basic Structure Exit to Dos Print Character Clear Screen Change BG & FG Color Set Curser Location.
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.
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.
Topics Control Flow Structure – Conditional Jump – Unconditional Jump Control Flow Structures – IF-THEN – IF-THEN-ELSE – CASE Branches with Compound Conditions.
Computer Systems 1 Fundamentals of Computing Von Neumann & Fetch Execute Cycle.
ORG ; FOUR INT 21H and INT 10H Programming and Macros Dec Hex Bin
Lecture 11 Last notes on interrupts and exam review Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
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.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
Computer Platforms Week 4: Assembly Language & Operating Systems.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
The x86 PC Assembly Language, Design, and Interfacing By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey © 2010, 2003, 2000, 1998 Pearson.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
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 Screen and Keyboard Operations Suthida Chaichomchuen
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
Lecture 4 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Overview of Assembly Language Chapter 4 S. Dandamudi.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
“It was the night before midterm”. Midterm rule (March 16 nd, 2005) - Student ID is required. Open books, note exam - Don’t: - Leave the exam room after.
Binary Number Output To display a number in binary format, a program looks at each bit in the number and sends the ASCII equivalent of a ‘1’ (31h) or a.
Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
8086 Microprocessor Interrupts By: Vijay Kumar. K Reference From Slide Share.
Software Interrupt Instruction ‘int’ A ‘int’ instruction is like a special kind of subroutine call. Will discuss details later ‘int’ stands for INTERRUPT.
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:
In Class Program Write, assemble and test a program: –Use the DB directive to define the following list of numbers and name it array: 31h, 32h, 33h, 34h.
Microprocessors Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Assembly Language Lecture 2. Lecture Outline Program Structure Memory models Data Segment Stack Segment Code Segment Input and Output Instructions INT.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
Program Structure Example for Data Segment CRLF EQU 0DH, 0AH PROMPT DB 'Enter a digit between 0 and 9', 0 VAR1 DB ? ARRAY DW 1234h, 23h, 0FF54h.
Stack Operations Dr. Hadi AL Saadi.
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A.
Additional Assembly Programming Concepts
Lecture 4 Control Flow Structures (LOOPS)
Microprocessor and Assembly Language
Computer Organization & Assembly Language
(The Stack and Procedures)
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Stack and Subroutines Module M17.1 Section 11.2.
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
(The Stack and Procedures)
Symbolic Instruction and Addressing
Unit:08 Software Interrupts
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Assembler Directives end label end of program, label is entry point
High-level language structures
Chapter 6 –Symbolic Instruction and Addressing
(The Stack and Procedures)
By Nasser Halasa Assembly Language.
Presentation transcript:

21/11/2005CAP2411 Input & Output Instructions CPU communicates with the peripherals through I/O registers called I/O ports. There are 2 instructions, IN & OUT, that access the ports directly. These instructions are used when fast I/O is essential ……. in a game program.

21/11/2005CAP2412 IN & OUT Most application programs do not use IN and OUT instructions. Why? 1) port addresses vary among computer models 2) easier to program I/O with service routines

21/11/2005CAP categories of I/O service routine 1.The BIOS routines. 2. The DOS routines.

21/11/2005CAP2414 BIOS routines Are stored in ROM and interact directly with I/O ports. Used to carry basic screen operations such as moving the cursor & scrolling the screen.

21/11/2005CAP2415 DOS routines Can carry out more complex tasks. Printing a character string…. They use the BIOS routines to perform direct I/O operations.

21/11/2005CAP2416 The INT Instruction. To invoke a DOS or BIOS routine, the INT (interrupt) instruction is used. FORMAT INTinterrupt_number is a number that specifies a routine.

21/11/2005CAP2417 Example INT16h invokes a BIOS routine that performs keyboard input. We will use a particular DOS routine INT 21h

21/11/2005CAP2418 INT 21h Used to invoke a large number of DOS functions. Put the function number in AH register and then invoke INT21h

21/11/2005CAP2419 FUNCTIONS Function numberRoutines 1 single-key input 2 single-character output 9 character string output

21/11/2005CAP24110 INT 21h functions Input values are to be in certain registers & return output values in other registers.

21/11/2005CAP24111 Function 1 Single-Key Input Input : AH = 1 Output :AL = ASCII code if character key is pressed. = o if non-character is pressed.

21/11/2005CAP24112 Example MOVAH,1 ; input key function INT21h ; ASCII code in AL

21/11/2005CAP24113 Example If character k is pressed, AL gets its ASCII code; the character is also displayed on the screen If Arrow key or F1-F10, AL will contain 0 The instructions following the INT21h can examine AL and take appropriate action.

21/11/2005CAP24114 Function 2 INT21h, function 1 …. doesn’t prompt the user for input, he might not know whether the computer is waiting for input or it is occupied by some computation. Function 2 can be used to prompt the user

21/11/2005CAP24115 Function 2 Display a character or execute a control function Input : AH = 2 DL = ASCII code for the display character or control character Output :AL = ASCII code of the display character or control character

21/11/2005CAP24116 Example MOVAH,2 ; display character function MOVDL, ‘?’ ; character is ‘?’ INT21h ; display character After the character is displayed, the cursor advances to the next position on the line.

21/11/2005CAP24117 Control functions Function 2 may also be used to perform control functions. If DL contains the ASCII code of a control character, INT21h causes the control function to be performed.

21/11/2005CAP24118 Control functions ASCII code (hex) SymbolFunction 7 BELbeep 8BSbackspace 9HTtab ALFline feed (new line) DCRcarriage return (start of current line)

21/11/2005CAP24119 A First Program Read a character and display it at the beginning of the next line 1-We start by displaying a question mark: MOV AH,2 ; display character function MOV DL,'?‘ ; character is ‘?’ INT 21H ; display character Move 3Fh, the ASCII code for “?”, into DL

21/11/2005CAP24120 Read a character MOV AH,1 ; read character function INT 21H ; character in AL

21/11/2005CAP24121 Display the character on next line First, the character must be saved in another register. MOVBL, AL; save it in BL This because the INT 21h, function 2, changes AL

21/11/2005CAP24122 Display the character on next line -Move cursor to the beginning of the next line: Execute carriage return & line feed. Put their ASCII codes in DL & execute INT 21h.

21/11/2005CAP24123 Move cursor to the beginning of the next line MOVAH, 2 ; display character function MOVDL, 0Dh ; carriage return INT 21h ; execute carriage return MOVDL, 0Ah ; line feed INT21h ; execute line feed

21/11/2005CAP24124 Display the character MOVDL, BL ; get character INT 21h ; and display it

21/11/2005CAP24125 Program Listing TITLE PGM4_1 : Echo PROGRAM.MODEL SMALL.STACK 100H.CODE MAIN PROC ;display prompt MOV AH,2 MOV DL,'?' INT 21H ; input a character MOV AH,1 INT 21H MOV BL,AL ; go to a new line MOV AH,2 MOV DL,0DH INT 21H MOV DL,0AH INT 21H ; display characters MOV DL,BL INT 21H ; return to DOS MOV AH,4CH INT 21H MAIN ENDP END MAIN

21/11/2005CAP24126 When a program terminates, it should return control to DOS MOV AH,4CH; DOS exit function INT 21H; exit to DOS

21/11/2005CAP24127 Displaying a string INT 21h, Function 9: Display a string Input : DX = offset address of string. The string must end with a ‘$’ character.

21/11/2005CAP24128 If the string contains the ASCII code of a control character, the control function is performed.

21/11/2005CAP24129 Example Print HELLO! on the screen. MSGDB ‘HELLO!$’

21/11/2005CAP24130 The LEA instruction INT 21h, function 9, expects the offset address of the character string to be in DX. To get it there, we use LEAdestination, source

21/11/2005CAP24131 LEAdestination, source LEA ….. Load Effective Address Destination … is a general register. Source ………… is a memory location. It puts a copy of the source offset address into destination.

21/11/2005CAP24132 Example MSGDB ‘HELLO!$’ LEADX, MSG ; puts the offset ;address of variable ; MSG in DX This example contains data segments initialize DS.

21/11/2005CAP24133 Program Segment Prefix When a program is loaded in memory, DOS prefaces it with PSP. The PSP contains information about program. DOS places in DS & ES segment # of PSP. DS must be loaded with the segment # of data segment

21/11/2005CAP24134 DS initialization A program containing a data segment begins with: is the name of the data segment defined by.DATA. It is translated into a segment #.

21/11/2005CAP24135 Print the message With DS initialized, we may print the “HELLO!” message: LEADX,MSG;get message MOVAH,9;display string function INT21h;display string

21/11/2005CAP24136 TITLE PGM4-2: PRINT STRING PROGRAM ; This program displays “Hello!”.MODEL SMALL.STACK 100H program title (comment) comment line memory model: small programs use at most 64K code and 64K data set the stack size Sample Program directive giving title for printed listings

21/11/2005CAP24137 Sample Program.DATA MSG DB “HELLO!”,0DH,0AH,’$’.CODE MAIN PROC MOV MOV DS,AX;initialize DS LEA DX,MSG;get message MOV AH,9;display string function INT 21H;display message MOV AH,4CH INT 21H;DOS exit MAIN ENDP END MAIN starts the data segment where variables are stored starts the code segment reserve room for some bytes variable name carriage return and line feed Declares the beginning of the procedure which is called main marks the end of the current procedure marks the end of the program. “main” specifies the program execution is to begin with the procedure “main”

21/11/2005CAP24138 Sample execution: A> PGM4_2 HELLO!

21/11/2005CAP24139 Case Conversion Program ENTER A LOWER CASE LETTER : a IN UPPER CASE IT IS : A

21/11/2005CAP24140 Case Conversion Program Use EQU to define CR & LF as names for the constants 0DH & 0AH. CREQU0DH LFEQU0AH

21/11/2005CAP24141 The messages and input character can be stored in the Data Segment like this: MSG1DB 'ENTER A LOWER CASE LETTER : $‘ MSG2DB CR,LF, 'IN UPPER CASE IT IS : ‘ CHARDB ?,'$'

21/11/2005CAP24142 Our program begins by displaying the first message and reading the character: LEADX,MSG1 ; get first message MOV AH,9 ; display string function INT21H ;display first message MOV AH,1 ; read character function INT21H ; read a small letter into AL

21/11/2005CAP24143 Convert to upper case SUB AL,20H ; convert into uppercase MOV CHAR,AL ; and store it

21/11/2005CAP24144 Display second message & uppercase LEA DX,MSG2 ; get second message MOV AH,9 ; display string function INT 21H ; display message & uppercase letter

21/11/2005CAP24145 Program Listing

21/11/2005CAP24146.MODEL SMALL.STACK 100H.DATA CREQU0DH LFEQU0AH MSG1DB 'ENTER A LOWER CASE LETTER : $' MSG2DB CR,LF,'IN UPPER CASE IT IS : ' CHARDB ?,'$'.CODE MAIN PROC ; initialize DS MOV MOV DS,AX ;print user prompt LEA DX,MSG1 MOV AH,9 INT 21H ; input a character and convert to upper case MOV AH,1 INT 21H SUB AL,20H MOV CHAR,AL ; display on the next line LEA DX,MSG2 MOV AH,9 INT 21H ; return TO DOS MOV AH,4CH INT 21H MAIN ENDP END MAIN