Internal representation

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Internal representation

#1 Post by LGR » 07 Feb 2011 03:05

How are integers, bytes and bits stored in RAM; packed, or using a full 32-bit word?

Also, it seems strange to me that you carried over the terminology from the PIC24, and call 16-bit "word", and 32-bit "dword". Shouldn't "word" be 32 bit, and 64 be "long"?
If you know what you're doing, you're not learning anything.

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: Internal representation

#2 Post by srdjan » 07 Feb 2011 10:01

LGR wrote:How are integers, bytes and bits stored in RAM; packed, or using a full 32-bit word?

Also, it seems strange to me that you carried over the terminology from the PIC24, and call 16-bit "word", and 32-bit "dword". Shouldn't "word" be 32 bit, and 64 be "long"?
- In such case, I guess that byte would be 16bit and how should we call 8bits then?
Either way around we are missing a type name :)

Usually, integer type is bounded to a platform basic type determined by a memory organization (32bit here).
All other types are specific to compiler implementation.
For example, in win32 Delphi, integer is 32bits, but word type is 16bits.

We decided to keep backward compatibility and enable users to easily port their existing codes and migrate to pic32 in a sec... or two ;)

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Internal representation

#3 Post by LGR » 07 Feb 2011 16:54

I'm an old guy who remembers 32-bit mainframes. The convention there was "word" was 32, and "byte" was 8. The hardware supported both word and byte addressing. There were no 16-bit types. With a 32 bit word, it's hard to imagine a use for them.

But you didn't answer the first question. Just to be perfectly clear, does a byte use an entire 32 bit word, or does the code pack 4 of them into a word? Same question for bits. If they're not packed, I can't see any legitimate use for 16-bit types.
If you know what you're doing, you're not learning anything.

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: Internal representation

#4 Post by srdjan » 08 Feb 2011 15:11

Hi,
LGR wrote:I'm an old guy who remembers 32-bit mainframes. The convention there was "word" was 32, and "byte" was 8. The hardware supported both word and byte addressing. There were no 16-bit types. With a 32 bit word, it's hard to imagine a use for them.

But you didn't answer the first question. Just to be perfectly clear, does a byte use an entire 32 bit word, or does the code pack 4 of them into a word? Same question for bits. If they're not packed, I can't see any legitimate use for 16-bit types.
Sorry, I have missed the first one.
Variables are packed with regards to their alignment.
8bits can be placed anywhere (alignment 1).
16bits must be placed at even addresses (alignment 2).
32 and 64bits must be placed at addresses divisible by 4 (alignment 4).

So using 8bits or 16bits instead of 32bits consumes less memory with same code efficiency.

P.S. Architecture itself does support placing any size at any address (i.e. 32bits at odd addresses), but code for accessing is highly inefficient.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Internal representation

#5 Post by LGR » 08 Feb 2011 17:18

It looks like I'm going to have to read the Microchip literature more thoroughly. :evil:

Thanks.
If you know what you're doing, you're not learning anything.

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: Internal representation

#6 Post by p.erasmus » 08 Feb 2011 18:35

srdjan wrote:
8bits can be placed anywhere (alignment 1).
16bits must be placed at even addresses (alignment 2).
32 and 64bits must be placed at addresses divisible by 4 (alignment 4).

So using 8bits or 16bits instead of 32bits consumes less memory with same code efficiency.

P.S. Architecture itself does support placing any size at any address (i.e. 32bits at odd addresses), but code for accessing is highly inefficient
This should be done by the compiler if I am not mistaken or should we as the user take care of this :?

Regards
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

User avatar
rajkovic
mikroElektronika team
Posts: 694
Joined: 16 Aug 2004 12:40

Re: Internal representation

#7 Post by rajkovic » 09 Feb 2011 08:33

p.erasmus wrote:
srdjan wrote:
8bits can be placed anywhere (alignment 1).
16bits must be placed at even addresses (alignment 2).
32 and 64bits must be placed at addresses divisible by 4 (alignment 4).

So using 8bits or 16bits instead of 32bits consumes less memory with same code efficiency.

P.S. Architecture itself does support placing any size at any address (i.e. 32bits at odd addresses), but code for accessing is highly inefficient
This should be done by the compiler if I am not mistaken or should we as the user take care of this :?

Regards
Yes compiler is taking care about alignment and packing variables at right address .

Post Reply

Return to “mikroPascal PRO for PIC32 General”