Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
amor
PostPosted: Aug 15, 2007 - 02:34 AM
Rookie


Joined: Oct 17, 2006
Posts: 29
Location: Turkey

Hi,
i don't understand why is it give warning?

Quote:
warning: .cseg .db misalignment - padding zero byte


my code:
Code:


prompt1:   .db      "Yuksek voltaj hatasi!", null
prompt2:   .db      "voltaj = ", null
[b]=>[/b]prompt5:   .db      "Dusuk voltaj hatasi!", null
prompt4:   .db      "Yuksek sicaklik hatasi!", null

voltajyazi:
      ldi      ZH,high(2*prompt2)   
      ldi      ZL,low(2*prompt2)
      rcall   PrStr
      ret
volyukprompt:
      ldi      ZH,high(2*prompt1)   
      ldi      ZL,low(2*prompt1)
      rcall   PrStr
      ret
voldusprompt:
      ldi      ZH,high(2*prompt5)   
      ldi      ZL,low(2*prompt5)
      rcall   PrStr
      ret
sicyukprompt:
      ldi      ZH,high(2*prompt4)   
      ldi      ZL,low(2*prompt4)
      rcall   PrStr
      ret
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Aug 15, 2007 - 04:25 AM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13828
Location: Vancouver, BC

The memory reserved with .db must be an even number of bytes. One or more of your strings must be an odd number of bytes, so the assembler padded it with an extra byte.

_________________
Regards,
Steve A.

The Board helps those that help themselves.


Last edited by Koshchi on Aug 15, 2007 - 04:26 AM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Aug 15, 2007 - 04:25 AM
10k+ Postman


Joined: Feb 19, 2001
Posts: 25901
Location: Wisconsin USA

A thread from a Forum search on "misalignment":
http://www.avrfreaks.net/index.php?name ... mp;t=27905

Mike B wrote:
This is what is happening. The AVR flash application program memory is 16 bits wide. Each byte is 8 bits wide, so you can also say the application program memory is 2 bytes wide (16 divided by 8 ). Two bytes together is also known as a 16 bit word.

When you use .db to place bytes in the flash application program memory, it takes two bytes to fill each word (each word has its own unique address). If you only specify an odd number of .db bytes, the assembler will pad your odd count with an extra zero byte (the assembler just happened to use zero for the value, it has nothing to do with strings). When you get the assembler warning message it pads your 21 bytes to 22 bytes to make it fit evenly into the 16 bit application flash memory words. If you do not want to see the warning message, you can add your own extra zero byte. In either case, you can go ahead and use the zero byte to terminate your string.

The newer versions of the assembler should pad the extra even byte correctly, without causing any problems.


From the AVR Assembler User's Guide:
Quote:
DB - Define constant byte(s) in program memory and EEPROM
The DB directive reserves memory resources in the program memory or the EEPROM memory. In order to be able to refer to the reserved locations, the DB directive should be preceded by a label. The DB directive takes a list of expressions, and must contain at least one expression. The DB directive must be placed in a Code Segment or an EEPROM Segment.

The expression list is a sequence of expressions, delimited by commas. Each expression must evaluate to a number between -128 and 255. If the expression evaluates to a negative number, the 8 bits twos complement of the number will be placed in the program memory or EEPROM memory location.

If the DB directive is given in a Code Segment and the expressionlist contains more than one expression, the expressions are packed so that two bytes are placed in each program memory word. If the expressionlist contains an odd number of expressions, the last expression will be placed in a program memory word of its own, even if the next line in the assemby code contains a DB directive. The unused half of the program word is set to zero. A warning is given, in order to notify the user that an extra zero byte is added to the .DB statement

 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Aug 15, 2007 - 05:36 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20347
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

Code:
"Dusuk voltaj hatasi!", null
Ther are 20 characters in the string plus the null makes it 21, so the assembler makes it even by putting an extra null at the end as explained above.

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
amor
PostPosted: Aug 15, 2007 - 01:50 PM
Rookie


Joined: Oct 17, 2006
Posts: 29
Location: Turkey

i understand very good:). thanks guys
now, it is ok
Code:
"Dusuk voltaj hatasi! ", null
 
 View user's profile Send private message  
Reply with quote Back to top
4RESTER
PostPosted: May 01, 2013 - 09:48 AM
Newbie


Joined: May 24, 2009
Posts: 10
Location: Ukraine

How to switch off into the AVRASM2 the automatic padding by $00?
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
clawson
PostPosted: May 01, 2013 - 10:05 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

