Andes Workshop

It is currently Mon Dec 05, 2022 6:07 pm

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: force array aligned on 1-byte address
PostPosted: Wed Jan 22, 2014 5:00 pm 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
If a user write a program array-test.c

Code:
unsigned char array1[2]={0x77,0x88};
unsigned char array2[3]={0x11,0x22,0x33};


assemble it

nds32le-elf-gcc -S array-test.c

.file 1 "array-test.c"
.abi_2
.section .mdebug.abi_nds32
.previous
.section .note.nds32, "", @progbits
.string "'-mlib=mculib' '-static' '-S'"
.previous
.globl array1
.data
.align 2
.type array1, @object
.size array1, 2
array1:
.byte 119
.byte -120
.globl array2
.align 2
.type array2, @object
.size array2, 3
array2:
.byte 17
.byte 34
.byte 51
.ident "GCC: (2013-09-24) 4.4.4"

Note the ".align 2" represents it is aligned on 4-byte address.
This situation only happens in BSP v3.2.0, BSP v4.0.0 is aligned on 1-byte address.

The objdump of array-test.o is

$ nds32le-elf-gcc -c array-test.c

hylai@APC187 /cygdrive/d/Andestech/AndeSight201MCU/mcu/workspace2/array-test/src

$ nds32le-elf-objdump.exe -s array-test.o

array-test.o: file format elf32-nds32

Contents of section .data:
0000 77880000 11223300 w...."3.
Contents of section .note.nds32:
0000 272d6d6c 69623d6d 63756c69 62272027 '-mlib=mculib' '
0010 2d737461 74696327 20272d63 2700 -static' '-c'.
Contents of section .comment:
0000 00474343 3a202832 3031332d 30392d32 .GCC: (2013-09-2
0010 34292034 2e342e34 00 4) 4.4.4.

------------------

To avoid this waste of space, we can change the align of this array.
Syntax:
Code:
__attribute__((aligned(1))) unsigned char array1[2]={0x77,0x88};
__attribute__((aligned(1))) unsigned char array2[3]={0x11,0x22,0x33};


The assembly code:
Code:
   .file   1 "array-test2.c"
   .abi_2
   .section   .mdebug.abi_nds32
   .previous
   .section   .note.nds32, "", @progbits
   .string      "'-mlib=mculib' '-static' '-S'"
   .previous
   .globl   array1
   .data
   .type   array1, @object
   .size   array1, 2
array1:
   .byte   119
   .byte   -120
   .globl   array2
   .type   array2, @object
   .size   array2, 3
array2:
   .byte   17
   .byte   34
   .byte   51
   .ident   "GCC: (2013-09-24) 4.4.4"



This objdump:
$ nds32le-elf-gcc -c array-test2.c

hylai@APC187 /cygdrive/d/Andestech/AndeSight201MCU/mcu/workspace2/array-test/src

$ nds32le-elf-objdump.exe -s array-test2.o

array-test2.o: file format elf32-nds32

Contents of section .data:
0000 77881122 33 w.."3
Contents of section .note.nds32:
0000 272d6d6c 69623d6d 63756c69 62272027 '-mlib=mculib' '
0010 2d737461 74696327 20272d63 2700 -static' '-c'.
Contents of section .comment:
0000 00474343 3a202832 3031332d 30392d32 .GCC: (2013-09-2
0010 34292034 2e342e34 00 4) 4.4.4.


Note: Users must follow the alignment rule. ex. a integer is four bytes, and it is aligned in 4-byte boundary.


Top
 Profile Send private message E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group