electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

8 bit declaration in 32 bit controllers


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> 8 bit declaration in 32 bit controllers
Author Message
saudrehman



Joined: 20 Dec 2005
Posts: 46
Helped: 1


Post16 Aug 2006 6:35   

bit declaration


Suppose i am using a 32 bit controller in which each memory location is 16 bits long.
if i declare an unsigned char variable of 8 bytes then how is it interpreted by compiler?
Does it have any meaning or by default it shall allocate 2 bytes?
Back to top
Google
AdSense
Google Adsense




Post16 Aug 2006 6:35   

Ads




Back to top
jan noha



Joined: 10 Dec 2002
Posts: 32
Helped: 1


Post16 Aug 2006 20:26   

8 bit declaration


As far as I know, sizeof(char) == sizeof(unsigned char) == 1 Byte. It is directly stated somewhere in C language norm, where - if I remember it correctly - char/uchar is the only type defined by its size. (Another types are defined with the help of "<=" and/or "==".)
From it follows, that the maximum value in unsigned char is always 0xff (interpreted by the compiler), but it does not mean, that one char allocate 1 Bytes only, because usually all variables on 16/32bits systems are WORD/DWORD aligned and thus 1 Byte of data (char) is padded with some "unused space". It is not a rule, because it is a system dependent feature, but there is usually significant speed penalty, if the variable is not "correctly" aligned.
Back to top
PaulHolland



Joined: 15 Jan 2003
Posts: 636
Helped: 59
Location: Holland


Post16 Aug 2006 20:53   

Re: 8 bit declaration in 32 bit controllers


Hi, if you type char you do not know. better use:

byte, or int8 if you can.
integer is not 16 bits but the normal word length on your cpu so 32 bits cpu has int of 32 bits !. if you want 32 bits on other platforms use long !!.

Paul.
Back to top
RegUser_2



Joined: 24 Dec 2001
Posts: 235
Helped: 2


Post16 Aug 2006 23:43   

Re: 8 bit declaration in 32 bit controllers


Most controllers have possibility to access warious lenght words - that's why for instance instructions like mov.b , mow.w and mov.d exists.

Take a look at the assembler instruction of your controller to find out. Or complie with assembly output enable and take a look at the assembly listing.
Back to top
swapgo



Joined: 24 Jun 2004
Posts: 127
Helped: 2


Post17 Aug 2006 11:35   

Re: 8 bit declaration in 32 bit controllers


Hi

Unsigned char will not contain 8 bytes. It contain just 8 bits ( might be typo error ) .
The compiler must take care by just allocating 8 bits.
Generally these type of info can be clearly found in the compiler user guide.

Regards
Gopi
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> 8 bit declaration in 32 bit controllers
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Difference in Writing Code between 8-bit/16-bit/32-bit Micro (1)
How do I know whether 8-bit or 16-bit MCU shall be adopted? (2)
LPC1111 32-bit for 65 cent! 8-bit finally going obsolete? (2)
Whats the difference between 32 bit os and 64 bit os (3)
Quick overview of common 8-bit and 16-bit microcontrollers? (5)
logic to detect 1 bit (only 1 bit) High in a bus (2)
Difference between 8 bit and 16 bit UC...process POV (1)
can I use 16-bit Multiplier as 2 seperate 8-bit Multipliers? (4)
can I use 16-bit adder as 2 seperate 8-bit adders? (6)
What is the difference between PC's - 32 bit, 64 bit (6)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS