Experiment 3 3 Basic Input Output

Similar documents
Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات

Experiment #5. Using BIOS Services and DOS functions Part 1: Text-based Graphics

EEM336 Microprocessors I. Data Movement Instructions

db "Please enter up to 256 characters (press Enter Key to finish): ",0dh,0ah,'$'

Assembly Language: g Part III. First Semester 2013 Department of Computer Science Faculty of Science Chiang Mai University

.code. lea dx,msg2. Page 1/8. Problem 1: Programming in Assembly [25 Points]

Experiment N o 3 Segmentation and Addressing Modes

Video processing The INT instruction enables program to interrupt its own processing. Use INT instruction to handle inputs and outputs

Lecture 13: I/O I/O. Interrupts. How?

Experiment N o 3. Segmentation and Addressing Modes

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

Code segment Stack segment

Assembling, Linking and Executing 1) Assembling: .obj obj .obj.lst .crf Assembler Types: a) One pass assembler:

Intel 8086: Instruction Set

Computer Architecture and System Software Lecture 07: Assembly Language Programming

ELEC 242 Using Library Procedures

Assembly Language Lab # 9

Computer Architecture and System Software Lecture 06: Assembly Language Programming

Programming in Assembler. Laboratory manual. Exercise 3

Transfer of Control. Lecture 10 JMP. JMP Formats. Jump Loop Homework 3 Outputting prompts Reading single characters

COE 205 Lab Manual Experiment N o 12. Experiment N o Using the Mouse

SHEET-2 ANSWERS. [1] Rewrite Program 2-3 to transfer one word at a time instead of one byte.

Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)

Experiment N o 1. 1 Introduction to Assembly Language Programming

CS-202 Microprocessor and Assembly Language

ELEC VIDEO BIOS ROUTINES

ADVANCE MICROPROCESSOR & INTERFACING

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Come and join us at WebLyceum

Chapter Three Addressing Mode MOV AX, BX

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

Experiment 8 8 Subroutine Handling Instructions and Macros

Lecture 16: Passing Parameters on the Stack. Push Examples. Pop Examples. CALL and RET

FACULTY OF ENGINEERING LAB SHEET

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

Data Transfers, Addressing, and Arithmetic. Part 2

Mr. Sapan Naik 1. Babu Madhav Institute of Information Technology, UTU

Constants and Expressions. Lecture 7: Assembly Language Programs. Constants and Expressions (cont.) Statements. Names. Assembly Directives

Experiment #2. Addressing Modes and Data Transfer using TASM

Experiment N o 8. String Handling Instructions

PESIT Bangalore South Campus

mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Q1: Define a character string named CO_NAME containing "Internet Services" as a constant?

FACULTY OF ENGINEERING LAB SHEET

Lesson 1. Fundamentals of assembly language

EC 333 Microprocessor and Interfacing Techniques (3+1)

Chapter 3: Addressing Modes

CONTENTS. 1. Display a Message Display a one Digit Number Accept a Character from keyboard and display the character 4

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

Computer Architecture 1 ح 303

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Basic Assembly SYSC-3006

ORG ; TWO. Assembly Language Programming

Basic characteristics & features of 8086 Microprocessor Dr. M. Hebaishy

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000

Assembly Language Each statement in an assembly language program consists of four parts or fields.

Constants and. Lecture 7: Assembly Language Programs. Expressions (cont.) Constants and. Statements. Expressions

EXPERIMENT TWELVE: USING DISK FILES

ECpE 185 Laboratory Hand Assembly Fall 2006

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

Introduction to IA-32. Jo, Heeseung

LABORATORY 8: USING BIOS ROUTINES FOR KEYBOARD INPUT AND DISPLAY OUTPUT

2003 LXI H, 42F2H ; this instruction store 42F2 in to the HL pair POP H ; store data from top of the stack to HL pair

Kingdom of Saudi Arabia Ministry of Higher Education. Taif University. Faculty of Computers & Information Systems

Hardware and Software Architecture. Chapter 2

INTRODUCTION TO IA-32. Jo, Heeseung

EC-333 Microprocessor and Interfacing Techniques

EE2007 Microprocessor systems.

CS401 Assembly Language Solved MCQS From Midterm Papers

CSE 505 Lecture 8: Introduction to Assembly Language

INT 21H and INT 10H Programming and Macros

The registers(di,si) are automatically incremented or decremented depending on the value of the direction flag:

Addressing Modes on the x86

Q. State and Explain steps involved in program development. [w-08, w-10, s-12, w-11]

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

ELEC 242 Time Delay Procedure

INTRODUCTION. NOTE Some symbols used in this manual CL = Click Left CR = Click Right DCL = Double Click Left = Enter. Page 1

Babu Madhav Institute of Information Technology, UTU

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

Week /8086 Microprocessor Programming I

Philadelphia University Student Name: Student Number:

16-bit MS-DOS and BIOS Programming

Q1: Define a character string named CO_NAME containing "Internet Services" as a constant?

