ADDR B1 B2 B3 B4 X:\public_html\EEL4746\programs\stop.asm PAGE 1 *===================================== * Program: stop.asm. * Purpose: Demonstrates how to use the * STOP instruction. * Author: M. Frank * Date: 10/20/2004 *===================================== * Bit mask equates. BIT7 EQU %10000000 BIT6 EQU %01000000 BIT5 EQU %00100000 BIT4 EQU %00010000 BIT3 EQU %00001000 BIT2 EQU %00000100 BIT1 EQU %00000010 BIT0 EQU %00000001 * Define bit masks for CCR flags. S_FLAG EQU BIT7 X_FLAG EQU BIT6 H_FLAG EQU BIT5 I_FLAG EQU BIT4 N_FLAG EQU BIT3 Z_FLAG EQU BIT2 V_FLAG EQU BIT1 C_FLAG EQU BIT0 * All 1's bit-pattern. * XOR'ing this with a given mask will invert the mask. ALL_1S EQU %11111111 *------------------------------------------- * Main routine: * Tests the Disable_Stop and Halt * subroutines. *------------------------------------------- D000 8D 08 Main: BSR Disable_stop ; Disables the STOP . instruction. D002 CF STOP ; This is a no-op. D003 20 0A BRA Halt ; This never returns. *------------------------------------------- * Subroutine: Enable_Stop * Action: Clears the S flag in the CCR, * which enables the STOP instruction * to actually halt the clocks. *------------------------------------------- Enable_Stop: D005 07 TPA ; Copy CCR to accA. D006 84 7F ANDA #S_FLAG^ALL_1S ; Clear S flag (bit 7) in A. D008 06 TAP ; Copy accA back to CCR. D009 39 RTS *------------------------------------------- * Subroutine: Disable_Stop * Action: Sets the S flag in the CCR, * which disables the STOP instruction, * making it act like a no-op (NOP). *------------------------------------------- Disable_Stop: D00A 07 TPA ; Copy CCR to accA. ADDR B1 B2 B3 B4 X:\public_html\EEL4746\programs\stop.asm PAGE 2 D00B 8A 80 ORAA #S_FLAG ; Set the S flag (bit 7) in . A. D00D 06 TAP ; Copy accA back to CCR. D00E 39 RTS *-------------------------------------------- * Subroutine: Halt * Action: Try our level best to halt the CPU * for good. (Or at least until reset.) *-------------------------------------------- D00F 8D F4 Halt: BSR Enable_Stop ; Enable STOP to halt the . clocks. D011 CF Stop: STOP ; Stop clocks (until . interrupt). D012 20 FD BRA Stop ; Do it again, indefinitely! Symbol Table H_FLAG 0020 S_FLAG 0080 Z_FLAG 0004 V_FLAG 0002 MAIN D000 DISABLE_STOP D00A C_FLAG 0001 N_FLAG 0008 BIT0 0001 BIT1 0002 BIT2 0004 BIT3 0008 BIT4 0010 BIT5 0020 BIT6 0040 BIT7 0080 ENABLE_STOP D005 X_FLAG 0040 STOP D011 HALT D00F I_FLAG 0010 ALL_1S 00FF