Main | Assembly Programming | Input/Output | Memory | Computer Architecture | Advanced Topics |
The following piece of assembly code is executed with the initial register and memory values shown in the table in the ‘before’ column. Fill in the memory and register values that result from this execution in the ‘after’ column. Cross any intermediate answers out that are not to be marked.
MyVar1 equ $20000 org $23000 move.l #$20010,a7 move.b d0, MyVar1 pea.l $4(a3) rts
Memory | Before | After |
---|---|---|
PC | $23000 |   |
a7 | $20004 |   |
a3 | $20014 |   |
d0 | $19283746 |   |
  |   |   |
$20000 | $12345678 |   |
$20004 | $22222222 |   |
$20008 | $33333333 |   |
$2000C | $44444444 |   |
$20010 | $55555555 |   |
$20014 | $66666666 |   |
Memory | Before | After |
---|---|---|
PC | $23000 | $20018 |
a7 | $20004 | |
a3 | $20014 |   |
d0 | $19283746 |   |
  |   |   |
$20000 | $12345678 | $46345678 |
$20004 | $22222222 |   |
$20008 | $33333333 |   |
$2000C | $44444444 |   |
$20010 | $55555555 | $20018 |
$20014 | $66666666 |   |
Consider the following --
org $0B0000 MyVal dc.l $123456
move.l MyVal,d0 | d0 = |
move.w $14(a0),d1 | a0 = |
move.b (a1)+,d2 | a1 = |
move.l -(a5),d3 | a5 = |
No
No – some are bytes/words & only change the last chunk of the register
Consider the following --
org $0B0000 MyVal dc.l $123456
move.l MyVal,d0 | d0 = |
move.w $14(a0),d1 | a0 = |
move.b (a1)+,d2 | a1 = |
move.l -(a5),d3 | a5 = |
move.l MyVal,d0 | d0 = $123456 |
move.w $14(a0),d1 | a0 = $AFFEA |
move.b (a1)+,d2 | a1 = $B0001 |
move.l -(a5),d3 | a5 = $B0000 |
Given the following data, what is the result of the operation on it?
Registers:
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF | d5 = $0D358B45 |
d6 = $00000010 | d7 = $FF00F2D0 | a0 = $00000001 | a7 = $00001000 |
Addr | Data |
---|---|
$00000000 | $F0394124 |
$00000004 | $FF000087 |
$00000008 | $00000004 |
$0000000C | $00000002 |
$00000010 | $B4FE8224 |
and.l d2,d0    Result: d0 = $00030054
or.b d7,3(a0)
M[$00000004]=$FF000087 (or ‘no changes’)
Given the following data, what is the result of the operation on it?
Registers:
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF | d5 = $0D358B45 |
d6 = $00000010 | d7 = $FF00F2D0 | a0 = $00000001 | a7 = $00001000 |
Addr | Data |
---|---|
$00000000 | $F0394124 |
$00000004 | $FF000087 |
$00000008 | $00000004 |
$0000000C | $00000002 |
$00000010 | $B4FE8224 |
and.l d2,d0    Result: d0 = $00030054
add.l $8,$C
illegal
illegal (multiple Absolute modes not supported)
Given the following data, what is the result of the operation on it?
Registers:
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF | d5 = $0D358B45 |
d6 = $00000010 | d7 = $FF00F2D0 | a0 = $00000001 | a7 = $00001000 |
Addr | Data |
---|---|
$00000000 | $F0394124 |
$00000004 | $FF000087 |
$00000008 | $00000004 |
$0000000C | $00000002 |
$00000010 | $B4FE8224 |
and.l d2,d0    Result: d0 = $00030054
and.l d2,d0    Result: d0 = $00030054
add.b d0, d5
d5=$0D358B99
Given the following data, what is the result of the operation on it?
Registers:
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF | d5 = $0D358B45 |
d6 = $00000010 | d7 = $FF00F2D0 | a0 = $00000001 | a7 = $00001000 |
Addr | Data |
---|---|
$00000000 | $F0394124 |
$00000004 | $FF000087 |
$00000008 | $00000004 |
$0000000C | $00000002 |
$00000010 | $B4FE8224 |
and.l d2,d0    Result: d0 = $00030054
and.w a0,d1
illegal
illegal, a0 cannot be used in "and" instruction
Given the following data, what is the result of the operation on it?
Registers:
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF | d5 = $0D358B45 |
d6 = $00000010 | d7 = $FF00F2D0 | a0 = $00000001 | a7 = $00001000 |
Addr | Data |
---|---|
$00000000 | $F0394124 |
$00000004 | $FF000087 |
$00000008 | $00000004 |
$0000000C | $00000002 |
$00000010 | $B4FE8224 |
and.l d2,d0    Result: d0 = $00030054
moveq.l #$3,d3 pea.l 0(a0,d3)
d3=$00000003
a7=$00000FFC, M[$00000FFC]=$00000004
Is this branch taken or not? What condition codes are involved in the branch decision and what is its value/are their values? [‘Taken’ means that the branch offset is used and we end up at MyLabel]
move.l #00008901,d0 add.w #$ABCD7A43,d0 bclr.l #2,d0 beq MyLabel
Not Taken
Condition Code and Value: Z = 0
Fill in the blank areas in the following table. The memory accesses column should include all memory accesses to get the instruction, the operands and to store the result. Assume each memory access can transfer at most one word.
Intruction | # of words in entire instruction | # of memory accesses |
---|---|---|
add.w d0,1550 |   |   |
add.w #1550,d0 |   |   |
addq.w #3,d2 |   |   |
move.b (a2),(a3)+ |   |   |
Intruction | # of words in entire instruction | # of memory accesses |
---|---|---|
add.w d0,1550 | 3 (or 2)* | 5 (or 4)* |
add.w #1550,d0 | 2 | 2 |
addq.w #3,d2 | 1 | 1 |
move.b (a2),(a3)+ | 1 | 4 |
Consider the assembly in (i), which implements the C-code factorial function in (ii).
(i)
003000: FACT link a6,#0 003004: tst.l 8(a6) 003008: bne NEXT 00300c: move.l #1,d0 003012: bra DONE 003016: NEXT move.l 8(a6),d0 00301a: subq.l #1,d0 00301c: move.l d0,-(a7) 00301e: bsr FACT 003022: addq.l #4,a7 003024: mulu.w 8(a6),d0 003028: DONE unlk a6 00302a: rts |
(ii)
int factorial(int x){ if (x == 0){ return 1; } return x * factorial(x-1); } |
Memory:
|
Resisters: a7: $24C a6: $254 PC: $3000 |
|
Registers: a7: a6: |
|
Registers: a7: $230 a6: $230 |
Student information is being held in a data area, where each student record has the following format:
       The first nine bytes are the student number, held in ASCII
       The next byte is the course mark
       The next word is the section identifier
