ECE341 Practice Question Website


Main Assembly Programming Input/Output Memory Computer Architecture Advanced Topics


Question 1

Assembly Programming Questions





Question 1

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  

Answer

Memory Before After
PC $23000 $20018
a7 $20004 $20010, $2000C, $20010
a3 $20014  
d0 $19283746  
     
$20000 $12345678 $46345678
$20004 $22222222  
$20008 $33333333  
$2000C $44444444  
$20010 $55555555 $20018
$20014 $66666666  



Question 2

Assembly Programming Questions





Question 2

Consider the following --

		org 	$0B0000
	MyVal 	dc.l 	$123456
	

The 68000 instructions in the following table have sources with the same effective addresses (see the first entry in the table).
move.l MyVal,d0 d0 =
move.w $14(a0),d1 a0 =
move.b (a1)+,d2 a1 =
move.l -(a5),d3 a5 =

a0 = $AFFEA, a1 = $B0000, a5 = $B0004

Given that the effective addresses of the sources are the same, can it be said that d0, d1, d2 and d3 have the same values in their least significant bytes after the execution of the instructions in the table above? Why or why not?

Answer

No

Solution

No – some are bytes/words & only change the last chunk of the register



Question 3

Assembly Programming Questions





Question 3

Consider the following --

		org 	$0B0000
	MyVal 	dc.l 	$123456
	

The 68000 instructions in the following table have sources with the same effective addresses (see the first entry in the table).
move.l MyVal,d0 d0 =
move.w $14(a0),d1 a0 =
move.b (a1)+,d2 a1 =
move.l -(a5),d3 a5 =

a0 = $AFFEA, a1 = $B0000, a5 = $B0004

On the right side of the table fill in the values contained in the registers after the instruction completes.

Answer

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



Question 4

Assembly Programming Questions





Question 4

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

Memory:
Addr Data
$00000000 $F0394124
$00000004 $FF000087
$00000008 $00000004
$0000000C $00000002
$00000010 $B4FE8224

Indicate all memory locations and registers that change values after the following instruction is executed, and the new values.

Eg.

	and.l d2,d0
    Result: d0 = $00030054

If the instruction is illegal or the result cannot be determined with the information given, clearly state the reason. Indicate values in memory as M[$addr] = $xxx and show longwords as in the tables above.

Operation:
	or.b	d7,3(a0)
	

Answer

M[$00000004]=$FF000087 (or ‘no changes’)



Question 5

Assembly Programming Questions





Question 5

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

Memory:
Addr Data
$00000000 $F0394124
$00000004 $FF000087
$00000008 $00000004
$0000000C $00000002
$00000010 $B4FE8224

Indicate all memory locations and registers that change values after the following instruction is executed, and the new values.

Eg.

	and.l d2,d0
    Result: d0 = $00030054

If the instruction is illegal or the result cannot be determined with the information given, clearly state the reason. Indicate values in memory as M[$addr] = $xxx and show longwords as in the tables above.

Operation:
	add.l	$8,$C
	

Answer

illegal

Solution

illegal (multiple Absolute modes not supported)



Question 6

Assembly Programming Questions





Question 6

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

Memory:
Addr Data
$00000000 $F0394124
$00000004 $FF000087
$00000008 $00000004
$0000000C $00000002
$00000010 $B4FE8224

Indicate all memory locations and registers that change values after the following instruction is executed, and the new values.

Eg.

	and.l d2,d0
    Result: d0 = $00030054

If the instruction is illegal or the result cannot be determined with the information given, clearly state the reason. Indicate values in memory as M[$addr] = $xxx and show longwords as in the tables above.

Operation:
	and.l d2,d0
    Result: d0 = $00030054

If the instruction is illegal or the result cannot be determined with the information given, clearly state the reason. Indicate values in memory as M[$addr] = $xxx and show longwords as in the tables above.

Operation:
	add.b	d0, d5
	

Answer

d5=$0D358B99



Question 7

Assembly Programming Questions





Question 7

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

Memory:
Addr Data
$00000000 $F0394124
$00000004 $FF000087
$00000008 $00000004
$0000000C $00000002
$00000010 $B4FE8224

Indicate all memory locations and registers that change values after the following instruction is executed, and the new values.

Eg.

	and.l d2,d0
    Result: d0 = $00030054

If the instruction is illegal or the result cannot be determined with the information given, clearly state the reason. Indicate values in memory as M[$addr] = $xxx and show longwords as in the tables above.

Operation:
	and.w	a0,d1
	

Answer

illegal

Solution

illegal, a0 cannot be used in "and" instruction



Question 8

Assembly Programming Questions





Question 8

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

Memory:
Addr Data
$00000000 $F0394124
$00000004 $FF000087
$00000008 $00000004
$0000000C $00000002
$00000010 $B4FE8224

Indicate all memory locations and registers that change values after the following instruction is executed, and the new values.

Eg.

	and.l d2,d0
    Result: d0 = $00030054

If the instruction is illegal or the result cannot be determined with the information given, clearly state the reason. Indicate values in memory as M[$addr] = $xxx and show longwords as in the tables above.

Operation:
	moveq.l #$3,d3
	pea.l 	0(a0,d3)
	

Answer

d3=$00000003
a7=$00000FFC, M[$00000FFC]=$00000004



Question 9

Assembly Programming Questions





Question 9

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
	

Answer

Not Taken
Condition Code and Value: Z = 0



Question 10

Assembly Programming Questions





Question 10

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)+    

Answer

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

