Transcript CSE22MAL

ELE22MIC Lecture 9
• ASll Examples
– 16 Bit Counters
– Buffalo Jump Table
• Interrupt processing (IRQ/RTI)
• Stack Frame & Base Pointer
• Wired OR Interrupts
AS11 Example (1)-16 bit counters
* 16 Bit counter problems
loop_counter rmb 2
dec_count:
dec
rts
loop_counter
; declare 2 bytes for 16 bit counter
; then execute code as follows:
; only one byte is decremented !!!
; How can we fix this problem?
; One way is to use a 16 bit register as follows:
dec_count:
ldd
std
lots_of_loops:
jsr
pshy
ldy
dey
sty
puly
bne
rts
#FFFF
loop_counter
; we can loop 65535 times
do_something
; do something
loop_counter
loop_counter
loop_again
;
;
;
;
;
save the y index register value
load value of loop_counter -> Y
decrement y = decrement loop_counter
store value of y-> loop_counter
recover saved y index register value
; if (loop_counter <> 0), loop again
68HC11 Parallel I/O & Control (1)
AS11 Example (2) - Bit IO (1)
* The 68HC11 has single Bit Set & Bit Clear instructions set or clear
* individual bits at the selected memory location.
* The instruction format is BSET/BCLR MemoryAddress Mask
* A ‘1’ in the Mask indicates this bit should be Set/Cleared
* A ‘0’ in the Mask indicates that the bit will not be changed.
* I.e. BSET bitwise-ORs the Mask onto memory
* BCLR bitwise-ANDs the inverse of the Mask onto memory
* We can declare equates as follows to access them:
Bit0
EQU
%00000001
; = 1
Bit1
EQU
%00000010
; = 2
Bit2
EQU
%00000100
; = 4
Bit3
EQU
%00001000
; = 8
Bit4
EQU
%00010000
; = $10
Bit5
EQU
%00100000
; = $20
Bit6
EQU
%01000000
; = $40
Bit7
EQU
%10000000
; = $80
AllBits EQU
%11111111
; = $FF
LowNyyble EQU
%00001111
; = $0F
HighNyyble EQU
%11110000
; = $F0
LoopMax EQU
100
IOREG
PORTB
EQU
EQU
$1000
4
; start address of Configuration Registers
AS11 Example (2) - Bit IO (2)
FlashLeds:
LDAA
LDX
; Connect LEDs to PortB
LoopMax ; A = 100 = Our loop counter
#IOREG
; X = $1000
BCLR
PORTB, X AllBits ; PortB = %00000000
LOOPAGAIN:
BSET
BSET
BSET
BSET
BSET
BSET
BSET
BSET
jsr
BCLR
BCLR
jsr
BSET
BCLR
DECA
BNE
RTS
PORTB, X BIT0
; PortB = %00000001
PORTB, X BIT1
; PortB = %00000011
PORTB, X BIT2
; PortB = %00000111
PORTB, X BIT3
; PortB = %00001111
PORTB, X BIT4
; PortB = %00011111
PORTB, X BIT5
; PortB = %00111111
PORTB, X BIT6
; PortB = %01111111
PORTB, X BIT7
; PortB = %11111111
wait_a_bit
PORTB, X LowNybble; PortB = %11110000
PORTB, X HighNybble; PortB = %00000000
wait_a_bit
PORTB, X HighNybble; PortB = %11110000
PORTB, X HighNybble; PortB = %00000000
LOOPAGAIN
; loop 100 times
Wired OR - IRQ
A Wired-NOR
gate is formed
by connecting
open-collector
device interrupt
lines together.
Normal gates
would fight
causing high
current drain
and possibly
damage the
gate.
IRQ Processing (1)
Any device requiring attention activates an interrupt service
routine simply by asserting its interrupt output.
The interrupt causes the CPU to :
1. Complete the current instruction - delay interrupt
servicing until the current instruction completes (delay
of from 1 (ABA) - 41 (IDIV) clock cycles)
2. Push all registers - PC, X, Y, AccA, AccB & CCR
3. Mask interrupts by setting the I bit in CCR
3. Fetch the interrupt vector
4. Jump to the address fetched from the int. vector
IRQ Processing (2)
The Interrupt Service Routine (ISR) must then poll all
devices connected to the IRQ pin and ask each device in
turn:
“Did you interrupt me?”
Upon finding a device requiring service, perform the
appropriate Input/Output/Processing and reset the device’s
interrupt request (so that upon return the cpu is not
immediately interrupted again).
Upon successful servicing, the ISR must exit without
altering the previously running program’s state. The ISR
does this simply by executing the RTI instruction (ReTurn
from Interrupt).
IRQ Processing (3)
The RTI instruction :Pulls all the previously saved registers
from the stack, in the reverse order that they were pushed,
so that all registers contain the previous values.
Pul : CCR, AccB, AccA, Y, X, PC
The last pul - Pul PC - Pulls (pops) the program counter
which effectively transfers program execution to the
instruction immediately following the instruction
completed before the interrupt request was accepted.
Pulling the CCR re-enables the CPUs ability to be
interrupted as the I flag which was cleared will be cleared
again.
IRQ Processing (4)
If the interrupt mask bit, I, in the CCR is unmasked during
the ISR, then the IRQ line could cause one or more nested
interrupts.
This ISR nesting procedure would normally only be
performed to provide more rapid response to a higher
priority device.
Stack Frame (1)
In the C language, the function parameters are normally
pushed in the reverse order that they are listed. This is to
facilitate C’s format statements for example:
Printf (“P1=%3d, P2=%4d\n”, P1, P2);
would compile to:
Push P2
Push P1
Push FormatStatement
JSR
Printf
; Printf knows where the
; format statement will be
Add
SP, #6
; drop the parameters
Stack Frame (2)
The subroutine Printf expects to find the format statement
as the first parameter on the stack. It then parses the
statement, and determines how many more, and what type
of, parameters are required.
The return address is also placed on the stack.
Also Local variables are pushed onto the stack.
During the function these variables can be accessed on the
stack frame as follows:
10A (SP+A)-> P2
108
106
104
102
100
(SP+8)-> P1
(SP+6)->A:H29
FormatStt
(SP+4)-> ReturnAddress
(SP+3)-> LocalVariable1
SP+1>
LocalVariable2
SP->
Frame/Base Pointer (2)
For the duration of the function execution a frame pointer
can be set up using the X or Y registers, and the variables
may be accessed using indexed addressing
P2
EQU
A
P1
EQU
8
FormatStt
EQU
6
LocalVar1
EQU
2
LocalVar2
EQU
0
TSX
10A
108
106
104
102
100
(X+A)->
(X+8)->
(X+6)->
(x+4)->
(X+2)->
X->
SP->
P2
P1
FormatStt
ReturnAddress
LocalVar1
LocalVar2
; X = SP+1 (Setup Frame Ptr)
LDD
P1, X
; D = P1 (Fetch P1)
STD
LocalVar1, X
; LocalVar = AccD = P1
Buffalo Routines Jump Table (1)
ORG
.WARMST
.BPCLR
.RPRINT
.HEXBIN
.BUFFAR
.TERMAR
.CHGBYT
.READBU
.INCBUF
.DECBUF
.WSKIP
.CHKABR
ROMBS+$1F7C
JMP
MAIN
JMP
BPCLR
JMP
RPRINT
JMP
HEXBIN
JMP
BUFFARG
JMP
TERMARG
JMP
CHGBYT
JMP
READBUFF
JMP
INCBUFF
JMP
DECBUFF
JMP
WSKIP
JMP
CHKABRT
warm start
clear breakpoint table
display user registers
convert ascii hex char to binary
build hex argument from buffer
read hex argument from terminal
modify memory at address in x
read character from buffer
increment buffer pointer
decrement buffer pointer
find non-whitespace char in buffer
check for abort from terminal
Buffalo Routines Jump Table (2)
ORG
.UPCASE
.WCHEK
.DCHEK
.INIT
.INPUT
.OUTPUT
.OUTLHL
.OUTRHL
.OUTA
.OUT1BY
.OUT1BS
.OUT2BS
.OUTCRL
.OUTSTR
.OUTST0
.INCHAR
.VECINT
ROMBS+$1FA0
JMP
UPCASE
JMP
WCHEK
JMP
DCHEK
JMP
INIT
JMP
INPUT
JMP
OUTPUT
JMP
OUTLHLF
JMP
OUTRHLF
JMP
OUTA
JMP
OUT1BYT
JMP
OUT1BSP
JMP
OUT2BSP
JMP
OUTCRLF
JMP
OUTSTRG
JMP
OUTSTRG0
JMP
INCHAR
JMP
VECINIT
convert to upper case
check for white space
check for delimeter
initialize i/o device
low level input routine
low level output routine
display top 4 bits as hex digit
display bottom 4 bits as hex digit
output ascii character in A
display the hex value of byte at X
out1byt followed by space
display 2 hex bytes at x and a space
carriage return, line feed to terminal
display string at X (term with $04)
outstrg with no initial carr ret
wait for and input a char from term
initialize RAM vector table