Freescale mc9s08aw60 Compilation Study notes (iii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.