Sei sulla pagina 1di 25

PROGRAMMING THE MICROPROCESSOR

Programming the Microprocessor


Using Keyboard and Video Display
Data Conversions
Disk files

02/21/15

PROGRAMMING THE MICROPROCESSOR

MS-DOS Memory Organization

02/21/15

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

MS-DOS MEMORY MAP


FFFFF
F0000
E0000

C8000

BIOS system ROM


BASIC language ROM
Free area
Hard disk controller ROM
LAN controller ROM
Video BIOS ROM

System area

C0000
B0000

REAL
MEMORY

A0000
9FFFF
9FFF0
08E30
08490

Video RAM(Graphics)
MS DOS program
Free TPA
COMMAND.COM

01160

Device drivers
such as MOUSE.SYS
MSDOS program

00700

IO.SYS program

00500

DOS communication area

00400

BIOS communication area

00000

Interrupt vectors

02530

02/21/15

Video RAM (text)

Transient Program area

PROGRAMMING THE MICROPROCESSOR

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 segmentoffset address for each possible interrupt handler.
Interrupt Service Routine (ISR) is another name for interrupt
handler.

02/21/15

PROGRAMMING THE MICROPROCESSOR

Interrupt Vectoring Process

02/21/15

PROGRAMMING THE MICROPROCESSOR

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

02/21/15

PROGRAMMING THE MICROPROCESSOR

USING THE KEYBOARD AND VIDEO DISPLAY


Reading the Keyboard with DOS functions
Interrupt

DOS
Entry

INT 21H

02/21/15

Explanation
Exit

AH

DL

AL

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

Reading a key with an echo


.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

D:\>EX715.EXE
R

After pressing the key R

D:\>
02/21/15

PROGRAMMING THE MICROPROCESSOR

Reading a key without an echo


.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
OUTPUT

D:\>EX715.EXE
D:\>
02/21/15

PROGRAMMING THE MICROPROCESSOR

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

02/21/15

10

PROGRAMMING THE MICROPROCESSOR

Read an entire line with an echo


.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
D:\>EX717.EXE
HELLO WORLD!
D:\>
02/21/15

11

PROGRAMMING THE MICROPROCESSOR

USING THE KEYBOARD AND VIDEO DISPLAY


Writing to the video display with DOS function
Interrupt

DOS
Entry

INT 21H

02/21/15

Explanation
Exit

AH

DL

AL

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) ]

12

PROGRAMMING THE MICROPROCESSOR

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

DISP MACRO A

MOV AH,06H

MOV AH,06H

MOV DL,A

MOV DL,A

INT 21H

INT 21H

ENDM
. MODEL SMALL
.CODE

ENDM
.MODEL TINY
.CODE

DISP 0DH
MOV AH,4CH
INT 21H
END

DISP 0AH

LINE FEED

MOV AH,4CH
INT 21H

CARRIAGE
RETURN
END

D:\MASMEX>EX718.EXE
D:\MASMEX>EX718.EXE

D:\MASMEX>
02/21/15

D:\MASMEX>
13

PROGRAMMING THE MICROPROCESSOR

Displaying a Character String


.MODEL SMALL
.DATA
MSG DB 'THIS IS A TEST LINE.$'

OUTPUT
D:\MASMEX>EX719
THIS IS A TEST LINE.
D:\MASMEX>

.CODE
MOV AH,9
LEA DX, MSG
INT 21H
MOV AH,4CH
INT 21H
END

02/21/15

14

PROGRAMMING THE MICROPROCESSOR

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)

02/21/15

15

PROGRAMMING THE MICROPROCESSOR

rows

Video display screen


0 - - - - - - - - - - - - - - - - -columns
- - - - - - - - - - -- - - -- - - - - - - -79
80 Characters

Page 0

24

02/21/15

16

PROGRAMMING THE MICROPROCESSOR

CUR MACRO
MOV AH,2
MOV BH,0
MOV DX,0
INT 10H

Sets cursor position at


page 0
row 0
column 0

ENDM

.MODEL TINY

Interrupt for video services

.CODE
CUR
MOV AH,4CH
INT 21H
END

02/21/15

17

PROGRAMMING THE MICROPROCESSOR

System Date /Time with DOS functions

02/21/15

18

PROGRAMMING THE MICROPROCESSOR

Interrupt

DOS
Entry
AH=2Ah

INT 21H

Exit
AL=day of the week
CX=year
DH=month
DL=day of the month

AH=2Bh
CX=year
DH=month
DL=day of the month
AH=2Ch

AH=2Dh
CH=hours(0-23)
CL=minutes
DH=seconds
DL=hundredth of second
02/21/15

Description

Get system date

Set system date

CH=hours(0-23)
CL=minutes
DH=seconds
DL=hundredth of second

Get system time

Set system time

19

PROGRAMMING THE MICROPROCESSOR

Program to display the system date


.MODEL SMALL
.CODE
.STARTUP
MOV AH,2AH

Program to display the system time


.MODEL SMALL
.CODE

INT 21H

.STARTUP

.EXIT

MOV AH,2CH

END

INT 21H
.EXIT
END

02/21/15

20

PROGRAMMING THE MICROPROCESSOR

Sequential file Access

02/21/15

21

PROGRAMMING THE MICROPROCESSOR

Sequential Access Files


Operation
File creation

Write to a
file

Entry
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

AH=40H

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

AH=3DH

AL=00H file opened for read


AL=01H file opened for write
AL=02H file opened for read/write

Opening File

Reading File

AH=3FH

Closing File

AH=3EH

DELETE

AH=41H

File pointer

AH=42H

02/21/15

Bx=file handle
CX=number of bytes to be written
DS:DX=location of a memory area where the data are store

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

22

PROGRAMMING THE MICROPROCESSOR

File Attributes
Bit Position

Value

Attribute

Function

01H

Read Only

A read only file or directory

02H

Hidden

Prevents the file or directory


from appearing in a directory
listing

04H

System

Specifies a system file

08H

Volume

Specifies the name of the disk


volume

10H

Subdirectory

Specifies a subdirectory name

20H

Archive

Indicates that a file has


changed since the last backup

02/21/15

23

PROGRAMMING THE MICROPROCESSOR

Program that opens FILE.NEW and appends it with 256 bytes of data from BUF
.MODEL SMALL
.DATA
FILEN DB FILE.TXT,0
.CODE
MOV AX,3CH

File Name
Open FILE.NEW

LEA DX, FILEN


INT 21H
MOV AH,4CH
INT 21H
END

02/21/15

24

PROGRAMMING THE MICROPROCESSOR

/* File creation program*/


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 EXIT1
ERRORMSG:
LEA DX,MSG1
MOV AH,09H
INT 21H
EXIT1:
MOV AH,4CH
INT 21H
END
.

02/21/15

25

Potrebbero piacerti anche