mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
In order to fully understand this, we should recollect the data types.
Data type determines not only the range of values variable can hold, but also the
amount of RAM space it consumes. This is fundamental in practical programming.
Let's assume that our destination variable C is a byte, consuming 8 bits of PIC
RAM, spanning values 0 to 255. Now observe what really happens inside the PIC:
the result should be 369, but in binary representation it equals (1)01110001.
Because C is limited to 8 bits it will store the lower 8 bits while dropping the rest
of the information (the most significant bit). 01110001 equals 113 in decimal rep-
resentation.
dim testA as byte
dim testB as byte
dim Cc as word
main:
testA = 250
testB = 10
Cc = testA + testB
' this will always be correct because
' range for Cc is 0..65535 and maximum result
' of adding two bytes is only 255 + 255 = 510
end.
MikroElektronika:
Development
tools
-
Books
-
Compilers
mikroBASIC
making it simple...
67
page
Result has 9 bits.
instead of 369. Most
Commentaires sur ces manuels