* Bracketted values for short addressing



Question 11

Assembly Programming Questions





Question 11

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);
	}
	
Consider a call to factorial() where x is 2. The appropriate state of memory and registers at the point just before the link instruction executes for the first time is shown in (iii).

(iii)
Memory:
... ?
$24C $2000
$250 2
Resisters:
a7: $24C
a6: $254
PC: $3000


Your task: fill in the memory table and the two registers below, showing the configuration just before the unlk instruction executes for the first time. Also write one of the following descriptions to the right of each memory table entry: “return address”, “local variable”, “parameter x”, “callee-saved register”, “caller-saved register”, or “old a6”.

Address Value Description
$214    
$218    
$21C    
$220    
$224    
$228    
$22C    
$230    
$234    
$238    
$23C    
$240    
$244    
$248    
$24C    
$250    

Registers:

a7:

a6:

Hints

  1. d0 is used for the return value;
  2. FACT calls itself recursively, but this behaves no differently than one subroutine calling another;

Answer

Address Value Description
$214    
$218    
$21C    
$220    
$224    
$228    
$22C    
$230 $23C old a6
$234 $3022 return address
$238 0 parameter x
$23C $248 old a6
$240 $3022 return address
$244 1 parameter x
$248 $254 old a6
$24C $2000 return address
$250 2 parameter x

Registers:

a7: $230

a6: $230



Question 12

Assembly Programming Questions





Question 12

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?

Answer

X = 9



Question 13

Assembly Programming Questions





Question 13

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?

Answer

Y = 10 or $0A



Question 14

Assembly Programming Questions





Question 14

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:

Answer

[a2] + 12 or $0C



Question 15

Assembly Programming Questions





Question 15

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.

Hints

Think about Questions 12, 13, and 14.

Answer

	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
	



Question 16

Assembly Programming Questions





Question 16

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
	

Answer

Result: d0 = $98230054



Question 17

Assembly Programming Questions





Question 17

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
	

Answer

Result: d1 = can’t tell

Full Solution

Result: d1 = can’t tell (don’t know what is in memory at location $1000)



Question 18

Assembly Programming Questions





Question 18

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
	

Answer

Result: d5 = $000000A0



Question 19

Assembly Programming Questions





Question 19

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
	

Answer

Result: d7 = illegal

Full Solution

Result: d7 = illegal (destination can’t be #1)



Question 20

Assembly Programming Questions





Question 20

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
	

Answer

Result: d7 = $F2D0FF00



Question 21

Assembly Programming Questions





Question 21

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
	

Answer

Result: d2 = $000000FF



Question 22

Assembly Programming Questions





Question 22

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
	

Answer

Result: d5 = $0D358B45
N = 0
Z = 0
V = 0
C = 0



Question 23

Assembly Programming Questions




Question 23

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)
	

Answer

Result: a7 = $00000FFC
(a7) = $0000980A



Question 24

Assembly Programming Questions





Question 24

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
	

Answer

d0 = 9



Question 25

Assembly Programming Questions





Question 25

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,#-4
can be done using multiple other instructions.

Answer

		move.l	a6,-(a7)
		move.l	a7,a6
		subql	#4,a7
	
	



Question 26

Assembly Programming Questions





Question 26

	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
		end
	
Specify addresses for each instruction & for RESULT in the boxes below.

Address starting at point A
 
 
 
 
 
 
 
 
 
 

Answer

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



Question 27

Assembly Programming Questions





Question 27

	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
		end
	
What is the signed displacement (or offset) to the destination in the “bne LOOP” instruction? (express this as a decimal number)

Answer

-8



Question 28

Assembly Programming Questions





Question 28

	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
		end
	
How many memory cycles are needed for execution of the program?

Answer

54 or 53 if you used absolute short addressing for RESULT



Question 29

Assembly Programming Questions





Question 29

	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
		end
	
What are the contents of memory location RESULT after execution of this program segment?

Answer

$0A (or 10)



Question 30

Assembly Programming Questions





Question 30

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.

Hint

Look up JSR in Appendix C, in particular the variety of addressing modes available.

Answer

	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]
	
	



Question 31

Assembly Programming Questions





Question 31

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
		rts
	
Assume 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

Answer

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



Question 32

Assembly Programming Questions





Question 32

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
		rts
	
After the instruction at point B, where is a6 pointing to relative to TOSA?

Answer

TOSA-12



Question 33

Assembly Programming Questions





Question 33

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
		rts
	
After the instruction at point C, what are the data items on top of TOSA? (fill in the memory table)
Data(words) Address
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
  TOSA

Answer

Data(words) Address
   
   
   
   
   
   
   
   
   
   
   
   
   
   
return adr  
Y  
return value  
  TOSA



Question 34

Assembly Programming Questions





Question 34

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
		rts
	
At point D, to get the result from the subroutine, which number should be filled in the blank?

Answer

2



Question 35

Assembly Programming Questions





Question 35

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
		rts
	
At point E, to make the top of stack the same as at point A, which number should be filled in the blank?

Answer

4



Question 36

Assembly Programming Questions





Question 36

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
		rts
	
Use X, Y, and Z as the name of variables. Express the function performed by SUB in the form of Z = f(X, Y).

Answer

RESULT = X2+Y2+2XY = (X + Y)2



Question 37

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
	



Question 38

Assembly Programming Questions





Question 38

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?

Answer

300 Hz to 330 Hz [1/(3 msec)]



Question 39

Assembly Programming Questions





Question 39

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?

Answer

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