Useful Tools

contact us contact tutor/group email to a friend accessibility options report a fault
Microcontrollers

Microcontrollers

Unit 3 -  Software and the Microcontroller Instruction Set

Self Assessment Questions

The answers for questions 1 to 7 inclusive are contained within the course notes.


Question 1

What is the purpose of:


Question 2

What are the stages in developing an assembly language program?


Question 3

What is the purpose of the EQU directive?


Question 4

What is the purpose of the ORG directive?


Question 5

What is the purpose of the Status register?


Question 6

Why is a reset vector necessary in a microprocessor/microcontroller system and how does it work in the case of the PIC16F84?


Question 7

What is the purpose of a stack in a microcontroller?


Question 8

Explain the function (and outcome) of the following PIC instructions:

Question 8a

BSF porta,3

Answer

sets bit 3 of portA (XXXX 1XXX) - where 'X' remains unchanged

 


Question 8b

BCF porta,5

Answer

Clears bit 5 of portA (XX0X XXXX) - where 'X' remains unchanged


Question 8c

GOTO 0004

Answer

Transfers program control to the instruction at address 0004.


Question 8d

BTSS portb,7

Answer

Test bit 7 of portB and skip the next instruction if bit 7 is set


Question 8e

BTSC portb,0

Answer

Test bit 0 of portB and skip the next instruction if bit 0 is clear


Question 8f

MOVLW 56h

Answer

Place the literal 56h (0101 0110) into the W register


Question 8g

MOVWF option

Answer

Move the contents of the W register into the option register

 


Question 8h

CLRW

Answer

Clear (set to zero) all bits of the W register

 


Question 8i

CLRF porta

Answer

Clear the contents of the Port A (assumed to be configured as an output port).


Question 8j

ANDLW FEh

Answer

Logically AND the contents of the W register with the literal FEh.


Question 8k

IORLW 01h

Answer

Logically OR the contents of the W register with the literal 01h


Question 8l

XORWF porta

Answer

Exclusive Or the contents of the W register with portA (assumed to be an input port).


Question 8m

INCF W,0

Answer

Add one to the W register.


Question 8n

DECF portb,1

Answer

Subtract one from portB (assumed to be configured as an output port).


Question 8o

NOP

Answer

No Operation instruction.  Used during program development or to pad out a program for specific execution time.


Question 8p

RETURN

Answer

Return from the sub program. The last instruction of a sub program should be this instruction (or the RETFIE instruction).


Question 8q

SUBLW 09h

Answer

Subtract W register from the literal 09h. i.e., 09h - W.


Question 8r

RRF  reg1,0

Answer

Rotate contents of reg1 right by one bit into the carry and place the result into the W register (because d=0).


Question 8s

RLF  reg1,1

Answer

Rotate the contents of reg1 left by one bit into the carry and place the result into reg1 (because d=1).


Question 8t

SWAPF option,0

Answer

Exchange upper and lower four bits (nibbles) of the option register and place the result into the W register.


Question 8u

DECFSZ count,1

Answer

Subtract one from the counter register and place the result of the subtraction into the count register.


Question 8v

DECFSZ count,0

Answer

Subtract one from the counter register and place the result of the subtraction into the W register.


Question 8w

INCFSZ count,1

 

Answer

Add one to the count register and place the result into the count register.


Question 9

Consider the following segments of PIC assembly language program and determine what they are doing:

Question 9a

BSF 
MOVLW 
MOVWF 
BCF 
STATUS,5
5Ah
TRISB
STATUS,5

Answer

5Ah = 0101 1010 in binary

This code sets up portB so that bits 7, 5, 2, and 0 are output bits. The rest are input bits


Question 9b
 

MOVLW
ANDLW
EEh
75h

Answer

Logically AND the literal value 75h with the contents of W register (EEh) giving

	1110 1110	(EEh) = W 
	0111 0101	(75h) = Literal
	0110 0100	(64h) = Result in the w register.

Question 9c

MOVF
IORLW
MOVF
porta,0
81h
porta

Answer

Logically OR the data of port A (moved into the W register for the operation) with the literal value 81h, giving:-

  
	XXXX XXXX	W
	1000 0001	literal 81h
	1XXX XXX1	The result is to set bits 7 and 0. The rest remains unchanged.
 

 


Question 9d



nxt 
MOVLW
MOVWF
DECFSZ 
GOTO 
BSF 
FFh
count
count
nxt
portb,7

Answer

FFh (1111 1111) is loaded into the register named 'count'. This value is then decremented until it reaches zero via the 'nxt' loop.

Program completes the loop 255 times before setting bit 7 of portB.


Question 9e

Convert the program fragment of question 9d into a sub-program.

Answer

delay MOVLW FFh
  MOVWF count
nxt DECFSZ count
  GOTO nxt
  BSF portb,7
  RETURN  


Question 9f

Show how the sub-program of question 9e could be used in a main program.

Answer

CALL delay

[Back to SAQ in unit 3]

[back to top]


Updated 20.06.07 ML

Site Search

Powered by Google
Site Map