0% found this document useful (0 votes)
19 views

02 Word Size and Data Type

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

02 Word Size and Data Type

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Word Size and Data Types

Embedded Software Essentials


C2M1V2
Architecture [S1]
Flash
• Architecture designed to Instruction_a
implement assembly instructions CPU Instruction_b
Instruction_c
General Instruction_d
Purpose Stack pointer

• Complex Instruction Set Registers Program Counter

Computer (CISC) Instruction


Register
Arithmetic Logical Instruction_c
Unit (ALU)
• Reduced Instruction Set
Computer (RISC)
Result

• Advanced RISC Machine (ARM)


Units of Operation [S2]
• Instruction – Fundamental unit of work Inside a CPU
or operation General
Stack pointer
• Arithmetic Purpose
Registers Program Counter
• Logical
• Instruction
Program Flow Control Register
• Load/Store Arithmetic Logical Instruction_c
Unit (ALU)

• Word – fundamental operand size for Result

each operation
Example: 32-bit Machines are built to
do 32-bit math most optimally
Units of Operation [S3]
Core CPU Registers

• General Purpose Registers in CPU


will be size of the Word
CPU N-bit architecture
ARM 32-bit Word = 32-bit registers

N-bit
• Cortex-M Processors has General Registers
N-bit ALU
and Special Purpose CPU Core
registers
• R0-R12 General Purpose N-bit Data Bus (internal)
• R13-R15 Reserved Role
• Program Status Registers
CPU operand size = data size of registers
• Exception Mask Registers
N-bits wide
• Control Register
Instruction Sizes [S4]
• Instruction size can vary
• ARM Instruction Set ARMv6-M  16-Bit and 32-Bit
• Thumb-2 Instruction Set  16-Bit

000104c8 <main>:
104c8: b5b0 push {r4, r5, r7, lr}
16-Bit
Example Output with 104ca: b096 sub sp, #88
Instructions
Machine Code and 104cc: af00 add r7, sp, #0
Assembly Code 32-Bit 104ce: f241 0330 movw r3, #4144
Instructions 104d2: f2c0 0302 movt r3, #2

Instruction Machine Assembly


Address Code Code
Units of Operation [S5] CPU N-bit architecture

• There are a lot of Busses in a


Microcontroller N-bit
Registers
• Internal System Busses N-bit ALU

• Example: ARM AHB


• External Peripheral Busses
N-bit Internal
• Example: ARM APB Data Bus
• Bus is at least the size of the Bus Fabric

instruction M-bit External


Peripheral Data
Bus or Crossbar

Analog GPIO Timer UART


C-Programming Types [S6]
Type Size Value Range (min)
• Sizes of C data types signed char
At least 8-bits [-27, +27 – 1]
are ambiguous and vary int8_t

between architectures unsigned char


At least 8-bits [0, +28 – 1]
uint8_t

signed short int


At least 16-bits [-215, +215 – 1]
• C-Standard Specifies a int16_t

minimum each variable unsigned short int


uint16_t
At least 16-bits [0, +216 – 1]

can be
signed long int
At least 32-bits [-215, +215 – 1]
int32_t

unsigned long int


At least 32-bits [0, +232 – 1]
uint32_t
Standard Integer Sizes[S7]
• Variable length Types can cause
portability issues int8_t Exactly 8-bits
int16_t Exactly 16-bits
• Explicitly defined types that specify int32_t Exactly 32-bits
int64_t Exactly 64-bits
storage and sign
uint8_t Exactly 8-bits
• Provide exact size, fast size, and minimum
uint16_t Exactly 16-bits
size
uint32_t Exactly 32-bits
uint64_t Exactly 64-bits
• Defined in the stdint.h header file
Standard Integer Sizes[S8] #ifndef __STDINT_H__
#define __STDINT_H__

• Explicitly defined types that specify /* 8-bit signed/unsigned Integers */


typedef signed char int8_t;
exact size and sign typedef unsigned char uint8_t;
• U = Unsigned
uint8_t var1; /* 16-bit signed/unsigned Integers */
• Int = Integer type int32_t var3 = -100; typedef signed short int int16_t;
• _t = type typedef unsigned short int uint16_t;

/* 32-bit signed/unsigned Integers */


uint16_t int32_t typedef signed long int int32_t;
typedef unsigned long int uint32_t;

/* 64-bit signed/unsigned Integers */


typedef signed long long int int64_t;
unsigned 16-bits signed 32-bits
typedef unsigned long long int uint64_t;

integer integer #endif /* __STDINT_H__ */


Standard Integer Sizes [S9]
• You need a data size that allows for the
fastest access while having at least N bits int_fast8_t int_least8_t
 Fast Types int_fast16_t int_least16_t
int_fast32_t int_least32_t
• Typically rounds up to word size
• Most optimum size for operations
int_fast64_t int_least64_t
uint_fast8_t uint_least8_t
uint_fast16_t uint_least16_t
• You need the smallest data size that has a uint_fast32_t uint_least32_t
minimum size N bits uint_fast64_t uint_least64_t
 Least Types int_fast8_t var1;
uint_least16_t var2 = 12;
Typedef [S10] #ifndef __STDINT_H__
#define __STDINT_H__

• Typedef keyword allows programmer to /* 8-bit signed/unsigned Integers */


typedef signed char int8_t;
create own types (like an alias) typedef unsigned char uint8_t;
• Can apply to standard types or derived types
/* 16-bit signed/unsigned Integers */
typedef signed short int int16_t;
typedef unsigned short int uint16_t;

typedef enum Color { typedef struct Data { /* 32-bit signed/unsigned Integers */


typedef signed long int int32_t;
COLOR_BLUE = 0, int32_t temperature; typedef unsigned long int uint32_t;
COLOR_RED = 1, unt32_t date;
COLOR_GREEN = 2, unt32_t time; /* 64-bit signed/unsigned Integers */
} Color_t; } Data_t; typedef signed long long int int64_t;
typedef unsigned long long int uint64_t;

#endif /* __STDINT_H__ */

You might also like