You are on page 1of 4

EE273 Microprocessor Systems —– Mid Term Solution

Oct 30, 2019


Time Allowed: 60 minutes Maximum Marks: 30

Student Name: ————— Section: —————


Roll No.: ——————

Question 1: (10)
Covert the following assembly program, without altering its functioning, to equivalent IT (IF-
THEN) block based assembly program. What will be the result stored in R3 if R0 = -10, R1
= 2, R2 = 5. Hint: Try to convert it into equivalent C-code first.
AREA |. text | , CODE , READONLY , ALIGN =2
ENTRY
EXPORT __main
__main
; For straight line equation ( y = mx + c), Suppose
; R0 is representing slope of the line (m)
; R1 is representing y - intercept of the line (c)
; R2 is representing variable x
; R3 is representing variable y

CMP R0 , #0
BLT Block1
MLA R3 , R0 , R2 , R1

B STOP

Block1
MLS R3 , R0 , R2 , R1
LSL R3 , R3 , #3

Stop
B Stop
END

Solution:
AREA |. text | , CODE , READONLY , ALIGN =2
ENTRY
EXPORT __main
__main
; For straight line equation ( y = mx + c), Suppose
; R0 is representing slope of the line (m)
; R1 is representing y - intercept of the line (c)
; R2 is representing variable x
; R3 is representing variable y

CMP R0 , #0
ITEE LT
MLALT R3 , R0 , R2 , R1
MLSGE R3 , R0 , R2 , R1
LSLGE R3 , R3 , #3

; IF R0 = -10 , R1 =2 , R2 =5 , THEN R3 =52

Stop
B Stop
END

Question 2: (10)
2
Write an ARM Assembly code subroutine to find the root of the equation f (x) : x − 4 = 0
using the bisection method having initial value l = 0, m = 8. Bisection method is a nemerical
method to find a root of a function. Pseudocode of bisection method is given below. You may
use any approach (recursive/non recurcive) to implement the following subroutine.

given equation f (x) = 0 , initial bracket, [l m] suchthatl < u, l ≤ p∗ , m ≥ p∗


repeat
l+m
1. C = 2

2. Solve equation f (x) = 0 at x = c


3. If ( f (c) < 0 ), l = c , else m = c
until (( f (a) 6= 0 ) && ( f (b) 6= 0 ))

Solution:
AREA |. text | , CODE , READONLY , ALIGN =2
ENTRY
EXPORT __main
__main
LDR R0 , = X
MOV R0 , #0 ; R0 = a
MOV R1 , #8 ; R1 = b

loop
; find f(a ) = a ^2 - 4
MUL R3 , R0 , R0
SUB R3 , R3 , #4 ; R3 = f(a ) = a ^2 - 4
CMP R3 , #0
BEQ ANSWERisA ; if f (a) = 0, STOP ITERATING , ROOT =a

; find f(b ) = b ^2 - 4
MUL R3 , R1 , R1
SUB R3 , R3 , #4 ; R3 = f(b ) = b ^2 - 4
CMP R3 , #0
BEQ ANSWERisB ; if f (b) = 0, STOP ITERATING , ROOT =b

; Finding c
ADD R2 , R1 , R0 ; c = a +b
ASR R2 , R2 , #1 ; c = ( a+b )/2
; find f(c ) = c ^2 - 4
MUL R3 , R2 , R2
SUB R3 , R3 , #4 ; R3 = f(c ) = c ^2 - 4

CMP R3 , #0

BLT if_condition ; if f( c ) <0 , go to if and replace a with c


MOV R1 , R2 ; else , replace b with c

B loop ; go back to loop

if_condition
MOV R0 , R2
B loop

ANSWERisA
MOV R5 , R0
B STOP

ANSWERisB
MOV R5 , R1
B STOP
STOP
B STOP
END

Question 3: (5)
A microprocessor executes single instruction in 2 clock cycles. Its non-pipelined architecture
version takes 200 clock cycles to execute a test program with 100 instructions. How many
clock cycles will be required to execute the same test program on its pipelined version? The
pipelined version of the processor is implemented by dividing a single instruction to three stages
(phases) and each stage takes one clock cycle. Moreover test program does not include branch
instructions that can cause pipeline flushing and refilling.

Solution: Now it wil take 102 (3+99) clock cycles. First instruction will be executed after 3
clock cycles, then after each clock cycle, next instruction will be executed.
Question 4: (5)
Eight bytes 0x12, 0x34, 0x56, 0x7A, 0x90, 0xC0, 0xDF, 0x01 are stored at contiguous memory
locations in order of increasing address as shown below. Assuming that these bytes constitutes
two 32-bit words in little Endian format. Now what will the 32-bit values loaded in registers
R1 and R2 when the given instructions will be executed?

Address Contents
0x000002E0 0x12
0x000002E1 0x34
.. ..
. .
0x000002E7 0x01

Solution:
AREA |. text | , CODE , READONLY , ALIGN =2
ENTRY
EXPORT __main
__main

LDR R0 , =0 x000002E0
LDR R1 , [ R0 ] , #4 ; R1 = 0 x7A563412
LDR R2 , [ R0 ] ; R2 = 0 x01DFC090

Stop
B Stop
END

You might also like