Escolar Documentos
Profissional Documentos
Cultura Documentos
The stack
Subroutines
Interrupts
Resets
The
STACK
z
z
Using the
STACK
push operations:
pull operations
z
z
Using Subroutines
z
Subroutine Example
* SUM OF SQUARES: Demonstrate subroutines
* Program squares all the numbers in addresses $C000 to $C07F
* and puts the sum of the squares as a 16-bit result in IX.
ORG
$E000 ;start address
* Start MAIN
MAIN LDS
#$CFFF ;You must define
*
;the stack first squaring loop
LDX #$C000 ;init. data block pointer
LOOP1
JSR
SQUARE ;square it and point to next data
PSHA
;save square
CPX
#$C080 ;squared all data?
BNE
LOOP1 ;get more if not
*
;summing loop
LDX
#$0000 ;sum = 0
LDAA #$80
;i=$80
LOOP2 PULB
;get square(i)
ABX
;sum = sum + square(i)
DECA
;i=i-1
BNE
LOOP2 ;repeat until i == 0
HERE BRA
HERE ;stop program
ENGG4640/3640; Fall 2004; Prepared by Radu Muresan
* End of MAIN
* ----------------------------------------------------
Subroutine Example
* SUBROUTINE SQUARE
* calculates the square of an 8-bit number
* as a rounded 8-bit normalized result
* data pointer (IX) increments
* calling registers:
*
IX = address of data to be squared
* return registers:
*
ACCA = 8-bit square
*
IX=IX+1
*
ACCB is affected
*
others unaffected
SQUARE
LDAA
TAB
MUL
ADCA
INX
RTS
$0,X
#$00
* -----------------------------------------------------
LDS
LDX
*
LOOP1
JSR
INX
CPX
BNE
SQUARE2
;square it and note that
;original IX value returned
;point to next data
#$C080 ;squared all data?
LOOP1 ;get more if not
BRA
HERE
HERE
* End of MAIN
#$FF
;stop program
10
11
12
13
14
15
16
Resets
z
z
z
Resets
and
Interrupts
18
External
RESET
19
Interrupt
z
z
20
10
Interrupt Vector
z
z
21
22
11
CPU Interrupt
Processing
z
23
24
12
Saving Context
z
25
26
13
Vectors
z
z
$vector
ISRname ; form double byte
27
28
14
Software Interrupts
z
A software interrupt is an
instruction that initiates the
interrupt process
In the CPU11 and CPU12
the software interrupt
instruction is SWI
Software interrupts should
be used exclusively for
debugging tools such as
software breakpoints in
debug monitors and
emulators
29
30
15
Software Interrupts
z
31
32
16
33
34
17
#PTR
WAI
REPEAT
*
LDAA
STAA
*
INY
BRA
RIRQ
* This is the interrupt handler routine for parallel I/O
* Note it has the same vector ($FFF2,F3) as IRQ
PTR
LDAA
LDAA
RTI
EQU
35
36
18
STOP
Instruction
37
38
19
Standard
Definitions
39
External Interrupts
z
z
40
20
41
42
68HC11
Interrupts
21
Changing Priority
z
43
44
22
External
Interrupt
Design
Approach
45
46
23
47
48
24
49
50
How to
Establish
the
Vector
25
51
52
Interrupt
Polling
Using
Linked
Lists
26
53
54
27
Periodic
Polling
Plus
Real
Time Interrupts
55
56
28
57
58
6811 Registers
Used to
Configure the
RTI
29
60
30
61
62
31