How to switch off into the AVRASM2 the automatic padding by $00?


You cannot - opcodes must be word aligned so if the byte length of the data is odd then it must be padded so that it regains even alignment. If you have lots of data with "holes" then consider re-arranging the data storage.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
4RESTER
PostPosted: May 01, 2013 - 11:06 AM
Newbie


Joined: May 24, 2009
Posts: 10
Location: Ukraine

clawson wrote:
Quote:

How to switch off into the AVRASM2 the automatic padding by $00?


You cannot - opcodes must be word aligned so if the byte length of the data is odd then it must be padded so that it regains even alignment. If you have lots of data with "holes" then consider re-arranging the data storage.

For the storage datas into the Flash (CSEG) to access via the LPM. Like this:
Code:
l_LookUp_1: .DB $DE,$AD,$BE  ;<=- unwanted padding !!!
            .DB $EF          ;<=- unwanted padding !!!
            .DB $AA,$0F,$55  ;<=- unwanted padding !!!
            .DB $F0          ;<=- unwanted padding !!!

That's very bad, that imposible to turn off the padding.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
clawson
PostPosted: May 01, 2013 - 11:35 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England

Code:
 l_LookUp_1: .DB $DE,$AD,$BE, $EF, $AA,$0F,$55, $F0

No padding Wink

(and in general just put an even number of bytes in each .db).

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
4RESTER
PostPosted: May 01, 2013 - 06:10 PM
Newbie


Joined: May 24, 2009
Posts: 10
Location: Ukraine

clawson wrote:
Code:
 l_LookUp_1: .DB $DE,$AD,$BE, $EF, $AA,$0F,$55, $F0

No padding Wink

(and in general just put an even number of bytes in each .db).

In single line.

What about it?

Code:
l_LookUp_1: .DB $DE,$AD,$BE  ;<=- unwanted padding !!!
            .DB $DE,$AD,$BE  ;<=- unwanted padding !!!
l_LookUp_2: .DB $AA,$0F,$55  ;<=- unwanted padding !!!
            .DB $DE,$AD,$BE  ;<=- unwanted padding !!!

Code:
.CSEG
.ORG $00F0
txt_OK:      .DB   "OK",0
txt_ERROR:   .DB   "ERROR",0
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
clawson
PostPosted: May 01, 2013 - 06:36 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

In single line.

What about it?

No the only requirement is that each line have an even number of bytes:
Code:
l_LookUp_1: .DB $DE,$AD,$BE, $DE
            .DB $AD,$BE
l_LookUp_2: .DB $AA,$0F,$55, $DE
            .DB $AD,$BE

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: May 01, 2013 - 08:23 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18545
Location: Lund, Sweden

If you really want to arrange your code textually with odd number of bytes per line I believe that you can use the "line continuation symbol":

Code:
l_LookUp_1: .DB $DE,$AD,$BE, \
                $EF,         \
                $AA,$0F,$55, \
                $F0


The important thing is that each DB has an even number of bytes. Not each line.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
4RESTER
PostPosted: May 01, 2013 - 09:30 PM
Newbie


Joined: May 24, 2009
Posts: 10
Location: Ukraine

JohanEkdahl wrote:
If you really want to arrange your code textually with odd number of bytes per line I believe that you can use the "line continuation symbol":

Code:
l_LookUp_1: .DB $DE,$AD,$BE, \
                $EF,         \
                $AA,$0F,$55, \
                $F0


The important thing is that each DB has an even number of bytes. Not each line.


This work with the values, but not working with the text datas Crying or Very sad
Code:
.ORG $00F0
txt_OK:      .DB   "OK",0, \
txt_ERROR:   .DB   "ERROR",0
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
js
PostPosted: May 01, 2013 - 11:47 PM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20347
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

But with the above text a padding byte makes NO difference to you.

You can't use the line termination if you have a new label in the next line.

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
JohanEkdahl
PostPosted: May 02, 2013 - 09:21 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18545
Location: Lund, Sweden

Quote:

This work with the values, but not working with the text datas
Code:
.ORG $00F0
txt_OK:      .DB   "OK",0, \
txt_ERROR:   .DB   "ERROR",0


No, of-course not. The continuation character is merely a way to make your code text look better. For the assembler, the above attempt is equivalent to
Code:
.ORG $00F0
txt_OK:      .DB   "OK",0, txt_ERROR:   .DB   "ERROR",0

which of-course is bad code.

The bottom line, stated several times in this thread already, is that every DB has to have an even number of bytes in it, or you will get the warning.

