You are on page 1of 6

Name: ________________________ Student #: ________________________

1
King Saud University
College of Engineering
Department of Electrical Engineering
EE 353 Introduction to Microprocessors
Midterm Exam I

Mark Your Section BEFORE You Start!
Section 44921 (Dr. Khaled Addoweesh; Day: 2-4; 8:00-9:50 and 8:00-8:50)
Section 5622 (Dr. Sohaib Majzoub; Day: 1-3-5, Time: 8:00-8:50)
Section 5615 (Dr. Sohaib Majzoub; Day: 1-3-5, Time: 9:00-9:50)






Instructions:

The duration of this exam is 60 minutes. Plan your time carefully!
This exam has 6 pages including this page: count them before you start!
Write your name and student number before you start.
The total points of this exam are 100 points, constituting at 20% of your final
course grade.
This is a closed-book and closed-notes exam.
Calculators are not allowed.
Cheating will not be tolerated. You will automatically get a grade of 0 and be
reported for disciplinary action.
You must show all your steps in your solution. Final answers alone might
receive no credit.

Question
Possible
Points
Your
Points
ABET
Outcomes
1 20
(h)
2 20
(e)
3 30
(c)
4 30
(k)


TOTAL 100

Name: ________________________ Student #: ________________________

2
Question 1(MSQ): [20 points]
I. The address bus in a microcontroller is:
a. A bus used to send the data from memory to the register.
b. A bus used to communicate between registers and Input/Output ports.
c. A bus used to access the data from the data memory.
d. A bus used to communicate between the instruction memory and instruction register.
II. The main difference between the program and data memory in a microcontroller is:
a. Program memory is volatile while data memory is nonvolatile.
b. Program memory is nonvolatile while data memory is volatile.
c. Program memory is equal to data memory.
d. Program memory is always inside the chip while the data memory is outside the chip.
III. What is the size of the PC in PIC24 and how many instructions can it address?
a. PC size is 24 bits, and it can address one instruction.
b. PC size is 23 bit and it can address 2
22
instructions.
c. PC size is 3 bytes and it can address 2
24
words.
d. PC size is 2 bytes and it can address 2
16
words.
IV. Machine code is usually referred to as the code:
a. produced by the assembler into hexadecimal or binary code lines.
b. produced by the operating system into octal or binary code lines.
c. produced by the user written code into decimal code lines.
d. produced by the compiler into assembly code lines.
V. Data transfer instructions are:
a. special instructions used to operate on the program memory.
b. special instructions used to copy data from/to memory and core registers.
c. special instructions used to move data from/to I/O pins.
d. None of the above.
VI. Given k=0x0F, consider the following code:
mov #0x0505,W0
inc.b k,WREG
the values of k and W0 after executing the code are

a. k = 0x10, W0 = 0x0505
b. k = 0x0F, W0 = 0x0010
c. k = 0x0F, W0 = 0x1005
d. k = 0x0F, W0 = 0x0510
VII. The goto instruction is:
a. expensive instruction because it takes two instruction cycles to finish and it takes two lines in
the instruction memory.
b. useful instruction to implement conditional jumps in the data memory.
c. useful instruction to move big chunk of instructions from one place to another.
d. None of the above.
VIII. Operation code or op-code is:
a. part of the instruction that defines the operands of the instruction.
b. part of the operation that defines the instruction code.
c. part of the machine code that defines the operand names.
d. part of the instruction that defines the operation of the instruction.
IX. In PIC24 the widths of the instruction and data memory, respectively, are:

a. 16 bits and 24 bits
b. 24 bits and 32 bits
c. 24 bits and 16 bits
d. 16 bits and 16 bits
X. mov instruction with Indirect addressing can be used to move data from:

a. register to register
b. literal to register
c. literal to memory
d. memory to memory

Name: ________________________ Student #: ________________________

3
Question 2: [20 points]

a. PIC24 has many possible addressing modes. Show in the following table the
allowed addressing modes and give an example for each case.
[12 points]
(hint: put X in the box to indicate unavailable addressing mode)

Source
Target
Literal Memory
Register
Direct
Register
Indirect
Literal





Memory





Register
Direct





Register
Indirect








b. Consider the following two instructions; write the proper change in the
memory and/or register. Justify your answer.
[8 points]

mov #0x1000, W2



mov 0x1000, W2



Justification: _______________________________




Name: ________________________ Student #: ________________________

4
Question 3: [30 points]
Assume that the memory/register contents are as shown. Show the contents of
the listed registers after the execution of each instruction of the following code
segment.

Assume that registers and memory contain the values shown at the START of
each instruction.

















Values after execution
mov #0x0800,W0 W0=

mov [W0],W2 W0=

W2=
inc.b W2,W2 W2=

add W0,[W0],W1 W0=

W1=
inc.b 0x0800 (0x0800)=

mov 0x0800,W0 W0=

sub.b W3,[W0],W3 W0=

W3=
add.b 0x0807 (0x0807)=

dec.b 0x0804 (0x0804)=

mov.b #0x00,W5 W5=

add.b 0x080D,WREG WREG=








0x0800 0x0805

0x0802

0x0102

0x0804

0x1012

0x0808

0x520A

0x080A

0x0808

0x080C

0x0005
0x0806

0x0020

W0
0x080A

W1
0x0000

W2
0x0002

W3
0x0814

W4
0x00A0

W5
0x0005

W6
0x00F0

0x080E

0x0660
Name: ________________________ Student #: ________________________

5
Question 4: [30 points]
Convert the following C code into PIC24 Assembly using the following methods:
a. Use registers to do computations and then store results in memory.
b. Do computations directly on memory locations, and keep the use of
registers to minimum.
c. Which method is faster?
(Assume memory locations 0x0800, 0x0801, and 0x0802 are used for i, j, and k
respectively)
#define avalue 10
uint8 i,j,k;

i = avalue;
i = i-1;
j = i + avalue;
j = j+1;
k = j + i - avalue;




















Name: ________________________ Student #: ________________________

6

You might also like