Lecture 04 Input and Output with Assembly PDF
Document Details
Uploaded by HumaneBarbizonSchool3912
Taibah University
Dr Hassanein Shaban Ahmed
Tags
Related
- Assembly Language Programming I: Introduction PDF
- Assembly Language Programming Lecture 7 PDF
- Chapter 6_1_Elements_of_Assembly_Language.pdf
- Assembly Language Programming ACSL PDF
- Project Proposal: Implementing a Bubble Sort Algorithm in Assembly Language (PDF)
- Lecture 02 Introduction to Assembly Language PDF
Summary
This document is a lecture on input and output with assembly language. It covers foundational concepts, examples and exercises. It's aimed at an undergraduate computer science course.
Full Transcript
Input and Output Instructions 1. The CPU communicates with the peripherals through I/O registers called I/O ports. Two instructions IN and OUT that access the ports directly for fast applications. 2. Most application programs do not use IN and OUT because: Port addresses vary among...
Input and Output Instructions 1. The CPU communicates with the peripherals through I/O registers called I/O ports. Two instructions IN and OUT that access the ports directly for fast applications. 2. Most application programs do not use IN and OUT because: Port addresses vary among computer models It’s much easier to program I/O with the service routines 3. There are two categories of I/O service routines The basic Input/Output System BIOS routines “stored in ROM” The DOS routines 4. To call a DOS or BIOS routine, the INT (interrupt) instruction is sued 2 Dr. Hassanein Shaban Ahmed Chapter 4 1- Introduction To read or print a character you can simply call an interrupt. There are also interrupt functions that work with disk drive and other hardware. To make an interrupt there is an INT instruction. Syntax : INT value value is the code of interrupt and can be a number between 0 and FFh. Each number correspond to a function (code of interrupt). And each interrupt may have sub-functions. To specify a sub-function, AH register should be set by the function number before calling interrupt. Chapter 4 Dr Hassanein Shaban Ahmed 3 2- Read a character To read a character use the following interrupt: INT 21h and AH = 01h. Input character is stored in AL. Example: MOV AH, 01h INT 21h Chapter 4 Dr Hassanein Shaban Ahmed 4 3- Write a character To print a character use the following interrupt: INT 21h and AH = 02h. DL = character to write, after execution AL = DL. Example: MOV AH, 2 MOV DL, 'T' INT 21h. Chapter 4 Dr Hassanein Shaban Ahmed 5 Exercise: Write a program that reads a character and then prints it. Note :.model small We do not use.data because.stack 100h there is no variables defined.code Main proc MOV AH, 01 INT 21h MOV DL, AL MOV AH, 02 INT 21h MOV AH,4CH INT 21 Main endp END main Chapter 4 Dr Hassanein Shaban Ahmed 6 Exercise: Change the previous program to read a string of 3 characters and then to print it..Model small MOV AH, 02h.Stack 100h MOV DL, BL.Code INT 21h Main proc MOV AH, 01h MOV DL, BH INT 21h INT 21h MOV BL,AL MOV DL, CL INT 21h INT 21h MOV BH,AL Mov AH,4Ch; exit to DOS Int 21h INT 21h Main endp MOV CL,AL End main ; stops the program Dr Hassanein Shaban Ahmed 7 Chapter 4 4- Terminating a program To return to dos we use int 21h with function 4Ch. i.e AH=4Ch. MOV AH,4ch Int 21h Chapter 4 Dr Hassanein Shaban Ahmed 8