You are on page 1of 5

MP

EEE342

Assignment # 01

Name Arslan Shabeer

Registration
Number FA20-BEE-033

Subject MP

Instructor’s Name Sir Sikender Gull SB


Q1. Look at the following code segments and answer the following questions.
A. What are the values of x1 and y1 after the last instruction?
LDI y1,33 //initial value of y1
LDI x1,8 //initial value of x1
ROL x1 //Rotate left through carry here
16 is saved
ROL x1 //again it is rolled so x1=32
ADD y1,x1 // Add y1 and x1 =33+32= 65
ROR y1 // Rotate right through carry

b. How many times will ‘Loop1’ iterate before PC reaches NOP instruction in the end? Write
in a table, values of x1, y1 and temp for each iteration.
LDI x1, 5
LDI y1, 8
LDI
temp, 7
Loop1:
DEC y1
BREQ Out
CP y1, x1 // compare x1 y1
BRNE Loop1
LDI
temp,5
RJMP Loop1
Out:
NOP

First will run 3 times and then will run 5 time after RJMP. Total 8 times

Here values are saved and then decrement is used BREQ is used if Z=1 but will skip, then CP is
used for checking compare. BRNE is used if Z=0 if z= 0 then the loop will go back. If z=1 then
compare will be done and z=1 so it will skip BRNE. Rjump will move it back to loop1 and will
dec up 0
Table is given as
X1 Y1 Temp
5 8 7
5 7 7
5 6 7
5 5 7
Here Rjump is used and loop is started again.
5 4 5
5 3 5
5 2 5
5 1 5
5 0 5

Q2. Answer these short questions.

1. A number is represented in 2’s complement as 0b11110000. What is this number in


decimal notation?
Taking 2’s complement again of binary number we get,

Number = 0b00010000;

Decimal Number = 16;

2.If DDRB = 0xBD; and PORTB = Your Roll No., Indicate the status of PortB pins such as (I)nput,
(O)utput or (P)ulled up.

Roll no: 008

DDRB=0b10111101
PORTB=0b00110011.
INPUT: all the zeros show input
OUTPUT: all the 1’S shows output
Pulled up: in port B where there is 1 it is pulled down and where there is zero then it will be
pulled up.
3.How big (in bits) a PC (Program Counter) is required to access a program memory of 1
MB x 8?

20 ig (in bits) a PC (Program Counter) is required to access a program memory of 1 MB x 8.

4.Why do ‘BRNE’ like branch statements take 2 clock cycles when they branch?

I cycle for checking the Z flag


And other cycle will be used to jump

5.Which flags in the SREG will be set if following assembly commands are executed? The
effect of ‘inc’ command on SREG is shown as well.

Ldi r16, your roll number //033


Roll number
Inc r16

Zero no flag will appear.

Q3. State the contents of RAM locations 0x212 to 0x215 in a table after
the following program is executed:

(6)

LDI R28, 0x14


LDI R29, 0x02
LDI R17, 0x34
LDI
R16,
0x99
STS
0x212
, R16
LDI
R17,
0x85
ST Y, R29 //see instruction syntax at the bottom
STS 0x213, R16
AND R16, R17
STS 0x215, R16
location Value
0x212 0x99
0x213 0x99
0x215 0x81

You might also like