Above you have two DBs and must see to it that each of them has an even number of bytes. There is no way around it, so you must:
Code:
txt_OK:      .DB   "OK",0
txt_ERROR:   .DB   "ERROR",0
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
joeymorin
PostPosted: May 02, 2013 - 11:53 PM
Hangaround


Joined: Jul 17, 2012
Posts: 428


4RESTER wrote:
That's very bad, that imposible to turn off the padding.
I think perhaps you are under the mistaken notion that this is a limitation of the assembler (or the linker). It is not. In AVR, instructions are 16-bit words, and all references to flash (in the context of instructions) are with word addresses. It is impossible to cause an AVR to execute code from an odd byte address, as that would be in the middle of an instruction word. The assembler knows this and is simply enforcing the restrictions imposed by the hardware.

JJ
 
 View user's profile Send private message  
Reply with quote Back to top
4RESTER
PostPosted: May 03, 2013 - 03:42 AM
Newbie


Joined: May 24, 2009
Posts: 10
Location: Ukraine

joeymorin wrote:
4RESTER wrote:
That's very bad, that imposible to turn off the padding.
I think perhaps you are under the mistaken notion that this is a limitation of the assembler (or the linker). It is not. In AVR, instructions are 16-bit words, and all references to flash (in the context of instructions) are with word addresses. It is impossible to cause an AVR to execute code from an odd byte address, as that would be in the middle of an instruction word. The assembler knows this and is simply enforcing the restrictions imposed by the hardware.

JJ

LPM adressing as 8-bits bytes (not by 16-bits words).
I wont to know how to bypass limitation of AVRASM2 to control padding/no padding.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
joeymorin
PostPosted: May 03, 2013 - 03:55 AM
Hangaround


Joined: Jul 17, 2012
Posts: 428


4RESTER wrote:
LPM adressing as 8-bits bytes (not by 16-bits words).
I wont to know how to bypass limitation of AVRASM2 to control padding/no padding.
LPM is for accessing data contained in flash.

Look at it this way: Imagine you had a single DB with an odd number of bytes. If the assembler didn't pad to an even number of bytes, then the instruction that follows the data contained in the DB would span a word boundary. The cpu cannot jump to or execute and instruction that is not word-aligned. Were the assembler or linker to generate code that had instructions offset by a single byte in this fashion, the cpu would basically be executing invalid and random code. Padding an odd-byte DB to an even number of bytes is the only way to fix this.

If you need every last byte, you'll have to store multiple data objects together in a single DB and manage the addressing yourself.

Perhaps an assembler expert can suggest a way to convince the assembler to pad only the last in a series of adjacent DBs, but to my knowledge that is not possible.

JJ
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: May 03, 2013 - 04:20 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20347
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

Quote:
to control padding/no padding.
You CANNOT DO IT as explained above, just make sure that you have an EVEN number of data bytes, if not then the assembler will pad it for you wether you like it or not. Smile

edit example of how to put things together to even out bytes
Code:
CHAR_GEN:

;Space !
.db   0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x04,0x04,0x04,0x04,0x04,0x00,0x04
2 by 7 bytes data combined for an even number of bytes (14).
Code:
;2 tables together to stop addition of padding bytes
   .db    6 , 62 , 58 , 50 , 38 , 24 , 9   ,   6 , 50 , 48 , 41 , 31 , 20 , 7
   .db    6 , 41 , 39 , 33 , 26 , 16 , 6 ,   6 , 34 , 31 , 28 , 21 , 13 , 5
   .db    4 , 41 , 35 , 23 , 9 ,            4 , 33 , 29 , 19 , 7
   .db    4 , 27 , 24 , 15 , 6 , 0
2 sinewave tables of different amplitude together, only the last unused byte is padded by a zero.

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
JohanEkdahl
PostPosted: May 03, 2013 - 08:18 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18545
Location: Lund, Sweden

Quote:

I wont to know how to bypass limitation of AVRASM2 to control padding/no padding.

The how: YOU CAN'T. Period.

The why: Reread everything above.

Quote:

LPM adressing as 8-bits bytes (not by 16-bits words).

This can be debated. You could just as well see it as the Z register having all but its lowest bit used as a flash address (addressed in words), and the lowest bit then selects what byte from the read word to pick. It is even likely that this is how it actually works. A whole word is read from flash to the CPU, and then (internal to the CPU) LSB of the Z register is then used to pick the high or low byte out of this word.

Anyway, the bottom line is: You just can't disable the padding. Live with it, and move on..
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits