Analyze align usage

Source: Internet
Author: User
After analyzing the usage of align, I decided to carefully analyze the u-boot code, but it was first reported. balignl160xdeadbeef is difficult. Fortunately, google found the article "analysis of align usage", which is well written by the Author. after reading this article, I wrote according... after analyzing the usage of align, I decided to carefully analyze the u-boot code, but it was ". balignl 16 0xdeadbeef "is difficult, but fortunately, google has found the article" analyze the usage of align ", which is well written by the Author. after reading it, based on my experiment results, I made appropriate changes to make myself more clear and record it as follows: www.2cto.com. align is used for align. how is align aligned? Next, let's analyze (1) $ vim align1.s. edit the following code in the new file: _ start: B reset. byte 0x55. byte 0 xaareset: ldr r0, = 0x53000000 save, and then run the following command: $ arm-linux-as align1.s-o align1.o, some compilers may report errors, however, my compiler does not report an error. although no error is reported, the results of the disassembly show that problems will certainly occur during the runtime. Run the following command at www.2cto.com: $ arm-linux-objdump-d align1.o: 00000000 <_ start>: 0: ea000000 B 4 <_ start + 0x4> 4: 010000aa55 ldreqb s1, [r3],-#264500000006 : 6: e3a00453 mov r0, #1392508928; 0x53000000 is obvious. the jump statement should jump to 0x06, but it jumps to 0x04. let's analyze it. First, the ARM commands are all 32-bit. here, the 4-byte (one word) alignment is required, and the B reset command occupies 4 bytes. then we use it. the byte command defines two constants. because this is a byte type, only eight bits are occupied, and two bits are occupied. Because the connector contains a program address counting pointer, which stores the current address, this address pointer is required by the connector's internal work. we just need to understand that there is such a mechanism. If _ start is from 0x00, the first command occupies 4 bytes, and then two bytes are allocated consecutively. the current address pointer should be 0x06, then the problem arises. next command, that is, the ldr command at the reset mark is an ARM command, which requires four bytes to be aligned. the current address is 0x06 and cannot meet this requirement, therefore, the compiler automatically redirects the address pointer to 0x04. The solution is simple. we only need to add one. the align command solves the _ start: B reset. byte 0x55. byte 0xaa. alignreset: ldr r0, = 0x53000000. the compilation result is: 00000000 <_ start>: 0: ea000000 B 8. 4: g0aa55 andeq sl, r0, r5, asr sl00000008 : 8: e3a00453 mov r0, #1392508928; 0x53000000 is automatically zero after two. byte commands until the address requirements are met. Here, the address is accumulated to 0x08, which meets the ARM instruction requirements. therefore, write the next instruction here. This is the basic content. let's take a look at other things (II). align 5. here is just an example. what is the meaning of "5" after "align 5? This command is available in uboot. Let's continue the experiment and see what the compilation result is. _ start: B reset. align 5. byte 0x55. align 5. byte 0xaa. alignreset: ldr r0, = 0x53000000 compilation result: 00000000 <_ start>: 0: ea00000f B 44 ... 20: 00000055 andeq r0, r0, r5, asr r0... 40: 1000000aa andeq r0, r0, sl, lsr #100000044 : 44: e3a00453 mov r0, #1392508928; 0x53000000 we found that the compilation result was a bit interesting. this address allocation went up all at once, but it was not difficult. just analyze it and you will be OK, let's look at the 20 and 40. here is the hexadecimal system, that is, 32 and 64. It is easy to think that what we do here is a power operation, that is, the align 5 alignment address is 2 ^ 5 = 32, and all the previous addresses are filled with zero. Www.2cto.com (3 ). balignl 16, 0xdeadbeef_start: B reset. balignl 53000000, 0 xdeadbeef reset: ldr r0, = 0 x there is such a statement when reading uboot. I checked the as manual for half a day and found it ,? Why? ? Dizzy? Why is chicory dizzy? Yi Qiang pure lips ?? /Div> 00000000 <_ start>: 0: ea000002 B 10 4: deadbeef cdple 14, 10, cr11, cr13, cr15, {7} 8: deadbeef cdple 14, 10, cr11, cr13, cr15, {7} c: deadbeef cdple 14, 10, cr11, cr13, cr15, {7} 00000010 : 10: e3a00453 mov r0, #1392508928; 0x53000000, you can see that this command is to fill in the deadbeef string, fill in a total of 16 alignment of the address to refer to, you can see above, enter 0x10, that is, 16.

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.