Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

INTRODUCTION TO MICROCOMPUTERS MIDTERM EXAM

Dr. Salih FADIL August 16, 2023

#1)
The following assembly program will be run on PIC16F877 microcontroller system with
Fxtall  8 MHz. Some instructions in the program are shown as Instr_i, i=1,2,..16 symbolically. Those
instructions is either BCF/SF ….., or NOP.

CBLOCK 0X070
CNT_1, CNT_2, CNT_3
ENDC

ORG 0x0000
NOP
Loop: NOP
Instr_1
Instr_2
CALL SUB_1
NOP
NOP
GOTO Loop
;*****************************************************
ORG 0xsayi_1
SUB_1: NOP
MOVLW AAh
Instr_3
Instr_4
MOVWF CNT_1
Loop_1: NOP
Instr_5
Instr_6
CALL SUB_2
NOP
NOP
Instr_7
Instr_8
DECFSZ CNT_1, F
GOTO Loop_1
NOP
ZZ: RETURN
;******************************************************
ORG 0xsayi_2
SUB_2: NOP
MOVLW BBh
Instr_9
Instr_10
MOVWF CNT_2
NOP
Loop_2: NOP
Instr_11
Instr_12
CALL SUB_3
NOP
NOP
Instr_13
Instr_14
DECFSZ CNT_2, F
GOTO Loop_2
RETURN
;*****************************************************
ORG 0x1900
SUB_3: NOP
Instr_15
Instr_16
MOVLW CCh
MOVWF CNT_3
Loop_3: DECF CNT_3, F
MOVLW 20h
XORWF CNT_3, W
BTFSS STATUS, Z
GOTO Loop_3
KK: NOP
YY: RETURN

When the program reaches the line labeled as KK active stack memory portion becomes as follows

Stack memory

Top 110Ah
0909h
Bottom 0005h

a) Determine values of sayi_1 and sayi_2 as hex numbers.


b) Determine 14-bit hex code (machine code) of CALL SUB_1 and CALL SUB_2 instructions.
c) Determine the PC content just after execution of ZZ: RETUN and YY: RETURN instructions.
d) Determine 14-bit hex code (machine code) of GOTO Loop_2 and GOTO Loop_3 instructions.
e) If there is no need to write any BCF/BSF …. instruction for any symbolic instruction Instr_i,
write NOP for in place of it. If there is only one symbolic instruction for which no BCF/BSF ….
instruction is needed to write in the symbolic instruction couple written in two consecutive
lines in the program, take the first Instr_i symbolic instruction as NOP. If both instructions in
the couple are BCF/BSF …. type, take first instruction in the couple as BCF …… . Any answer
where the above rules are not taken into consideration are given ZERO POINT.

Determine

I) Instr_1 and Instr_2,


II) Instr_3 and Instr_4,
III) Instr_5 and Instr_6,
IV) Instr_7 and Instr_8,
V) Instr_9 and Instr_10,
VI) Instr_11 and Instr_12,
VII) Instr_13 and Instr_14,
VIII) Instr_15 and Instr_16.

f) Assume that user defined GPRs CNT_1, CNT_2, CNT_3 are redefined as follows.

CBLOCK 0x070
CNT_1
ENDC
;***********************
CBLOCK 0x120
CNT_2
ENDC
;************************
CBLOCK 0x1A0
CNT_3
ENDC

Determine the following symbolic instructions by considering the rules explained in part e.

I) Instr_1 and Instr_2,


II) Instr_3 and Instr_4
III) Instr_5 and Instr_6
IV) Instr_7 and Instr_8
V) Instr_9 and Instr_10
VI) Instr_11 and Instr_12
VII) Instr_13 and Instr_14
VIII) Instr_15 and Instr_16

g) How many memory locations does subroutine SUB_3 occupy in the system memory?
h) Calculate processing time for subroutine SUB_3.
i) If Instr_11 and Instr_12 are erased from the program, determine the instruction to which the
program jumps after execution of CALL SUB_3.

#2)
Consider hex code (machine code) of an assembler program part written for a PIC16F877
microcontroller system.

