A Look Inside the 8086

Download Report

Transcript A Look Inside the 8086

Real-Time Clock
Module M19.4
Section 14.1 (p.415)
Introduction to Computer Engineering by Richard E. Haskell
Real-time Clock
Time of Day options using INT 1AH
AH = 0
AH = 1
Read the 32-bit counter clock setting
Output: CX = high word of count
DX = low word of count
AL = 0 if count has not exceeded
24 hours since last read
= 1 if 24 hours has passed
Set the 32-bit counter clock
Input: CX = high word of count
DX = low word of count
32-bit counter at address 0040:006C - 0040:006F
Counter increments 18.2 times per second.
Each increment is called a tick.
Introduction to Computer Engineering by Richard E. Haskell
Offset Address
000
004
008
00C
010
014
Interrupt
Vector
Table
040
044
048
04C
050
054
058
05C
060
INT 1CH
Timer Tick
Offset: $070
064
068
06C
070
080
084
088
08C
Type No.
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
0
Division by zero
1
Single Stepping
2
NMI Interrupt
3
1-byte INT (opcode= CC)
4
Signed overflow
5
Print Screen
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
10
Video I/O
11
Equipment Check
12
Memory Size
13
Diskette I/O
14
Serial Communication I/O
15
Cassette I/O
16
Keyboard I/O
17
Printer I/O
18
Cassette BASIC
19
Bootstrap
1A
1B
Time of Day
Keyboard Break
1C
Timer Tick
20
ProgramTerminate
21
22
Function Request
23
Ctrl-Break Exit Address
IP
CS
IP
CS
IP
CS
IP
CS
Terminate Address
Introduction to Computer
Engineering
3F8
IP
FE by Richard E. Haskell
3FC
CS
IP
CS
FF
BIOS
DOS
Table 14.1
PC Hardware Interrupts
Interrupt
Type No.
8
9
A
B
C
D
E
F
Interrupt Vector
Hex Offset Address
20
24
28
2C
30
34
38
3C
Name
Timer Tick
Keyboard
Unused
Reserved for COM2 Serial I/O
Reserved for COM1 Serial I/O
Unused
Disk I/O
Reserved for Printer
The Timer Tick hardware interrupt increments the
32-bit counter and then calls INT 1CH.
The software interrupt routine just returns using
the IRET instruction.
Therefore, INT 1CH is called 18.2 times per second.
Introduction to Computer Engineering by Richard E. Haskell
Offset Address
000
004
008
00C
010
014
Interrupt
Vector
Table
040
044
048
04C
050
054
058
05C
060
Type No.
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
0
Division by zero
1
Single Stepping
2
NMI Interrupt
3
1-byte INT (opcode= CC)
4
Signed overflow
5
Print Screen
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
IP
CS
10
Video I/O
11
Equipment Check
12
Memory Size
13
Diskette I/O
14
Serial Communication I/O
15
Cassette I/O
16
Keyboard I/O
17
Printer I/O
18
Cassette BASIC
064
19
Bootstrap
INT 1CH
068
1A
Time of Day
Timer Tick
06C
1B
Keyboard Break
1C Timer Tick
070
Offset: $070
IP
20
080
ProgramTerminate
You can replace the
CS
084
IP
21
Function Request
CS
IP and CS values at
088
22
IP
Terminate Address
CS
08C
IP
23
Ctrl-Break Exit Address
0000:0070 with the
CS
address of yourIntroduction
routine.
to Computer
Engineering
3F8
IP
FE by Richard E. Haskell
3FC
CS
IP
CS
FF
BIOS
DOS
Real-time clock interrupt
service routine algorithm
dec count (count is initially set to 18)
if count > 0
then return from interrupt
else inc SECS
if SECS=60
then inc MINS
reset SECS=00
if MINS=60
then inc HOURS
reset MINS=00
if HOURS=13
then set HOURS=01
endif
endif
endif
display time
set count to 18 (or 19 every 5th time)
endif
Introduction to Computer Engineering by Richard E. Haskell
Setting the interrupt vector
using an INT 21H DOS call
AH = 35H
AH = 25H
Get Interrupt Vector
Inputs: AL = interrupt number
Outputs: ES:BX = segment:offset of current
Type AL interrupt handler
Set Interrupt Vector
Inputs: AL = interrupt number
DS:DX = segment:offset of interrupt
handler
push ds
push cs
pop
ds
mov
dx,offset intser
mov
al,1Ch
mov
ah,25h
int
21h
pop
Introduction ds
to Computer Engineering by Richard E. Haskell
Storing the time 10:24:37
in the keyboard buffer
kbuf
3 1
HOURS
3 0
kbuf + 3
3 A
:
3 2
MINS
3 4
kbuf + 6
3 A
:
3 3
SECS
3 7
Introduction to Computer Engineering by Richard E. Haskell
;
dsptim
dpt1:
dsptim
display time
proc near
push
ax
push
si
push
di
push
cx
push
es
mov
ax,vidseg
mov
es,ax
mov
di,008ch
mov
cx,8
mov
si,offset kbuf
mov
ah,70h
cld
lodsb
stosw
loop
dpt1
pop
es
pop
cx
pop
di
pop
si
pop
ax
ret
endp
;save regs
;point to video
; RAM with es
;end of 1st row
;move 8 bytes
;point to time
;reverse video
;load byte
;store word
;do 8 times
;restore regs
Introduction to Computer Engineering by Richard E. Haskell
Listing 14.1
title
clock.asm
real-time clock
;
Link with screen
stack
segment para stack
db
64 dup (?)
ends
stack
extrn mess2:near,setcur:near
extrn query:near
extrn kbuf:byte,blank:near
data
msg1
count
cnt5
vidseg
vecseg
vecoff
data
segment
public
db
'Enter current time '
db
'<hour:min:sec>: ',0
db
?
db
?
dw
?
;video segment address
dw
?
;save int vector segment addr
dw
?
;save int vector offset addr
ends
Introduction to Computer Engineering by Richard E. Haskell
;
clock
clk1:
clk2:
clock
main program
proc far
mov
ax,data
mov
ds,ax
;ds=data
mov
ah,15
;get video state
int
10h
cmp
al,7
;if mode 7
jne
clk1
mov
vidseg,0b000h
;vidseg=b000
jmp
clk2
;else
mov
vidseg,0b800h
;vidseg=b800
mov
dh,24
;row=24
call
blank
;blank row 24
mov
dl,0
;col=0
call
setcur
;set cursor
mov
si,offset msg1
call
mess2
;enter
call
query
; starting time
call
dsptim
;display time
mov
count,18
;count=18
mov
cnt5,5
;cnt5=5
push
ds
;save ds
mov
ah,35h
;save 1Ch int vec
mov
al,1Ch
int
21h
mov
vecseg,es
mov
vecoff,bx
push
cs
;store int vec
pop
ds
mov
dx,offset intser
mov
ah,25h
int
21h
pop
ds
;restore ds
Introduction
to Computer Engineering;bystay
Richard
Haskell
int 3
in E.tutor
endp
Real-time clock interrupt
service routine algorithm
dec count (count is initially set to 18)
if count > 0
then return from interrupt
else inc SECS
if SECS=60
then inc MINS
reset SECS=00
if MINS=60
then inc HOURS
reset MINS=00
if HOURS=13
then set HOURS=01
endif
endif
endif
display time
set count to 18 (or 19 every 5th time)
endif
Introduction to Computer Engineering by Richard E. Haskell
;
intser
out1:
out2:
interrupt service routine
proc near
push
ax
;save regs
push
cx
push
si
push
ds
mov
ax,data
mov
ds,ax
;ds=data
dec
count
;dec count
jne
out2
;if = 0
mov
si,offset kbuf
;point to time
mov
ax,6[si]
;ax=secs
xchg
al,ah
add
al,1
;inc secs
aaa
;ascii adjust
or
al,30h
mov
6[si],ah
mov
7[si],al
cmp
ax,3630h
;if secs=60
jne
out1
;then
mov
word ptr 6[si],3030h
; secs=00
mov
ax,3[si]
xchg
al,ah
add
al,1
; inc mins
aaa
or
al,30h
mov
3[si],ah
mov
4[si],al
cmp
ax,3630h
; if mins=60
jne
out1
; then
mov
word ptr 3[si],3030h
;
mins=00
mov
ax,[si]
xchg
al,ah
add
al,1
;
inc hours
aaa
or
al,30h
mov
[si],ah
mov
1[si],al
cmp
ax,3133h
;
if hours=13
jne
out1
;
then
mov
word ptr [si],3130h
;
hours=01
call
dsptim
;display time
mov
count,18
;count=18
dec
cnt5
; (or every
jne
out2
;
5th time,
inc
count
;
count=19)
mov
cnt5,5
; reset cnt5=5
pop
ds
;restore regs
pop
si
pop
cx
pop
ax
iret
endp
Introduction
to Computer Engineering by Richard E. Haskell
out3:
intser
;
intser
interrupt service routine
proc near
push
ax
;save regs
push
cx
push
si
push
ds
mov
ax,data
mov
ds,ax
;ds=data
dec
count
;dec count
jne
out2
;if = 0
mov
si,offset kbuf
;point to time
mov
ax,6[si]
;ax=secs
xchg
al,ah
add
al,1
;inc secs
aaa
;ascii adjust
or
al,30h
mov
6[si],ah
mov
7[si],al
cmp
ax,3630h
;if secs=60
jne
out1
;then
mov
word ptr 6[si],3030h
; secs=00
mov
ax,3[si]
xchg
al,ah
add
al,1
; inc mins
aaa
Introduction to Computer Engineering by Richard E. Haskell
out1:
out2:
out3:
intser
aaa
or
al,30h
mov
3[si],ah
mov
4[si],al
cmp
ax,3630h
; if mins=60
jne
out1
; then
mov
word ptr 3[si],3030h
;
mins=00
mov
ax,[si]
xchg
al,ah
add
al,1
;
inc hours
aaa
or
al,30h
mov
[si],ah
mov
1[si],al
cmp
ax,3133h
;
if hours=13
jne
out1
;
then
mov
word ptr [si],3130h
;
hours=01
call
dsptim
;display time
mov
count,18
;count=18
dec
cnt5
; (or every
jne
out2
;
5th time,
inc
count
;
count=19)
mov
cnt5,5
; reset cnt5=5
pop
ds
;restore regs
pop
si
pop
cx
pop
ax
iret
Introduction to Computer Engineering by Richard E. Haskell
endp
;
clkoff
clkoff
turn clock off
proc near
push
ds
mov
dx,vecoff
mov
ds,vecseg
mov
al,1Ch
mov
ah,25h
int
21h
pop
ds
int 3
endp
;save ds
;restore old
; 1Ch int vec
Introduction to Computer Engineering by Richard E. Haskell