THE UNIVERSITY OF TRINIDAD & TOBAGO

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

EXPERIMENT NINE DEVELOPING MACRO SEQUENCES

Assignment 3. Problem Definition:

Assembly Language. Dr. Esam Al_Qaralleh CE Department Princess Sumaya University for Technology. Overview of Assembly Language

CG2007 Microprocessor systems.

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

UNIVERSITY OF CALIFORNIA, RIVERSIDE

The x86 Architecture

Program controlled semiconductor device (IC) which fetches (from memory), decodes and executes instructions.

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans.

if 2 16bit operands multiplied the result will be

The statement above assumes that the PCMAC.INC file is in the current directory. The full path of the file can also be given:

EC 333 Microprocessor and Interfacing Techniques (3+1)

Assignment no:4 on chapter no :3 : Instruction set of 8086

Transcription:

Experiment 3 3 Basic Input Output Introduction The aim of this experiment is to introduce the use of input/output through the DOS interrupt. Objectives: INT Instruction Keyboard access using DOS function calls 01, 02 and 08. OFFSET operator String reading and display using the DOS function call 09and 0AH Some basic assembly instructions 3.1 The INT Instruction You might have noticed in the first experiments that we made use of to exit the program. In fact, is a built in program available as part of the BIOS. This built in program can perform a multitude of functions. However, is not the only available interrupt. There are over 50 different interrupts available when using DOS. Of these, the programmer will only use a few. Each interrupt though, has a number of functions which select the individual task that the function has to do. The INT instruction calls a DOS interrupt (like a function) to perform a special task. For example, there is just one interrupt for accessing the mouse INT 33h, but there are separate functions available to see if a button has been clicked, to see how far the mouse has moved, to display or hide a mouse pointer etc. Example: From table 3.1 it can be seen that interrupt 21h function 02, outputs a character on the screen. So to output the character "!" on the screen, use the following code: MOV AH,02 ; To select function 2, move the number 2 to AH MOV DL,"!" ; Move character to output in DL INT 21h ; Finally when all registers are set the interrupt is called Function 4CH is the function which terminates the program and returns the user to the operating system. 1

3.2 Basic Input Output The following table summarizes the main I/O functions used through. These functions are mainly used to read a character or a string from the keyboard, which could stand for input data to a program, and display characters or strings, which also could be results, or an output, of a program. Input and output can only be a character or a string. Function Input in Output in Effect 01H AH AL Reads a character with echo on the screen. 02H / 06H AH, Character in DL No output Displays a character on the screen 08H AH AL Reads a character without echo. 09H AH No output Displays a string terminated by a $ sign 0AH AH Offset in DX Reads a string of characters from the keyboard Table 3.1: Simple I/O DOS function calls 3.2.1 Character Input Output Functions 3.2.1.1 Displaying a Character DOS functions 02 and 06 are used for a single character display. Function 09 is used to display a string. Both functions, 02 and 06, are identical except that function 02 can be interrupted by a control break (Ctrl-Break), while function 06 cannot. To display a single character ASCII character at the current cursor position, use the following sequence of instructions: MOV AH, 06H ;(Or: MOV AH, 02H) MOV DL, Character Code The Character Code may be the ASCII code of the character taken from the ASCII table or the character itself written between single quotes. The following displays the number 2 using its ASCII code: MOV AH, 06H MOV DL, 32H ; or MOV DL, 2 2

3.2.1.2 Reading a Character These include reading a single character with or without echo preformed respectively by functions 01 and 08. Function 01H To read single character and have it echoed, or displayed, on the screen, use the following code: MOV AH, 01H After this code, AL contains now the ASCII code of the character read from the keyboard. Function 08H If the character is to be read without echo, such as reading a password, use the following code: MOV AH, 08H AL contains now the ASCII code of the character read 3.2.2 Dealing with Strings Dealing with strings is done through functions 09 and 0AH, respectively for displaying and reading. However, we need to introduce a few useful tools before getting to write programs that deal with strings. - The Offset Operator - LEA Instruction - Array Indexing - Keyboard Buffer declaration 3.2.2.1 The Offset Operator The offset operator returns the number of bytes between the label and the beginning of its segment, or its effective address. Since it produces a 16-bit immediate value, the destination must be a 16-bit operand. The statement: offset label, returns the offset address portion of label, which can be saved in a 16-bit register or memory location. Examples 1. After executing the following instruction, MOV BX, OFFSET COUNT ; Let BX point to count 3