CBLOCK 0x070
CNT
ENDC

ORG 0x0000

11 0000 1111 1111


00 0000 1111 0000
00 0000 0000 0000
00 0011 1111 0000
11 0000 0010 0000
00 0110 0111 0000
01 1101 0000 0011
10 1000 0000 0010
00 0000 0000 0000

Space characters in 14-bit hex codes are inserted just to increase the readability.

a) Write the assembler program corresponding the above hex code.


b) What is the content of CNT after processing of the last instruction in the program?
c) Assume that “0” written as bold face in the sixth instruction is changed with “1”, what is the
content of CNT after the second processing of the sixth instruction in the program?

#3) Consider the following hardware and the software associated with it.

CBLOCK 0x070
TMP, CNT0, CNT1, Time
ENDC

ORG 0x0000
NOP
GOTO Main
ORG 0x0004
GOTO ISR
Main: NOP
BANKSEL TRISB
MOVLW F0h
MOVWF TRISB
BCF TRISC, 0
MOVLW b’00000111’
MOVWF OPTION_REG
;**************************************
BANKSEL PORTB
BCF PORTB, 0
BCF PORTC, 0
;**************************************
CLRF INTCON
BSF INTCON, RBIE
BSF INTCON, GIE
;*************************************************
CLRF TMP
CLRF CNT0
AA: CLRF CNT1
CLRF Time
;*************************************************
Loop: NOP
NOP
NOP
GOTO Loop
;*************************************************
ISR: NOP
BTFSC INTCON, RBIF
GOTO Keys
BTFSC INTCON, T0IF
GOTO Measure
GOTO Son
;***************************************************
Keys: BANKSEL PORTB
MOVF PORTB, W
MOVWF TMP
BTFSS TMP, 4
GOTO Key_4
BTFSS TMP, 5
GOTO Key_5
BTFSS TMP, 6
GOTO Key_6
BTFSS TMP, 7
GOTO Key_7
GOTO Son
;************************************************
Key_4: BCF INTCON, RBIE
BANKSEL TMR0
CLRF TMR0
BB: BSF PORTC, 0
BSF INTCON, T0IE
;##################################
MOVLW .5
MOVWF Time
;##################################
GOTO Son
;*******************************************************
Key_5: BCF INTCON, RBIE
BANKSEL TMR0
CLRF TMR0
BSF PORTC, 0
BSF INTCON, T0IE
;##################################
MOVLW .10
MOVWF Time
;##################################
GOTO Son
;*******************************************************
Key_6: BCF INTCON, RBIE
BANKSEL TMR0
CLRF TMR0
BSF PORTC, 0
BSF INTCON, T0IE
;##################################
MOVLW .15
MOVWF Time
;##################################
GOTO Son
;****************************************************
Key_7: BCF INTCON, RBIE
BANKSEL TMR0
CLRF TMR0
BSF PORTC, 0
BSF INTCON, T0IE
;##################################
MOVLW .20
MOVWF Time
;##################################
GOTO Son
;*****************************************************
Measure: NOP
;###########################################
INCFSZ CNT0, F
GOTO Son
INCF CNT1, F
MOVF Time, W
SUBWF CNT1, W
BTFSS STATUS, Z
GOTO Son
BANKSEL PORTC
BCF PORTC, 0
CLRF CNT1
BCF INTCON, T0IE
BSF INTCON, RBIE
;#################################################
Son: BCF INTCON, T0IF
BCF INTCON, RBIF
RETFIE

a) What are the interrupt events that are used in this system?
b) Is any interrupt recognized if no key is pressed initially in this system?
c) If the user pushes Key_4 after power on reset in the system, say at time t=0. What happens?
d) If the user pushes Key_4 after power on reset in the system, say at time t=0. After 1 minute
later, he pushes Key_5. What happens?
e) If the user pushes Key_6 after power on reset in the system, say at time t=0. After 5 minutes
later, he pushes Key_7. What happens?
f) What are the number of active stack locations when the program reaches at point labelled as
AA and BB.

You might also like