Hardware Reference
In-Depth Information
The result is shown in Figure 2.15b.
Original value
New value
[A] = 10111110
C = 1
[A] = 11011111
C = 1
Figure 2.15b Execution result of rora
Example 2.23
Write a program to count the number of 0s contained in memory locations $1000,$1001
and save the result at memory location $1005.
Solution: The logical shift-right instruction is available for double accumulator D. We can load
this 16-bit value into D and shift it to the right 16 times or until it becomes 0. The algorithm of
this program is as follows:
Step 1
Initialize the loop count to 16 and the zero count to 0.
Step 2
Place the 16-bit value in D.
Step 3
Shift D to the right one place.
Step 4
If the C flag is 0, increment the zero count by 1.
Step 5
Decrement the loop count by 1.
Step 6
If the loop count is 0, then stop. Otherwise, go to step 3.
The program is as follows:
org
$1000
dc.w
$2355
zero_cnt
rmb
1
lp_cnt
rmb
1
org
$1500
clr
zero_cnt
; initialize the zero count to 0
movb
#16,lp_cnt ; initialize the loop count to 16
ldd
$1000
; place the 16-bit number in D
again
lsrd
bcs
chk_end
; branch if the lsb is 1
inc
zero_cnt
Search WWH ::




Custom Search