Re: C language on 8-bit microcontrollers
- From: Gene <gene.ressler@xxxxxxxxx>
- Date: Sat, 1 Aug 2009 15:56:17 -0700 (PDT)
On Jul 31, 3:32 am, "Mark" <mark_cruzNOTFORS...@xxxxxxxxxxx> wrote:
It's clear that for 8-bit MCUs the native word length is 8 bits. But we
can't represent 'int' data in 8 bits, as it contradicts the standard (the
int type must contain at least 16 bits to hold the range of values). Does it
mean, compilers used on 8-bit processors are not standard compliant, or they
provide some tricks to overcome this and make illusion of 16-bit ints?
Thanks in advance.
--
Mark
It's no trick. The compiler must generate code that does the
arithmetic in accordance with the C standard. The case of 16-bit (or
more) arithmetic just requires more than one instruction per
operattion. For example most processors have an "add with carry"
instruction. This accounts for the carry of the previous operation.
So adding 16-bit quantities A and B will be something like
MOV lo8(A) to R1
ADD lo8(B) to R1
MOV hi8(A) to R2
ADC hi8(B) to R2
Now the register pair R2|R1 contains the 16-bit result. There are
other solutions that don't even need the ADC instruction.
Of course all the other arithmetic ops can be implemented with
appropriate sequences like this. When the sequence is long (as in the
case of floating point ops), the code is often written as a subroutine
in the runtime system, and the compiler generates a call to the
routine, which is comparatively short.
.
- Prev by Date: Re: Zero terminated strings
- Next by Date: Re: Help a beginner - simple lowercase to uppercase and so on
- Previous by thread: Re: C language on 8-bit microcontrollers
- Next by thread: Re: Difference between Windows and Linux GCC compiler
- Index(es):
Relevant Pages
|