Freescale mc9s08aw60 Compilation Study notes (v)

Source: Internet
Author: User

Before learning the function of table check, you can use the function to realize a lot of powerful functions, such as cube table, Square table, function table, digital tube display of the Segment Code table. There is also a powerful function that is implemented by tabular and transfer directives: scatter. Scatter refers to the input data according to the different to jump to a different program entrance processing, that is, if there are many sub-programs, we can not only let them in order to execute each, but also according to the value of the data to determine the decision to jump to which sub-program. The specific way to implement the scatter is to define a contiguous storage unit as a jump table in the program, and to store the jump address of each branch handler in the order of the table. The offset address of each jump address in the table is the product of the first address of the jump table plus the number of bytes of their respective ordinal. Feel about the jump address this piece is a bit difficult to understand, use an example to illustrate:

The value range of the byte variable num is 0~3, the program entry address Pro0~pro3, and the subroutine is written, requiring that the value of num be shifted to different pro programs. If NUM is 2 then turn to Pro2. The code is as follows:

ORG $0070
Num ds.b 1

ORG $1860

PRO0:NOP, sub-program groups, all of which let them operate empty.
Rts
Pro1:nop
Rts
Pro2:nop
Rts
Pro3:nop
Rts

Sbranch: Branch program, a bit like switch in C language
LDX Num; Num-->x
LDA #05h
Mul; Num*5-->x:a
Tax; A-->x
CLRH do not forget to clear the table before you look it up.
JMP pro_tab,x

Pro_tab:; Jump table
JSR Pro0; jump to pro0,3b
Bra sb_end; Call Pro0 complete, return, 2B

JSR Pro1
Bra sb_end

JSR Pro2
Bra sb_end

JSR Pro3
Sb_end:rts

Main
Clra
Clrx
Clrh

MOV #$01,num; Sets the value of Num to be used as a judge of the selection subroutine

BSR Sbranch


Again
Nop
JMP again


ORG $fffe
DC.W Main

Careful people will find that NUM is multiplied by 5 before it is used to do the scatter, the reason is that the Pro_tab label behind the JSR instruction is 3-byte instruction, bra instruction value 2 byte instruction, so the value Num, label Pro_tab address addr_pro and instruction statement JSR Pro_ The relationship between the first address of N Addr_pro_n is:

Address_pro_n=addr_pro+num*5

is not suddenly found that the assembly of the powerful, from the beginning of the assembly to the feeling is jumping between registers to jump to become the assembly can achieve this function that function, as long as the design is delicate enough, the mind is delicate enough, even the assembly of this machine language can be full of vigor, For example: MenuetOS is an operating system written entirely in assembly language. So it runs very fast and is very small, and it can even be placed in a floppy disk. MenuetOS provides preemptive multitasking, a compelling and beautiful GUI, a TCP/IP stack for network access, and more. This shows that powerful is not a tool but a person. Of course, if a powerful tool strengthens a large person, it is inevitable that an astonishing force can erupt.

Freescale mc9s08aw60 Compilation Study notes (v)

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.