the BX register contains the address of the variable count. BX may thus be used as a pointer to the count variable. 2. The following example illustrates the use of the OFFSET operator: BLIST DB 10H, 20H, 30H, 40H WLIST DW 1000H, 2000H, 3000H MOV DI, OFFSET BLIST ; DI = 0000 MOV BX, OFFSET BLIST+1 ; BX = 0001 MOV SI, OFFSET WLIST+2 ; SI = 0006 3.2.2.2 The LEA Instruction The MOV instruction when dealing with Offsets, as in the above examples, may be replaced by the following instruction: LEA BX, COUNT ; equivalent to MOV BX, Offset COUNT 3.2.2.3 Array Indexing When dealing with strings, we often need to access specific items within the string. Therefore, some sort of indexing is necessary. Strings are considered as arrays indexed starting from 0. To access the N th character in the string KeybBuf, use KeybBuf [N-1] Usually the BX register is used as an index, and helps accessing a specific character within a string: MOV BX, Position ; Position could be a number MOV AL, KeybBuffer[BX] 3.2.2.4 String Display Function Function 09 is used to display a string of characters ended with a $ sign. The following code displays the string MESSAGE defined as: MESSAGE DB This is the Message to be displayed, $ LEA DX, MESSAGE MOV AH, 09H ; or MOV DX, OFFSET MESSAGE 4

A. Reading a String Reading a string is accomplished by function 0AH. This function accepts a string of text entered at the keyboard and copies that string into a memory buffer. Function 0AH is invoked with DX pointing to an input buffer, whose size should be at least three bytes longer than the largest input string anticipated. String Declaration Strings, like arrays, are declared using the DUP operator. To declare an array MyStr of 20 bytes: MyStr DB 20 DUP (?) Keyboard Buffer Declaration Before invoking function 0AH, you must set the first byte of the buffer with the maximum number of characters to be expected in the buffer. After returning from function 0AH, the second byte of the buffer will contain the number of characters actually read form the keyboard (Table 3.3). Buffer Length Actual Length Figure 3.1: Keyboard buffer structure Function 0AH Entry Exit Read from Keyboard AH = 0AH ; DX = address of keyboard input buffer First byte of buffer contains the size of the buffer (up to 255) Second byte of buffer contains the number of characters read. Reading operation continues until buffer full, or a carriage return (CR = 0DH) is typed. Table 3. 2: Functions 0AH of DOS interrupt Example This example shows the use of function 0AH. The user is supposed to enter the word hello. We prepare a buffer to enter a string of maximum 10 characters. Buffer: KeybBuffer DB 11, 12 DUP (?) 11???????????? The first number (11) indicates the length of the buffer including the Carriage return key entered after the string. 5

Code: Input: LEA DX, KeybBuffer MOV AH, 0AH The user enters through the keyboard the word hello Output: 11 05 68 65 6C 6C 6F 0D????? - Bold characters are returned by function 0Ah - The second number (05) indicates the number of characters effectively read from the keyboard. - The eighth number (0Dh) corresponding to the carriage return is not shown on the screen. 3.3 Some Basic Assembly Instructions 3.3.1.1 The LOOP instruction In this experiment, the FOR loop equivalent in assembly language is introduced. The LOOP instruction uses the CX register as a counter. Syntax: Effect: MOV CX, Count next:..... LOOP next - decrements CX but does not change any flags - if CX is not zero after the decrement, control is transferred to the destination label - This is a SHORT jump only 3.3.1.2 The Unconditional Jump This is mainly used to perform unconditional jumps such as infinite loops. The syntax is: here:..... JMP here 6

3.4 Lab Work 3.4.1 Part I Write and test the following programs. Program 1 ; This program displays the characters A B C, using function 02..MODEL SMALL.STACK 200 X EQU B Y DB 43H MOV AX, @DATA MOV DS, AX ; Assume Data Segment MOV AH, 02 ; Load Function 02 MOV DL, A ; Load Character To Be Displayed ; Call Interrupt 21h MOV DL, X MOV DL, Y ; Load Character To Be Displayed ; Call Interrupt 21h ; Load Character To Be Displayed ; Call Interrupt 21h MOV AH, 4CH ; Exit to DOS END Program 2 ; This program displays a string terminated by a $ sign using function 09H..MODEL SMALL MESSAGE DB This is the message to be displayed, $.STACK 200 MOV AX, @DATA MOV DS, AX MOV DX, OFFSET MESSAGE MOV AH, 09H.EXIT END 7

Program 3.MODEL SMALL.STACK 200 MESSAGE DB Enter a character:, $ MESSAGE2 DB The character you typed is:, 0DH, 0AH, $.STARTUP LEA DX, MESSAGE MOV AH, 09H ; Display message MOV AH, 02 ; Function 02H, display character MOV DL, AL ; Load character to be displayed ; LEA DX, MESSAGE MOV AH, 09H MOV AH, 08H ; Function read character without echo. ; Character read is returned in AL register. No echo on the display. MOV BL, AL ;Save character read in BL register LEA DX, MESSAGE2 MOV AH, 09H ;Display MESSAGE2 MOV AH, 02 ; Function 02H, display character MOV DL, BL ; Load character to be displayed from BL.EXIT END 3.4.2 Part II 1. Write a program that displays a string on the screen then asks the user to enter a number between 1 and 9. The program should then display the character whose position is indicated by the number entered by the user. 2. Write a program that reads a string from the keyboard then displays the string back on the screen together with the number of characters in the string. 3. Write a program that reads a string from the keyboard, reverses the string, then displays it back on the screen. 8