;----------------------------------------------------------------- ; EX81.ASM Using a Software Interrupt. C.P. Diduch, 2001 ; ; This program uses a software interrupt to branch control to an ; interrupt handler that toggles the state of an LED connected ; to output port 0x0003. ; ; Author(s): ; Signature(s): Date: ;----------------------------------------------------------------- ; .ORG 0x0000 ; "assign to RAM" .DS 1 ; "interrupt vector 0" .DS 1 ; "interrupt vector 1" ; MAIN PROGRAM ; void main(void) { ; .ORG 0x8000 ; "assign the following to ROM" ; ADDL R1, NULL, TOGG ; "initialize interrupt vector" STOREM 0, R1 ; ; do { M0: CALL DELAY, RA ; DELAY() ; INT 0 ; asm "INT 0" ; JMP M0 ; } ;----------------------------------------------------------------- ; void interrupt TOGG(void) ; ; Interrupt handler, TOGG, toggles the state of the LED ; connected to bit-0 of output port 0x0003 with each interrupt. ; TOGG: ; void interrupt TOGGLE(void) { XORL R2, R2, 0x8001 ; STOREP 0x0003, R2 ; outport(3, LEDVAL^0x8001) ; RETI ; ; ;----------------------------------------------------------------- ; void DELAY(void) ; ; Procedure DELAY() implements a software delay via a 'nested' ; decrement of registers R0 and R1. The procedure modifies ; registers R1, R0 and FL. ; DELAY: ; void DELAY(void) { ADDL R1, NULL, 0x400 ; D0: ADDL R0, NULL, 0x020 ; D1: SUBL R0, R0, 1 ; JMPNZ D1 ; SUBL R1, R1, 1 ; JMPNZ D0 ; DJMP (RA) ;