25
PROGRAMMING THE MICROPROCESSOR 03/25/22 1 Programming the Microprocessor Using Keyboard and Video Display Data Conversions Disk files

Lecture 13 (Keyboard, Display,Data Conversion,File Handling)

Embed Size (px)

DESCRIPTION

44444444444444444444

Citation preview

PROGRAMMING THE MICROPROCESSOR

04/19/23 1

Programming the Microprocessor

• Using Keyboard and Video Display• Data Conversions• Disk files

PROGRAMMING THE MICROPROCESSOR

04/19/23 2

MS-DOS Memory Organization• Interrupt Vector Table• BIOS & DOS data• Software BIOS• MS-DOS kernel• Resident command processor• Transient programs• Video graphics & text• Reserved (device controllers)• ROM BIOS

PROGRAMMING THE MICROPROCESSOR

04/19/23 3

MS-DOS MEMORY MAP

Interrupt vectors

BIOS communication area

DOS communication area

IO.SYS program

MSDOS program

Device drivers such as MOUSE.SYS

COMMAND.COM

Free TPA

MS DOS program9FFFF

9FFF0

08E30

08490

02530

01160

00700

00500

00400

00000

FFFFF

F0000

E0000

C8000

C0000

B0000

A0000

Video RAM (text)

Free area

Hard disk controller ROM

LAN controller ROM

BASIC language ROM

BIOS system ROM

Video BIOS ROM

Video RAM(Graphics)

System area

Transient Program area

REAL MEMORY

PROGRAMMING THE MICROPROCESSOR

04/19/23 4

INT Instruction• The INT instruction executes a software interrupt.• The code that handles the interrupt is called an

interrupt handler.• Syntax:

INT number

(number = 0..FFh)

The Interrupt Vector Table (IVT) holds a 32-bit segment-offset address for each possible interrupt handler.

Interrupt Service Routine (ISR) is another name for interrupt handler.

PROGRAMMING THE MICROPROCESSOR

04/19/23 5

Interrupt Vectoring Process

PROGRAMMING THE MICROPROCESSOR

04/19/23 6

Common Interrupts• INT 10h Video Services• INT 16h Keyboard Services• INT 17h Printer Services• INT 1Ah Time of Day• INT 1Ch User Timer Interrupt• INT 21h MS-DOS Services

– Input-output– File handling– Memory management

PROGRAMMING THE MICROPROCESSOR

04/19/23 7

USING THE KEYBOARD AND VIDEO DISPLAY

Reading the Keyboard with DOS functions

Interrupt DOS Explanation

Entry Exit

AH DL AL

INT 21H

01 --- ASCII char

Reading a key with an echo

06

or 07

0FFH

(or)

ASCII char

ASCII char

Reading a key without an echo

07 wait till char is read

0A DS:DX = addr. of KB I/P buffer

-- Reading an entire line with an echo

PROGRAMMING THE MICROPROCESSOR

04/19/23 8

.MODEL SMALL

.CODE

KEY PROC FAR

BACK: MOV AH,1

INT 21H

OR AL,AL

JZ BACK

MOV AH,4CH

INT 21H

KEY ENDP

END

Reading a key with an echoReading a key with an echo

D:\>EX715.EXE

R

D:\>

After pressing the key R

PROGRAMMING THE MICROPROCESSOR

04/19/23 9

.MODEL SMALL

.CODE

KEY PROC FAR

MOV AH,6

MOV DL,0FFH

INT 21H

OR AL,AL

JNZ KEY1

KEY1: MOV AH,4CH

INT 21H

KEY ENDP

END

Reading a key without an echoReading a key without an echo

D:\>EX715.EXE

D:\>

OUTPUT

PROGRAMMING THE MICROPROCESSOR

04/19/23 10

Reading an entire line with an echo

DS:DX = addresses the keyboard buffer

In Buffer area

•first byte: maximum number of keyboard characters read by this function

•Second byte :count of the actual number of character typed

•Remaining location: ASCII keyboard data

PROGRAMMING THE MICROPROCESSOR

04/19/23 11

D:\>EX717.EXE

HELLO WORLD!

D:\>

.MODEL SMALL

.DATA

BUF1 DB 257 DUP(?)

.CODE

.STARTUP

MOV BUF1,255

LEA DX, BUF1

MOV AH,0AH

INT 21H

MOV AH,4CH

INT 21H

END

Read an entire line with an echoRead an entire line with an echo

PROGRAMMING THE MICROPROCESSOR

04/19/23 12

USING THE KEYBOARD AND VIDEO DISPLAY

Writing to the video display with DOS function

Interrupt DOS Explanation

Entry Exit

AH DL AL

INT 21H

02 (or)06

0FFH

(or)

ASCII char

ASCII char

Display one ASCII character

09 DS:DX = addr. of KB I/P buffer

-- Display a character string

[ Character must end with ‘$’ (24h) ]

PROGRAMMING THE MICROPROCESSOR

04/19/23 13

D:\MASMEX>EX718.EXE

D:\MASMEX>

D:\MASMEX>EX718.EXE

D:\MASMEX>

DISP MACRO A

MOV AH,06H

MOV DL,A

INT 21H

ENDM. MODEL SMALL.CODE

DISP 0DH

MOV AH,4CHINT 21H

END

DISP MACRO A

MOV AH,06H

MOV DL,A

INT 21H

