Download PB PICBASIC user's manual
Transcript
PICBASIC DATABOOK Variable type PICBASIC language uses five types of variable. PB series can use only two types of variable, BYTE type and INTEGER type, while PBM series use all five types of variable. - Byte - Integer - Long - Single - String : 8bit number without sign (0~255) : 16bit number without sign (0~65535) : 32bit number with sign (-2,147,483,648~2,147,483,647) : 32bit floating point number with sign : 8bit character (extended up to 92 byte at most) Byte variable is a type of 8bit number without sign and reserves 8bits (1byte) of memory space. Therefore, its expression range is 0~225. Integer variable is a type of 16bit number without sign and reserves 16bits (2bytes) of memory space. So, its expression range is 0~65535. Long variable is a type of 32bit number with sign and reserves 32bits (4bytes) of memory space. So, its expression range is 2,147,483,648~2,147,483,647. Single variable is a type of 32bit of floating point number with sign. In accordance with recommendation of IEEE 754, it consists of seven bits of exponential part, twenty three bits of point part and one sign bit. String variable is available in PBM series only. It can be 93byte at most and must be used with value indicating its maximum bytes for reserving memory space. Refer to the following example. DIM ST AS STRING * 14 ‘Declare ST as string variable with 14byte of maximum bytes The following picture describes how string data is stored in memory when maximum bytes of string variable is 14 bytes. If the maximum byte is 14, 2byte of additional memory is reserved. One byte is for the value indicating the maximum byte. The other byte is for NULL value indicating end of string. P I C B AS I C 2 0 0 0 '14' '0' Garbage In the above picture, PICBASIC2000, 12bytes of string data, is stored in 14bytes of memory space. In this case, the rest, 2bytes, is filled with unknown garbage value. DIM ST AS STRING * 16 ST = “COMFILE TECHNOLOGY” COMFILE Technology ‘Declare ST as string variable with 16byte of ‘maximum bytes ‘Because data, COMFILE TECHNOLOGY, is out of ‘Reserved range (16bytes), last two characters, GY, will ‘Not be stored. 39