Anda di halaman 1dari 7

FACULTY OF ELECTRICAL ENGINEERING UNIVERSITI TEKNOLOGI MARA MICROPROCESSOR SYSTEMS (ECE365) EXPERIMENT 2 BITWISE AND BRANCH INSTRUCTIONS OBJECTIVES

1. 2. 3.

To perform bits manipulation operations involving logic and shift instructions To implement loop by using branch instructions To understand the usage of Condition Code Register

THEORY S !"# I$%#&'(#!)$% The shift instructions change the position of bits in register or memory to the left or right by one (1) place. The shift operation shifted-out bit through carry bit. supports arithmetic" logical and circular (rotate) shift. B&*$( I$%#&'(#!)$% #oop can be categori$ed into infinite and finite loop. %n infinite loop is a se&uence of instructions that the computer 'ill e(ecute forever 'hile finite loop is a se&uence of instructions that 'ill be e(ecuted for a certain number of times. #oop implementation can be realised by using branch instructions. )n general" there are t'o types of branch instructions available in bits status of CCR register. C11*12+ unconditional branching and conditional C11*12 e(amines the branching. ,hen e(ecuting conditional branch instructions" C!12

HSC+2 I$%#&'(#!)$ S,#% ds.b -efine store byte -efine store 'ord Compare the value of b The .alue is e&ual to / add accumulator a and b and store into ( add accumulator a and b and store into y 0ranch is select bits are clear al'ays e(ecute )ncrement by 1 -ecrement by 1 Rotate Right 0ranch carry set 0ranch not e&ual #ogic !hift Right #ogic !hift Right Clear dc.' cmpb be& ab( aby brclr bra inc dec ror bcs bne lsr lsrd clr -

PROCEDURE PART A- CALCULATE SUM OF N ./BIT ARRAY 1. 1nderstand and 'rite the follo'ing program.
N sum i equ org ds.b ds.b org movb movw ldab cmpb beq ld# ab# ldab ld$ ab$ s)$ i"c bra swi dc.b e"d 20 $900 2 1 $1500 #0,i #0,sum i #N do"e #arra$ 0,# sum sum i loop

; sum <- 0 ; is i N!

loop

; ; ; ;

b <- arra$%i& ' <- sum ' <- sum ( arra$%i& sum <- '

do"e arra$

1,2,*,+,5,,,-,.,9,10,11,12,1*,1+,15,1,,1-,1.,19,20

2. 2odify the program such that it computes the summation of 11" 13" 13" 14 and 15 (odd numbers) in the array. %ttach the program in the result section of your report. What type of loop that is implemented in the program? Other method can use for loop or increment i 2 times
N sum i equ org ds.b ds.b org movb movw ldab cmpb beq ld# ab# ldab ld$ ab$ s)$ i"c i"c bra swi dc.b e"d 20 $900 2 1 $1500 #0,i #0,sum i #N do"e #arra$ 0,# sum sum i i loop

; sum <- 0 ; is i N!

loop

; ; ; ;

b <- arra$%i& ' <- sum ' <- sum ( arra$%i& sum <- '

do"e arra$

1,2,*,+,5,,,-,.,9,10,11,12,1*,1+,15,1,,1-,1.,19,20

3. 2odify the program such that the loop 'ill compute summation bac6'ard. %ttach the program in the result section of your report.
N sum i equ org ds.b ds.b org movb movw ldab cmpb beq ld# de# ab# ldab ld$ ab$ s)$ dec bra swi dc.b e"d 20 $900 2 1 $1500 #N,i #0,sum i #0 do"e #arra$ 0,# sum sum i loop

; sum <- 0 ; is i = N? ;decreme") 6 ; ; ; ; b <- arra$%i& ' <- sum ' <- sum ( arra$%i& sum <- '

loop

do"e arra$

1,2,*,+,5,,,-,.,9,10,11,12,1*,1+,15,1,,1-,1.,19,20

PART B- COUNT THE NUMBER OF 0S IN +6/BIT NUMBER 1. 1nderstand and 'rite the follo'ing program.
)es)/da)a 0ero/c") loop/c") org dc.b ds.b ds.b org clr movb ldd lsrd bcs i"c dec b"e bra e"d $900 $2*,$55 ; 1,-bi) )es) da)a 1 1 $1500 0ero/c") ; i"i)iali0e )1e 0s cou") )o 0 #1,,loop/c") )es)/da)a ; place )1e "umber i" 2 ; s1i3) )1e lsb o3 2 )o )1e 4 3lag c15e"d ; is )1e 4 3lag a 0! 0ero/c") ; i"creme") 1s cou") i3 )1e lsb is a 1 loop/c") ; c1ec5 )o see i3 2 is alread$ 0 loop 3orever

loop c15e"d 3orever

2. 2odify the program such that it counts the number of /s in 32-bit number. The number is 723338812.

)es)/da)a 0ero/c") loop/c")

loop

c15e"d 3orever

org dc.w ds.b ds.b org clr movb ldx ls! !o! !o! !o! bcs i"c dec b"e bra e"d

$900 $2355,$4412 ; *2-bi) )es) da)a 1 1 $1500 0ero/c") ; i"i)iali0e )1e 0s cou") )o 0 #32,loop_cnt #$ 00 0,x ; lo"ic#l s$i%t !i"$t t$e &'(,bit 0 moves to ) %l#" 1,x ; !ot#te !i"$t wit$ t$e ) bit 2,x ; !ot#te !i"$t wit$ t$e ) bit 3,x ; !ot#te !i"$t wit$ t$e ) bit c15e"d ; bra"c1 i3 4 1 0ero/c") ; i"creme") 1s cou") i3 )1e lsb is a 1 loop/c") ; c1ec5 )o see i3 2 is alread$ 0 loop 3orever

RESULTS P*&# A+) 120+- 7d2 1202- 718 2) 120+- 798 1202- 718 3) :irst Results of+ 1202- 718 #ast Results of+ 120+- 7d2 1202- 7// P*&# B+) L*%# R,%'3#%1202- 7/5 1203- 7// 2) L*%# R,%'3#%1200- 7// 120+- 7// 1202- 7// 1203- 7// 1204- 713 1205- 7//

CONSLUSION )n conclusion" 'e are able to perform bits manipulation operations involving logic and shift instructions. ,e also are able to implement loop by using branch instructions and lastly 'e able to understand the usage of Condition Code Register.

Anda mungkin juga menyukai