Hardware Reference
In-Depth Information
done swi ; return to D-Bug12 monitor
; the array is defined in the following statement
array
db
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
end
It is a common mistake for an assembly language programmer to forget about updating the
variable in memory. For example, we will not get the correct value for sum if we did not add the
instruction sty sum in the program of Example 2.14.
Loop primitive instructions are especially suitable for implementing the “repeat S until C“
looping construct, as demonstrated in the following example:
Example 2.15
Write a program to find the maximum element from an array of N 8-bit elements using the
“repeat S until C” looping construct.
Solution: We will use the variable i as the array index and also as the loop count. The variable max_val
will be used to hold the array maximum. The logic flow of the program is shown in Figure 2.10.
The program is as follows:
Start
max_val
array[0]
N − 1
No
max_val < array[i] ?
Yes
max_val array[i]
i i − 1
No
i = 0?
Yes
Stop
Figure 2.10 Logic flow of example 2.15
 
Search WWH ::




Custom Search