Chapter-2 ARM
Chapter-2 ARM
Chapter-2 ARM
2
Number System
Embedded Systems with ARM Cortext-M
Updated: Tuesday, January 16, 2018
What you should know…..
Before coming to this class
Decimal Binary Octal Hex
0 0000 00 0x0
1 0001 01 0x1
2 0010 02 0x2
3 0011 03 0x3
4 0100 04 0x4
5 0101 05 0x5
6 0110 06 0x6
7 0111 07 0x7
8 1000 010 0x8
9 1001 011 0x9
10 1010 012 0xA
11 1011 013 0xB
12 1100 014 0xC See the review
13
14
1101
1110
015
016
0xD
0xE notes!
15 1111 017 0xF
What you should know…..
Before coming to this class
5
Switch State and Digital Representation
0100010101100111=17767=4567
1000100110101011=35243=89AB
1100110111101111=52719=CDEF
One Word
Double-Word
Data Representation
• Data representation can be Digital or Analog
• In Analog representation values are represented over a
continuous range
• In Digital representation values are represented over a
discrete range
• Digital representation can be
• Decimal
• Binary
• Octal
• Hexadecimal We need to know how to use
and convert from one to another!
Digital Data Representations:
Decimal (base 10), Binary (base 2), Hex(base 16)
Decimal Binary Octal Hex
0 0000 00 0x0
1 0001 01 0x1
2 0010 02 0x2
3 0011 03 0x3
4 0100 04 0x4
5 0101 05 0x5
6 0110 06 0x6
7 0111 07 0x7
8 1000 010 0x8
9 1001 011 0x9
10 1010 012 0xA
11 1011 013 0xB
12 1100 014 0xC
13 1101 015 0xD
14 1110 016 0xE
15 1111 017 0xF
Digital Data Representations:
Power of 2
Using Binary Representation
• Digital systems are binary-based
• All symbols are represented in binary format
• Each symbol is represented using Bits
• A bit can be one or zero (on or off state)
• Comparing Binary and Decimal systems:
• In Decimal a digit is [0-9] – base-10
• In Binary a digit is [0-1] – base-2
• In Decimal two digits can represent [0-99] à102-1
• In Binary two digits can represent [0-3] à 22-1
Binary Counting
23 22 21 20 2-1 2-2 2-3 2-4
0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 0 0.5
0 0 1 0 2 0 1 0 0 0.25
0 0 1 1 3 0 0 1 0 0.125
0 1 0 0 4 0 1 1 0 0.375
0 1 0 1 5 1 0 1 0 0.625
Binary Point
Counting in Different Numbering Systems
• Decimal
• 0,1,2,3,4,5,6,7,8,9,10,11,12…,19,20,21,…,29,30,…,39….
• Binary
• 0,1,10,11,100,101,110,111,1000,….
• Octal
• 0,1,2,3,4,5,6,7,10,11,12…,17,20,21,22,23…,27,30,…
• Hexadecimal
• 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,…,1F,20,…,2F,30,..…
Learning Number Conversion
Decimal
Hexasdecimal Octal
Binary
BCD/ ASCII
Binary-to-Decimal Conversions
11011 à Decimal
Decimal
Hexasdecimal Octal
1´ 2 4 + 1´ 23 + 0 ´ 2 2 + 1´ 21 + 1´ 20 = 16 + 8 + 2 + 1 = 2710
Binary
BCD
¾¾® n0 ´ b 0 + n1 ´ b1 + n2 ´ b 2 + n3 ´ b 3 ... + nN -1 ´ b N -1
(nN -1nN - 2 ...n3n2 n1n0 )b ¾Convert
32 / 2 = 16 + Re mainder _ of _ 0 Binary
16 / 2 = 8 + Re mainder _ of _ 0
8 / 2 = 4 + Re mainder _ of _ 0 1000001
BCD
4 / 2 = 2 + Re mainder _ of _ 0
MSB LSB
2 / 2 = 1 + Re mainder _ of _ 0
1 / 2 = 0 + Re mainder _ of _ 1
3 ´ 82 + 7 ´ 81 + 2 ´ 80 = 3 ´ 64 + 7 ´ 8 + 2 ´1 = 25010
Binary
BCD
¾¾® n0 ´ b 0 + n1 ´ b1 + n2 ´ b 2 + n3 ´ b 3 ... + nN -1 ´ b N -1
(nN -1nN - 2 ...n3n2 n1n0 )b ¾Convert
What about 372.28? Ans: =250+(2x8-1)=250.25
Decimal-to-Octal:
266 à Octal Decimal
266 / 8 = 33 + Re mainder _ of _ 2
Hexasdecimal Octal
33 / 8 = 4 + Re mainder _ of _ 1
412
Binary
4 / 8 = 0 + Re mainder _ of _ 4 BCD
MSB LSB
Hex-to-Decimal Conversions
2AF à Decimal
Decimal
BCD
¾¾® n0 ´ b 0 + n1 ´ b1 + n2 ´ b 2 + n3 ´ b 3 ... + nN -1 ´ b N -1
(nN -1nN - 2 ...n3n2 n1n0 )b ¾Convert
Binary
423 / 16 = 26 + Re mainder _ of _ 7
26 / 16 = 1 + Re mainder _ of _ 10 1A7
BCD
1 / 16 = 0 + Re mainder _ of _ 1
MSB LSB
Remember 10 in Hex is A
214à Hex
214 / 16 = 13 + Re mainder _ of _ 6
13 / 16 = 0 + Re mainder _ of _ 13 D6
Remember 13 in Hex is D
Last one should be “0”
Converting from Hex-to-Octal
Decimal
Binary
BCD
=0 4 4 4
=444 Oct
BCD
Counting
• Decimal
• 0,1,2,3,4,5,6,7,8,9,10,11,12…,19,20,21,…,29,30,…,39….
• Binary
• 0,1,10,11,100,101,110,111,1000,….
• Octal
• 0,1,2,3,4,5,6,7,10,11,12…,17,20,21,22,23…,27,30,…
• Hexadecimal
• 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,…,1F,20,…,2F,30,..…
BCD Addition
n 0 1 1 0 ß BCD for 6
0 1 1 1 ß BCD for 7
• Any symbol can be represented by a code _________________
• Example: Binary-Coded-decimal (BCD) 1 1 0 1 ß 13 but invalid!
• Each digit has its own binary code 0 1 1 0 ß Add 6 to correct
• Example: 610=0110, 1610=0001 0110 (In binary 16 is?)
________________________
• BDC numbers 0 0 0 1 0 0 1 1 ß BDC for 13!!
• They are between 0 and 9
• Hence each decimal number is represented by 4 bits
ASCII Code
1 01 SOH 33 21 ! 65 41 A 97 61 a
2 02 STX 34 22 " 66 42 B 98 62 b
3 03 ETX 35 23 # 67 43 C 99 63 c
4 04 EOT 36 24 $ 68 44 D 100 64 d
5 05 ENQ 37 25 % 69 45 E 101 65 e
24
Convert to Upper Case
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A
a b c d e f g h i j k l m n o p q r s t u v w x y z
61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A
25
Digital Arithmetic
Binary Numbers
X 127 1111111
Y 63 111111
X 170 10101010
Y 85 1010101
X 127 1111111
Y 63 111111
X 170 10101010
Y 85 1010101
9 -9 9 -9 9
-9 10111 01001
11001 01001 10110 01001
-10 10 -10 10
-10 10
11010 01010 10101 01010 10110 01010
-11 11 -11 11 -11 11
31
Representing Signed Numbers
Converting to 2’s Complement
For example:
• In order to change a binary number to 2’s +9 à 01001 (sign bit = 0, indicating +)
complement it must first be changed to 1’s 2’s complement of 9 à
complement.
01001 à 10110
• To convert to 1’s complement, simply change each
bit to its complement (opposite). 10110 + 1 à 10111 = -9
• To convert 1’s complement to 2’s complement add 1
to the 1’s complement.
This is
• A positive number is true binary with 0 in the sign The sign
bit. BIT
• A negative number is in 2’s complement form with When the sign-bit is zero à Positive number
1 in the sign bit. If the sign-bit is set à Negative number
• A binary number can be negated by taking the 2’s
complement of it. Remember: 2’s complement is just a
conventional way of representing signed
numbers in digital arithmetic – Don’t ask why!
2’s Complement Representation
For example:
• Assuming N+1 bits representing Assume 3+1 bits
a 2’s Complement (that is Largest pos. number will be 0111= +7
Smallest number will be 1000 = -8
representing the number with N Remember: 1111= -1
bits and one bit is dedicated to Zero is represented by 0000 = Zero
11010
27
+6
Carry
5
00110
+ 0 0 1 1 0 + 6
28 + 6
11001
26 6
00111
1 0 0 0 1 0 2
25 7
NOT 32!
11000 24 8 01000
Extra bit is 5-bit result
23 9
10111 01001 discarded.
22 10
10110 01010
21 11
38
Carry/borrow flag bit for unsigned numbers
If the traverse crosses the boundary between 0 and 𝟐𝒏 − 𝟏, the carry flag is set on
addition and is cleared on subtraction.
11111 00000 00001
11110 00010
11101 00011
11100
31 0 1
2 00100
Borrow 1 1 1 0 0
30
29 3
11011 28 -5
4 00101 0 0 0 1 1 3
Carry 3-5
11010
27 5
00110 - 0 0 1 0 1 - 5
26 6
11001
25 7
00111 1 1 1 1 0 30
11000 24 8 01000
23 9
10111 01001 5-bit result
22 10
10110 01010
21 11
39
Arithmetic Operations using 2’s Complement
• Inverting X 180 10110100
Magnitude Overflow:
• A positive number to a negative number Y 85 01010101
(max unsigned number
that can be represented
• A negative number to a positive number using 8 bits is 255)
X+Y 265 100001001
X 4 0100
• Subtracting B from A à A-B Note the value is negative
Y -7 1001
• Just take the 2’s Complement of B
X-Y -3 1101
• Add A and B (A+B)
X -4 11100
Overflow: X 7 0 111
Y -9 10111
(max signed number that
can be represented using Y 7 0 111
X+Y -13 1 10011
4 bits is 7) X+Y 14 1 110