ECE243 Practice Question Website


Main Assembly Programming Input/Output Memory Computer Architecture Advanced Topics

Assembly Programming Questions





Question 37

Every rotation of a motor causes a switch to be pushed. The switch, like most mechanical switches, ‘clatters’ or bounces when the contacts come together, causing an interval when a single press causes multiple closures. This bouncing can continue for just under 3 milliseconds.
The switch is linked into the memory map of a 68000 processor at bit 0 of location $FFFFF000. It is connected so that the bit will read a ‘1’ when the switch is open, and a ‘0’ when closed and not bouncing. The bouncing will cause alternating zeros and ones.
For ease of any analysis you do, assume that every instruction takes 1 usec., regardless of addressing mode.

Write a commented program that continuously counts the number of times the switch is pushed. It must ignore the bouncing of the switch. This is all your program needs to do; don’t worry about other functions that the 68000 may have to perform at this point.

Answer

Assumptions: The switch is like a switch on a calculator, where there is no latched 'on' position. At one point in the turn of the motor the switch is pressed and bounces. Later on in the turn the switch is released. This repeats every revolution of the motor. There is no bounce when the switch is released.
Different reasonable interpretations of the mechanics of the problem are possible.

	SwitchPlace 	EQU 	$FFFFF000
	SwitchBit 	EQU 	$00
	DelayCount 	EQU 	1500			;1500 * 2 instr * 1 usec = 3 msec.
			org 	$10000
	Start 		moveq 	#0,d0 			;d0 is the counter
						; The main counting loop starts here
	Open 		btst.b 	#SwitchBit,SwitchPlace 	;see if switch open
			bne 	Open 			;back if so
						; When we get here, the switch has just been pressed
			addq.l 	#1,d0 			;advance the count
						; Delay over 3 msec to ignore bounce
			movei 	#DelayCount,d1 		;loop this many times
	Loop 		subq 	#1,d0 			;d0 will be zero by 3 msec.
			bne 	Loop
						; Now must wait for switch to be released
	Closd 		btst.b 	#SwitchBit,SwitchPlace 	;see if switch closed
			bne 	Open 			;back to start if open (released)
			bra 	Closd 			;keep looping here if not