Assembly language hcs12 question! The explanation included of the intire program
ID: 643959 • Letter: A
Question
Assembly language hcs12 question! The explanation included of the intire program the better really.
Ok, so I can follow this code well enough until the interupts are enabled with the CLI command. It then
hits the RTS command and then goes back to hit the infinite main loop. I would like to know how the
program ever gets to the "IRQ_ISR:" part. It seems to me that the code is set up to not hit this. But I know
this part is needed because is tell what is to be done when a flag is triggered.
;******************************************************************************
;-----------------------------Include Libraries--------------------------------
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
; export symbols
XDEF Entry, _Startup, main
; we use export 'Entry' as symbol. This allows us to
; reference 'Entry' either in the linker .prm file
; or from C/C++ later on
XREF __SEG_END_SSTACK
; symbol defined by the linker for the end of the stack
INCLUDE 'mc9s12dg256.inc'
;******************************************************************************
;-----------------------------code section-------------------------------------
MyCode: SECTION
main:
_Startup:
Entry:
LDS #__SEG_END_SSTACK ;initialize the stack pointer
;******************************************************************************
;-----------------------------Main Code Loop-----------------------------------
BSR Init_Ports ;Branch to subroutine below
Main Loop:
BRA Main_Loop
Init_Ports: ;Initialize ports and interrupt hardware
sei ;Disable Interrupts
ldaa DDRH ;Setup I/O IE. switches
anda #$FE ;And's the binary value 11111110 with PORT H
;This sets PORT H bit 0 to be zero or input
staa DDRH ;store new anded value back in DDRH
ldaa DDRB ;Load accumulator A with DDRB, LED's
oraa #$FF ;OR with 1111 1111, makes all leds outputs
staa DDRB ;Store into DDRB, so save that configuration
ldaa DDRJ ;Set up DDRJ, load accumulator A: LED enabler
oraa #$02 ;OR with 0000 0010
staa DDRJ ;Store into DDRJ
ldaa PTJ ;Set up PortJ by load
anda #$FE ;And with 1111 1110
staa PTJ ;Store into PortJ
;*****************************************************************************
ldaa PPSH ;Setup Interrupts, PORT POLARITY SELCT REISTER(ppsh, ppsj,ppsp)
anda #$FE ;And with 1111 1110
staa PPSH ;Set polarity
ldaa PIEH ;Load PIEH, PORT INTERRUPT ENABLE REGISTER(pidh,piej,piep)
oraa #$0F ;OR with 0000 1111
staa PIEH ;Enable interupt on bit 0
ldaa #$FF ;Load accumulator A with 1111 1111
staa PIFH ;Clear all interrupt flags on portH, port interupt flag register
cli ;Enable Interrupts cli
rts ;Then, return to subroutine
IRQ_ISR: ;Interrupt Routine
ldaa PIFH ;LOAD FLAGS
cmpa #$01 ;JUMP ACCORDING TO WHICH FLAG
BEQ Switch1 ;If equal, go to Switch1 loop
cmpa #$02 ;Compare with 0000 0010
BEQ Switch2 ;If equal, then go to Switch2
bra none ;Branch always to none loop
Switch1: ;Switch 1 for incrementing
inc PORTB ;Increment PORTB
bra none
Switch2: ;Switch 2 for clearing
ldaa PORTB
anda #$00 ;Clear the bits, 0000 0000
staa PORTB
bra none ;Branch always to none loop below
none: ;none button
ldaa #$0F ;CLEAR FLAGS, 0000 1111
staa PIFH
rti ;Return from Interrupt
;Enter Vector Table
org $FFCC ;port h interrupt vector see page 145
dc.w IRQ_ISR
Explanation / Answer
When it implements cli command, the program enters interrupt subroutine that is written after the RTS. After completing the interrupt service routine i.e IRQ_ISR, the program counter comes back to the next command after cli and then RTS is implemented.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.