Assembly Language section and RSEG usage

Source: Internet
Author: User

Rseg is a paragraph selection instruction, to understand its meaning is to understand the meaning of paragraph.
A segment is the storage unit of a program code or data object. The program code is placed in the code snippet, and the data object is placed in the data segment. The paragraph is divided into two kinds, one is absolute paragraph, the other is the repositioning section. The absolute segment is specified in assembly language, and the address does not change when connected with L51. Used for I/O, such as accessing a fixed memory, or providing an entry address for the interrupt vector. The address of the repositioning segment is floating. Its address has the L51 to the program module connection, the decision, C51 to the source program compiles the segment which produces is the relocation segment, it all has the segment name and the storage type. Absolute paragraph has no segment name.
Having said so much, we may still not understand what the paragraph means. Don't worry, look down.
For example, you write a function in C that writes a void Test_fun (void) {...}, which exists in test.c, after compiling with the compiler. The SRC file sees:
? Pr?test_fun? TEST SEGMENT Code//(the function is placed in the snippet)
When writing this function body: rseg? Pr?test_fun? TEST//Select the code snippet that is already positioned as the current segment Test_fun:
...//code
So the expression pattern of the function is this:? PR? function name? file name
And the function name is divided into: 1: no parameter function? PR? function name? file name
2: Has the parameter function? pr?_ function name? file name
3: Re-entry function? Pr?_? function name? file name
Another example you define a global variable unsigned char data temp1,temp2; unsigned char xdata Temp3; In the test.c file, the compiler will divide 0 to multiple global data segments for each file, and global variables of the same type are stored in the same segment. So the above will be compiled as follows:
Rseg? Dt? TEST
. Temp1:ds 1
. Temp2:ds 1
;
Rseg? Xd? TEST
. Temp3:ds 1
The following is a representation of each type of data global segment
? CO? File name//constant segment
? Xd? file_name//xdata Data Segment
? Dt? file_name//data Data Segment
? ID? File_name//idata .....
? BI? file_name//BIT .....
? BA? file_name//bdata ....
? Pd? File_name//pdata .....
See here everyone should understand the meaning of paragraph. You might ask, what's the effect? It is used in assembly language when you need to write a part of the program, the function of the sink written in this question, renamed Xxx.a51, according to the above rules.
Compile just fine.
Now that we know the meaning of paragraph, let's go back to the use of SEG.
There are two types of segment selection directives in A51: Reposition segment Selection directives and absolute segment selection directives. They are used to select whether the current segment is a reposition segment or an absolute segment. Using different segment selection directives will cause the program to be positioned in a different address space.
1: The selection command for the repositioning segment is: RSEG segment name
It is used to select a repositioning segment that has been previously defined as the current segment.
The usage, like the example above, declares a function segment, followed by the function segment.
2: Absolute Segment selection Instruction
Cseg [at absolute address expression]//Absolute Code snippet
Dseg [at absolute address expression]//internal absolute data segment
Xseg [at absolute address expression]//external Absolute data segment
Iseg [at absolute address expression]//internal indirection absolute Data segment
Bseg [at absolute address expression]//absolute bit addressing segment
Their usage I give an example:
For example, we write serial interrupt program, the starting address is 0x23. Just write it like this.
Cseg at 0X23
LJMP SERIALISR
Rseg? Pr?serialisr? TEST
. SERIALISR:

Assembly Language section and RSEG usage

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.