A small program to implement addition is given earlier, but what if the requirements become more complex and the steps become more cumbersome?? We can use subroutines to solve this problem, here is an example: if the character variables Data1 and DATA2 hold two 16-bit unsigned numbers, write a subroutine that asks for the sum of two numbers, and then store and store it in the total byte storage space. The code is as follows:
ORG $0070
Data1 ds.b 2
Data2 ds.b 2
Sum ds.b 3
ORG $1860
ADD_PRO:CLC; Empty the carry flag bit
Clrx
Clrh
Clra
MOV #$00,data1
MOV #$04,data1+1
MOV #$00,data2
MOV #$28,data2+1
LDA data1+1
Add data2+1
STA sum+2
LDA data1
ADC Data2
STA sum+1
Rola the 17th, the main operation is to move the data in register a one and put the carry flag bit into the first position in register a
and #01H
STA sum
RTS; sub-Program return instruction
Main
Clra
Clrx
BSR Add_pro; subroutine calls, directly into the subroutine, executes the subroutine program.
Again
Nop
JMP again
ORG $fffe
DC.W Main
Analysis: Two 16-bit unsigned numbers added, and 17 bits, requiring at least 3B of storage space. And because Mc9s08aw60 is stored in a big-endian way: The low address holds the most significant bytes. Therefore, the data1+1 and data2+1 are used when adding the low number of two numbers.
Freescale mc9s08aw60 Compilation Study notes (iii)