Hardware Reference
In-Depth Information
N
equ
20
; array count
org
$1000
; starting address of on-chip SRAM
arrmax
ds.b
1
; memory location to hold array max
org
$1500
; starting address of program
movb
array,arrmax
; set array[0] as the temporary array max
ldx
#array 1 N 2 1
; start from the end of the array
ldab
#N 2 1
; use B to hold variable i and initialize it to N 2 1
loop
ldaa
arrmax
cmpa
0,x
; compare arrmax with array[i]
bge
chk_end
; no update if max_val is larger
movb
0,x,arrmax
; update arrmax
chk_end
dex
; move the array pointer
dbne
b,loop
; decrement the loop count, branch if not zero yet
forever
bra
forever
array
db
1,3,5,6,19,41,53,28,13,42,76,14,20,54,64,74,29,33,41,45
end
2.6.6 Decrementing and Incrementing Instructions
We often need to add 1 to or subtract 1 from a variable in our program. Although we can
use one of the add or sub instructions to achieve this, it would be more efficient to use a single
instruction. The HCS12 has a few instructions for us to increment or decrement a variable by 1.
A summary of decrement and increment instructions is listed in Table 2.5.
Decrement Instructions
Mnemonic
Function
Operation
dec <opr>
deca
decb
des
dex
dey
Decrement memory by 1
Decrement A by 1
Decrement B by 1
Decrement SP by 1
Decrement X by 1
Decrement Y by 1
M
[M] − 1
A
[A] − 1
B
[B] − 1
SP
[SP] − 1
X
[X] − 1
Y
[Y] − 1
Increment Instructions
Mnemonic
Function
Operation
inc <opr>
inca
incb
ins
inx
iny
Increment memory by 1
Increment A by 1
Increment B by 1
Increment SP by 1
Increment X by 1
Increment Y by 1
[M] + 1
A [A] + 1
B [B] + 1
SP [SP] + 1
X [X] + 1
Y [Y] + 1
M
Note:
<opr> can be specified using direct, extended, or indexed addressing
modes.
Table 2.5 Summary of decrement and increment instructions
 
Search WWH ::




Custom Search