There are well over three hundred such student records that have been loaded sequentially into memory starting at address $10000. The last record loaded is a dummy record with a section identifier of $FFFF, to show the end of the records.
If a2 has the address of a student record, if using indexed addressing mode, what is the index value X such that X(a2) addresses the course mark?
X = 9
Student information is being held in a data area, where each student record has the following format:
       The first nine bytes are the student number, held in ASCII
       The next byte is the course mark
       The next word is the section identifier
There are well over three hundred such student records that have been loaded sequentially into memory starting at address $10000. The last record loaded is a dummy record with a section identifier of $FFFF, to show the end of the records.
If a2 has the address of a student record, what is the index value Y such that Y(a2) addresses the section identifier?
Y = 10 or $0A
Student information is being held in a data area, where each student record has the following format:
       The first nine bytes are the student number, held in ASCII
       The next byte is the course mark
       The next word is the section identifier
There are well over three hundred such student records that have been loaded sequentially into memory starting at address $10000. The last record loaded is a dummy record with a section identifier of $FFFF, to show the end of the records.
If a2 has the address of a student record, what is the location of the next record in the array / data area:
[a2] + 12 or $0C
Student information is being held in a data area, where each student record has the following format:
       The first nine bytes are the student number, held in ASCII
       The next byte is the course mark
       The next word is the section identifier
