$E000 $E01F Answer $0900: Sum Odd Numbers in Array From 0xe000 To 0Xe01F Treat Numbers As 8 Bit Unsigned Numbers
$E000 $E01F Answer $0900: Sum Odd Numbers in Array From 0xe000 To 0Xe01F Treat Numbers As 8 Bit Unsigned Numbers
4 0xE000
5
1
8
6
11
0xE01F
1
EE 308 Spring 2002
4 0xE000
START 5
1
8
6
Init
11
Process
Entries
Save
Answer
Done
0xE01F
2
EE 308 Spring 2002
4 0xE000
START Init
5
1
8
Addr −> 6
Init
Pointer 11
Process
Entries 0 −> Sum
Save
Done
Answer
Done
0xE01F
3
EE 308 Spring 2002
4 0xE000
START Init
5
1
8
Addr −> 6
Init
Pointer 11
Process
Entries 0 −> Sum
Save
Done
Answer
Done
0xE01F
Pointer: X or Y −− use X
4
EE 308 Spring 2002
Process X −> 4
Init 0xE000
START Entries 5
loop: 1
8
Addr −> Get 6
Init Num
Pointer 11
Process
Entries 0 −> Sum Yes
Even?
Save No
Done
Answer
Add Num
to Sum
Done even:
Inc
Pointer
0xE01F
Yes More
to do?
No
Init
5
EE 308 Spring 2002
More details: How to tell if number is odd, how to tell when done
Process
Entries 0 −> Sum
Yes
Even?
Save No
Done
Answer
Add Num
to Sum
Done even:
Inc
Pointer 0xE01F
How to test if even?
LSB = 0 − check LSB of memory
6
EE 308 Spring 2002
loop:
Addr −>
Init LDX #ARRAY Get
Pointer Num LDAB 0,X
Process
Entries 0 −> Sum LDY #0
Yes
Even? BRCLR 0,X,$01,even
Save
Done No
Answer
Add Num
to Sum ABY
Done
even:
Inc
How to test if even? Pointer INX
LSB = 0 − check LSB of memory
BRCLR 0,X,$01,even
Yes More CMPX #ARRAY_END
to do? BLO loop
How to check if more to do?
If X < 0xE020, more to do. No
BLO loop
Init
0xE01F ARRAY_END
7
EE 308 Spring 2002
Write program
8
EE 308 Spring 2002
Note that the assembler output shows the op codes which the assembler generates for the
HC12.
9
EE 308 Spring 2002
Note that the map file shows you where your code and data will go, and how much room they
will take.
Map of sumodds.h12 from link file sumodds.lkf - Thu Jan 31 21:19:43 2002
Segments:
Modules:
sumodds.o:
start 00000000 end 0000011e length 286 section .debug
start 00000800 end 00000818 length 24 section CODE
start 00000900 end 00000902 length 2 section DATA
.11 00000000
.12 00000008
.13 00000013
answer 00000900
array 0000e000
data 00000900
len 00000020
loop 00000806
prog 00000800
skip 0000080e
Symbols:
10
EE 308 Spring 2002
11
EE 308 Spring 2002
0x09F9
A B
0x09FA
D
0x09FB
0x09FC X
0x09FD
Y
0x09FE
0x09FF SP
0x0A00
PC
0x0A01
0x0A02 CCR
0x0A03
12
EE 308 Spring 2002
Stack Pointer:
0x09F5
CODE: section .text
0x09F6 org 0x0800
0x09FD pulx
pula
0x09FE
0x09FF A
0x0A00
X
SP
13