473,395 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Compailation

if i write

A = 512 * 512 ;

for an 8-bit processor,compailer

who will compute the value? pre-processor or the compailer generate
assembly code for 8-bit processor to find the value,

can any body help me... by explaining this, how des this work

thanks
James

Feb 14 '06 #1
4 1447

ja******@gmail.com wrote:
if i write

A = 512 * 512 ;

for an 8-bit processor,compailer

who will compute the value? pre-processor or the compailer generate
assembly code for 8-bit processor to find the value,

can any body help me... by explaining this, how des this work

thanks
James


Not the preprocessor, because it is not a preprocessor related
statement (at least, not the usual preprocessors).

The compiler can do several actions. It depends of how improved it is:
From the point of view of messages, one warning or error if A is not
enough big to keep the resulting value.
From the point of view of execution, it can evaluate the result at
compilation time and generate code to assign this result to A. Or it
can compute code that evaluates the expression and assigns it.
Kind regards.

Feb 14 '06 #2

ja******@gmail.com wrote:
if i write

A = 512 * 512 ;

for an 8-bit processor,compailer

who will compute the value? pre-processor or the compailer generate
assembly code for 8-bit processor to find the value,

can any body help me... by explaining this, how des this work

thanks
James


The fact you're using an 8-bit processor is much less (if at all)
important than the type of `A`. If `A` is not wide enough for the
result of the expression on the right, a compiler should issue a
warning (but is not required to). Decent compilers will allow you to
use more than 8-bit variables even on 8-bit architectures.

As for how and when the expression is calculated, that depends on the
compiler, and also on the options you pass to it. One thing is certain,
though: this is /not/ done by pre-processor.

Any half-decent compiler should calculate th value of the expression
during compilation, and generate only the store instruction (NB, it
will also do any operations that may be required to force the value
into `A`).

It may be possible to force the compiler to actually generate the code
for multiplication, but why would one want to do that?

Feb 14 '06 #3
tmp123 wrote:

ja******@gmail.com wrote:
if i write

A = 512 * 512 ;

for an 8-bit processor,compailer

who will compute the value? pre-processor or the compailer generate
assembly code for 8-bit processor to find the value,

can any body help me... by explaining this, how des this work

thanks
James


Not the preprocessor, because it is not a preprocessor related
statement (at least, not the usual preprocessors).

The compiler can do several actions. It depends of how improved it is:
From the point of view of messages, one warning or error if A is not
enough big to keep the resulting value.
From the point of view of execution, it can evaluate the result at
compilation time and generate code to assign this result to A. Or it
can compute code that evaluates the expression and assigns it.

It certainly *can* be computed at compile time. But I have used
compilers that were *so* bad...that such constant expressions had
code generated for them, and were computed at execution time.
--
+----------------------------------------------------------------+
| Charles and Francis Richmond richmond at plano dot net |
+----------------------------------------------------------------+
Feb 14 '06 #4
thank you very much for clearing my very basic doubt... :)

Feb 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.