There are well over three hundred such student records that have been loaded sequentially into memory starting at address $10000. The last record loaded is a dummy record with a section identifier of $FFFF, to show the end of the records.
Write an assembler subroutine GetMax that will scan the entire list and find the highest mark. If there is a tie, the first student in the list with the highest mark should be found. The subroutine should return the starting address of this record in address register a3.
GetMax movea.l #$10000,a0 ;point a0 to records movea.l a0,a3 ;init return pointer clr.b d0 ;d0 holds the max mark Loop move.w $A(a0),d1 ;get section ID cmpi.w $FFFF,d1 ;see if done beq Exit ;leave loop if so cmp.b 9(a0),d0 ;see if max so far bge L1 ;br if not movea.l a0,a3 ;reset the pointer move.b 9(a0),d0 ;set the new max so far L1 adda.l #$C,a0 ;go to next record bra Loop ;and look at that one Exit rts ;done
Given the following data, what is the result of the operation on it? If an instruction is illegal or the result cannot be determined with the information given, clearly state the reason.
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF |
d5 = $0D358B45 | d7 = $FF00F2D0 | a0 = $00009802 |
a7 = $00001000 |
and.w d2,d0
Result: d0 = $98230054
Given the following data, what is the result of the operation on it? If an instruction is illegal or the result cannot be determined with the information given, clearly state the reason.
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF |
d5 = $0D358B45 | d7 = $FF00F2D0 | a0 = $00009802 |
a7 = $00001000 |
or.b (a7),d1
Result: d1 = can’t tell
Result: d1 = can’t tell (don’t know what is in memory at location $1000)
Given the following data, what is the result of the operation on it? If an instruction is illegal or the result cannot be determined with the information given, clearly state the reason.
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF |
d5 = $0D358B45 | d7 = $FF00F2D0 | a0 = $00009802 |
a7 = $00001000 |
moveq #$A0,d5
Result: d5 = $000000A0
Given the following data, what is the result of the operation on it? If an instruction is illegal or the result cannot be determined with the information given, clearly state the reason.
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF |
d5 = $0D358B45 | d7 = $FF00F2D0 | a0 = $00009802 |
a7 = $00001000 |
addi.l d7,#1
Result: d7 = illegal
Result: d7 = illegal (destination can’t be #1)
Given the following data, what is the result of the operation on it? If an instruction is illegal or the result cannot be determined with the information given, clearly state the reason.
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF |
d5 = $0D358B45 | d7 = $FF00F2D0 | a0 = $00009802 |
a7 = $00001000 |
swap d7
Result: d7 = $F2D0FF00
Given the following data, what is the result of the operation on it? If an instruction is illegal or the result cannot be determined with the information given, clearly state the reason.
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF |
d5 = $0D358B45 | d7 = $FF00F2D0 | a0 = $00009802 |
a7 = $00001000 |
ext.l d2
Result: d2 = $000000FF
Given the following data, what is the result of the operation on it? If an instruction is illegal or the result cannot be determined with the information given, clearly state the reason.
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF |
d5 = $0D358B45 | d7 = $FF00F2D0 | a0 = $00009802 |
a7 = $00001000 |
cmp.l #1,d5
Result: d5 = $0D358B45
N = 0
Z = 0
V = 0
C = 0
Given the following data, what is the result of the operation on it? If an instruction is illegal or the result cannot be determined with the information given, clearly state the reason.
d0 = $98237654 | d1 = $A68B3237 | d2 = $000300FF |
d5 = $0D358B45 | d7 = $FF00F2D0 | a0 = $00009802 |
a7 = $00001000 |
pea.l 8(a0)
Result: a7 = $00000FFC
(a7) = $0000980A
What will be the contents of register d0 when the nop instruction is executed? [See pg 767 in the textbook for a description of dbra if you don’t know what it is]
move.l #0,d0 move.l #2,d4 LOOP addq.l #3,d0 dbra d4,LOOP nop
d0 = 9
The LINK and UNLK instructions are useful for subroutine linkages, but the same operations can be performed using multiple other instructions.
Show how
link.l a6,#-4can be done using multiple other instructions.
move.l a6,-(a7) move.l a7,a6 subql #4,a7
COUNT equ 10 TUTOR equ 228 PROGRAM equ $1000 org PROGRAM move.w #0,d0 ;Point A move.w #COUNT,d1 LOOP subq #1,d1 addq #1,d0 tst d1 bne LOOP move.w d0,RESULT move.w #TUTOR,d7 trap #15 RESULT ds.w 1 endSpecify addresses for each instruction & for RESULT in the boxes below.
Address starting at point A |
---|
  |
  |
  |
  |
  |
  |
  |
  |
  |
  |
Either of the following is correct. The second if you used absolute short addressing for RESULT
Address starting at point A |
---|
$1000 |
$1004 |
$1008 |
$100A |
$100C |
$100E |
$1010 |
$1016 |
$101A |
$101C |
Address starting at point A |
---|
$1000 |
$1004 |
$1008 |
$100A |
$100C |
$100E |
$1010 |
$1014 |
$1018 |
$101A |
COUNT equ 10 TUTOR equ 228 PROGRAM equ $1000 org PROGRAM move.w #0,d0 ;Point A move.w #COUNT,d1 LOOP subq #1,d1 addq #1,d0 tst d1 bne LOOP move.w d0,RESULT move.w #TUTOR,d7 trap #15 RESULT ds.w 1 endWhat is the signed displacement (or offset) to the destination in the “bne LOOP” instruction? (express this as a decimal number)
-8
COUNT equ 10 TUTOR equ 228 PROGRAM equ $1000 org PROGRAM move.w #0,d0 ;Point A move.w #COUNT,d1 LOOP subq #1,d1 addq #1,d0 tst d1 bne LOOP move.w d0,RESULT move.w #TUTOR,d7 trap #15 RESULT ds.w 1 endHow many memory cycles are needed for execution of the program?
54 or 53 if you used absolute short addressing for RESULT
COUNT equ 10 TUTOR equ 228 PROGRAM equ $1000 org PROGRAM move.w #0,d0 ;Point A move.w #COUNT,d1 LOOP subq #1,d1 addq #1,d0 tst d1 bne LOOP move.w d0,RESULT move.w #TUTOR,d7 trap #15 RESULT ds.w 1 endWhat are the contents of memory location RESULT after execution of this program segment?
$0A (or 10)
Depending on an index sent by an outside device we want to be able to call one of ten subroutines in our 68000 program. For 0 sent we call Sub0, for 1 sent we call Sub1, …, for 9 sent we call Sub9.
The subroutine addresses are in a table of longwords, SubAdrs. The index value is passed to our code in d0. Write the code that uses table SubAdrs to make the call to the correct subroutine using only one JSR instruction. State any other assumptions you need.
Look up JSR in Appendix C, in particular the variety of addressing modes available.
movea.l #SubAdrs,a0 ;a0 points to the table asl.l #2,d0 ;change index to a longword offset movea.l 0(a0,d0),a0 ;get tabled value to a0 jsr (a0) ;go to routine [note that jsr uses the effective address]
The following is a code segment with a routine named MAIN which calls a subroutine named SUB. X, Y, and Z are addresses of three one-word memory locations.
MAIN . . . ;point A move.w X,-(a7) move.w Y,-(a7) bsr SUB move.w __(a7),Z ;point D addi.l #__,a7 ;point E . . . SUB link a6,#-6 movem.l d0-d1/a0, -(a7) ;point B move.w $08(a6),d0 muls d0,d0 move.w d0,-2(a6) move.w $0A(a6),d0 muls d0,d0 move.w d0,-4(a6) move.w $0A(a6),d0 move.w $08(a6),d1 muls d1,d0 asl.w #1,d0 move.w d0,-6(a6) lea $0A(a6),a0 move.w -2(a6),d0 add.w -4(a6),d0 add.w -6(a6),d0 move.w d0,(a0) movem.l (a7)+,d0-d1/a0 unlk a6 ;point C rtsAssume at point A, the top of the processor stack is at address TOSA. After the instruction at point B, what are the data items on top of TOSA and their sizes? (fill in the memory table)
Data(words) | Address |
---|---|
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  | TOSA |
Data(words) | Address |
---|---|
  |   |
  |   |
  |   |
d0, d1, a0 |   |
d0, d1, a0 |   |
d0, d1, a0 |   |
d0, d1, a0 |   |
d0, d1, a0 |   |
d0, d1, a0 |   |
local vars |   |
local vars |   |
local vars |   |
old a6 | <-a6 |
old a6 |   |
return adr |   |
return adr |   |
Y |   |
X |   |
  | TOSA |
The following is a code segment with a routine named MAIN which calls a subroutine named SUB. X, Y, and Z are addresses of three one-word memory locations.
MAIN . . . ;point A move.w X,-(a7) move.w Y,-(a7) bsr SUB move.w __(a7),Z ;point D addi.l #__,a7 ;point E . . . SUB link a6,#-6 movem.l d0-d1/a0, -(a7) ;point B move.w $08(a6),d0 muls d0,d0 move.w d0,-2(a6) move.w $0A(a6),d0 muls d0,d0 move.w d0,-4(a6) move.w $0A(a6),d0 move.w $08(a6),d1 muls d1,d0 asl.w #1,d0 move.w d0,-6(a6) lea $0A(a6),a0 move.w -2(a6),d0 add.w -4(a6),d0 add.w -6(a6),d0 move.w d0,(a0) movem.l (a7)+,d0-d1/a0 unlk a6 ;point C rtsAfter the instruction at point B, where is a6 pointing to relative to TOSA?
TOSA-12
The following is a code segment with a routine named MAIN which calls a subroutine named SUB. X, Y, and Z are addresses of three one-word memory locations.
MAIN . . . ;point A move.w X,-(a7) move.w Y,-(a7) bsr SUB move.w __(a7),Z ;point D addi.l #__,a7 ;point E . . . SUB link a6,#-6 movem.l d0-d1/a0, -(a7) ;point B move.w $08(a6),d0 muls d0,d0 move.w d0,-2(a6) move.w $0A(a6),d0 muls d0,d0 move.w d0,-4(a6) move.w $0A(a6),d0 move.w $08(a6),d1 muls d1,d0 asl.w #1,d0 move.w d0,-6(a6) lea $0A(a6),a0 move.w -2(a6),d0 add.w -4(a6),d0 add.w -6(a6),d0 move.w d0,(a0) movem.l (a7)+,d0-d1/a0 unlk a6 ;point C rtsAfter the instruction at point C, what are the data items on top of TOSA? (fill in the memory table)
Data(words) | Address |
---|---|
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  | TOSA |
Data(words) | Address |
---|---|
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
  |   |
return adr |   |
Y |   |
return value |   |
  | TOSA |
The following is a code segment with a routine named MAIN which calls a subroutine named SUB. X, Y, and Z are addresses of three one-word memory locations.
MAIN . . . ;point A move.w X,-(a7) move.w Y,-(a7) bsr SUB move.w __(a7),Z ;point D addi.l #__,a7 ;point E . . . SUB link a6,#-6 movem.l d0-d1/a0, -(a7) ;point B move.w $08(a6),d0 muls d0,d0 move.w d0,-2(a6) move.w $0A(a6),d0 muls d0,d0 move.w d0,-4(a6) move.w $0A(a6),d0 move.w $08(a6),d1 muls d1,d0 asl.w #1,d0 move.w d0,-6(a6) lea $0A(a6),a0 move.w -2(a6),d0 add.w -4(a6),d0 add.w -6(a6),d0 move.w d0,(a0) movem.l (a7)+,d0-d1/a0 unlk a6 ;point C rtsAt point D, to get the result from the subroutine, which number should be filled in the blank?
2
The following is a code segment with a routine named MAIN which calls a subroutine named SUB. X, Y, and Z are addresses of three one-word memory locations.
MAIN . . . ;point A move.w X,-(a7) move.w Y,-(a7) bsr SUB move.w __(a7),Z ;point D addi.l #__,a7 ;point E . . . SUB link a6,#-6 movem.l d0-d1/a0, -(a7) ;point B move.w $08(a6),d0 muls d0,d0 move.w d0,-2(a6) move.w $0A(a6),d0 muls d0,d0 move.w d0,-4(a6) move.w $0A(a6),d0 move.w $08(a6),d1 muls d1,d0 asl.w #1,d0 move.w d0,-6(a6) lea $0A(a6),a0 move.w -2(a6),d0 add.w -4(a6),d0 add.w -6(a6),d0 move.w d0,(a0) movem.l (a7)+,d0-d1/a0 unlk a6 ;point C rtsAt point E, to make the top of stack the same as at point A, which number should be filled in the blank?
4
The following is a code segment with a routine named MAIN which calls a subroutine named SUB. X, Y, and Z are addresses of three one-word memory locations.
MAIN . . . ;point A move.w X,-(a7) move.w Y,-(a7) bsr SUB move.w __(a7),Z ;point D addi.l #__,a7 ;point E . . . SUB link a6,#-6 movem.l d0-d1/a0, -(a7) ;point B move.w $08(a6),d0 muls d0,d0 move.w d0,-2(a6) move.w $0A(a6),d0 muls d0,d0 move.w d0,-4(a6) move.w $0A(a6),d0 move.w $08(a6),d1 muls d1,d0 asl.w #1,d0 move.w d0,-6(a6) lea $0A(a6),a0 move.w -2(a6),d0 add.w -4(a6),d0 add.w -6(a6),d0 move.w d0,(a0) movem.l (a7)+,d0-d1/a0 unlk a6 ;point C rtsUse X, Y, and Z as the name of variables. Express the function performed by SUB in the form of Z = f(X, Y).
RESULT = X2+Y2+2XY = (X + Y)2
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.
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
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.
What is the approximate limit to the rate at which the motor can turn and your program from Question 37 still correctly count the pushes of the switch?
300 Hz to 330 Hz [1/(3 msec)]
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.
If the switch were connected to a falling-edge-sensitive interrupt request line what problem could result during the bouncing? And what is one way the problem might be solved?
Problem:
Multiple interrupts, one per bounce
Solutions:
Disable interrupts in ISR during bounce time
Put debounce as in Question 37 in the ISR
Use hardware debounce circuit
Use flag, set flag while bouncing and don’t count