Professional Documents
Culture Documents
BED25403 Lecture4
BED25403 Lecture4
Learning Outcomes
1. Declare type variables according to bit-size of data
2. Use bitwise operators to manipulate data at bit level
3. Read codes written in C for embedded system
4. Explain the flow of instructions written for embedded system
©2023 Hazizulden AbdulAziz
ARM Processor
Instruction Set
The ARM architecture includes
two instruction sets for executing
code on processors that support
the Thumb mode: Thumb and
Thumb-2.
Code written in
Assembly Language
©2023 Hazizulden AbdulAziz
Embedded C
An ANSI/ISO C with some extensions and adaptations to suit the specific
microcontroller architecture
©2023 Hazizulden AbdulAziz
Structure of a
Program written in
Embedded C
©2023 Hazizulden AbdulAziz
Data Types
Data types Description Range
String of binary digits (bits) are usually grouped into a string of 4 or 8 bits to
simplified writing, reading and processing the binary numbers. A nibble is a unit
of binary number consisting 4 bits of 1’s and/or 0’s and, a byte is a unit of
binary number consisting of 8 bits of 1’s and/or 0’s.
A word is a unit of binary number consisting of 2-4 bytes of 1’s and/or 0’s
Most digital systems process and store binary data in a group of 8-bit or a byte
©2023 Hazizulden AbdulAziz
32-bit Data
Processing
A 32 bits long binary number can
by divided into 8 groups of 4-bit
binary.
4-bit binary can easily be written
as an hexadecimal number.
Example:
100101101010010111000011000
01111 in binary can be written as
0x96A5C30F in hexadecimal
©2023 Hazizulden AbdulAziz
Binary-Coded-Decimal (BCD)
Binary-Coded-Decimal (BCD) is used to Decimal Binary
represent each decimal digit as a binary 0 0000
number. 1 0001
Also known as 8-4-2-1 code 2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
©2023 Hazizulden AbdulAziz
Alphanumeric
characters
representation
ASCII (American
Standard Code for
Information Interchange)
code is used to represent
alphanumeric characters
in binary format
©2023 Hazizulden AbdulAziz
Bitwise Operators
Category Operators
Bitwise NOT ~
Bitwise AND &
Bitwise OR |
Bitwise XOR ^
Bitwise left-shift << n
Bitwise right-shift >> n
Example 1:
Bitwise shift
operation
©2023 Hazizulden AbdulAziz
Bits Masking
Bits-masking is method of applying a mask to a value. Bits-masking filters a bit
or a multiple bit in a byte of data.
Using a bitmask, a bit in a byte can be set either to 1 (masked ON) or to 0
(masked OFF) using bitwise operation.
©2023 Hazizulden AbdulAziz
Example 2:
Bit Masking
©2023 Hazizulden AbdulAziz
Example 3:
Structure datatype
Each member of a structure is
accessed using member/dot (.)
operator
©2023 Hazizulden AbdulAziz
Example 4:
Structure datatype
Using arrow operator (->) to
access member of structure data
type pointed by a pointer variable
©2023 Hazizulden AbdulAziz
Pointer
A pointer is a variable that stores the memory address of another variable.
Pointers allow you to manipulate the data stored in memory, which is useful for
tasks such as dynamic memory allocation, passing parameters to functions by
reference, and creating complex data structures like linked lists and trees.
©2023 Hazizulden AbdulAziz
Example 5:
Pointer
©2023 Hazizulden AbdulAziz
Example 6:
©2023 Hazizulden AbdulAziz
Example 7:
©2023 Hazizulden AbdulAziz
NEXT
Getting started with STM32 IDE