ENDM.MODEL TINY.CODE

DISP 0AH

MOV AH,4CHINT 21H

END

CARRIAGE RETURN

LINE FEED

Programs that display a carriage return and a lined feed using the DISP macroPrograms that display a carriage return and a lined feed using the DISP macro

PROGRAMMING THE MICROPROCESSOR

04/19/23 14

.MODEL SMALL

.DATA

MSG DB 'THIS IS A TEST LINE.$'

.CODE

MOV AH,9

LEA DX, MSG

INT 21H

MOV AH,4CH

INT 21H

END

D:\MASMEX>EX719

THIS IS A TEST LINE.

D:\MASMEX>

Displaying a Character StringDisplaying a Character StringOUTPUT

PROGRAMMING THE MICROPROCESSOR

04/19/23 15

USING THE KEYBOARD AND VIDEO DISPLAY

Using BIOS Video Function Calls

Interrupt AH Description Parameters

INT 10H 02H Sets cursor position AL=Mode

DH=rows

DL =columns

BH=Page number

INT 10H 03H Reads cursor position DH=rows

DL =columns

BH=Page number

CH =Start line (cursor size)

CL=Ending line (cursor size)

PROGRAMMING THE MICROPROCESSOR

04/19/23 16

80 Characters

0 - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - -- - - - - - - -79columns0

24

row

s Page 0

Video display screenVideo display screen

PROGRAMMING THE MICROPROCESSOR

04/19/23 17

CUR MACRO

MOV AH,2

MOV BH,0

MOV DX,0

INT 10H

ENDM

.MODEL TINY

.CODE

CUR

MOV AH,4CH

INT 21H

END

Sets cursor position at page 0 row 0

column 0

Interrupt for video services

PROGRAMMING THE MICROPROCESSOR

04/19/23 18

System Date /Time with DOS functions

PROGRAMMING THE MICROPROCESSOR

04/19/23 19

Interrupt DOS Description

Entry Exit

INT 21H

AH=2Ah AL=day of the week CX=year

DH=month

DL=day of the month

Get system date

AH=2Bh

CX=year

DH=month

DL=day of the month

Set system date

AH=2Ch CH=hours(0-23)

CL=minutes

DH=seconds

DL=hundredth of second

Get system time

AH=2Dh

CH=hours(0-23)

CL=minutes

DH=seconds

DL=hundredth of second

Set system time

PROGRAMMING THE MICROPROCESSOR

04/19/23 20

.MODEL SMALL

.CODE

.STARTUP

MOV AH,2AH

INT 21H

.EXIT

END

.MODEL SMALL

.CODE

.STARTUP

MOV AH,2CH

INT 21H

.EXIT

END

Program to display the system dateProgram to display the system date

Program to display the system timeProgram to display the system time

PROGRAMMING THE MICROPROCESSOR

04/19/23 21

Sequential file Access

PROGRAMMING THE MICROPROCESSOR

04/19/23 22

Sequential Access FilesOperation Entry

File creation AH =3CH

5AH(UNIQUE)

5B(DOS FILE)

CX=File attributes

AX=Error code if file is not created C=1 (Refer Appendix A)

5B is similar to 5A but displays error code if file is already existing

Write to a file

AH=40H

Bx=file handle

CX=number of bytes to be written DS:DX=address of the area to be written to the disk

Opening File

AH=3DH

AL=00H file opened for read

AL=01H file opened for write

AL=02H file opened for read/write

Reading File AH=3FH Bx=file handle

CX=number of bytes to be written

DS:DX=location of a memory area where the data are store

Closing File AH=3EH

DELETE AH=41H

File pointer AH=42H AL=00H File Pointer move form the start of the file

AL=01H From the current location

AL=02H From the end of the file

CX=Least significant part of the distance

DX=Most Significant part of the distance

PROGRAMMING THE MICROPROCESSOR

04/19/23 23

File Attributes

Bit Position Value Attribute Function

0 01H Read Only A read only file or directory

1 02H Hidden Prevents the file or directory from appearing in a directory listing

2 04H System Specifies a system file

3 08H Volume Specifies the name of the disk volume

4 10H Subdirectory Specifies a subdirectory name

5 20H Archive Indicates that a file has changed since the last backup

PROGRAMMING THE MICROPROCESSOR

04/19/23 24

.MODEL SMALL

.DATA

FILEN DB ‘FILE.TXT,0

.CODE

MOV AX,3CH

LEA DX, FILEN

INT 21H

MOV AH,4CH

INT 21H

END

Program that opens FILE.NEW and appends it with 256 bytes of data from BUFProgram that opens FILE.NEW and appends it with 256 bytes of data from BUF

File Name

Open FILE.NEW

PROGRAMMING THE MICROPROCESSOR

04/19/23 25

.MODEL SMALL

.DATA FILENAME DB 'HEMA1.TXT',0 MSG DB "FILE IS CREATED !$",10,13 MSG1 DB "FILE ERROR $",10,13.CODE MOV AX,@DATA MOV DS,AX LEA DX,FILENAME MOV AH,3CH MOV CX,0H INT 21H JC ERRORMSG LEA DX,MSG MOV AH,09H INT 21H JMP EXIT1ERRORMSG: LEA DX,MSG1 MOV AH,09H INT 21HEXIT1: MOV AH,4CH INT 21H END

/* File creation program*/