*===================================== * 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. *------------------------------------------- Main: BSR Disable_stop ; Disables the STOP instruction. STOP ; This is a no-op. 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: TPA ; Copy CCR to accA. ANDA #S_FLAG^ALL_1S ; Clear S flag (bit 7) in A. TAP ; Copy accA back to CCR. 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: TPA ; Copy CCR to accA. ORAA #S_FLAG ; Set the S flag (bit 7) in A. TAP ; Copy accA back to CCR. RTS *-------------------------------------------- * Subroutine: Halt * Action: Try our level best to halt the CPU * for good. (Or at least until reset.) *-------------------------------------------- Halt: BSR Enable_Stop ; Enable STOP to halt the clocks. Stop: STOP ; Stop clocks (until interrupt). BRA Stop ; Do it again, indefinitely!