Beruflich Dokumente
Kultur Dokumente
Spring 2006
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Hex 0 1 2 3 4 5 6 7 8 9 A B C D E F
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
EE 308
Spring 2006
Binary numbers are a code, and represent what the programmer intends for the code. 0x72 Some possible codes: r INC (ASCII) (HC12 instruction)
2.26V (Input from A/D converter) 11410 (Unsigned number) 11410 (Signed number) Set temperature in room to 69 F Set cruise control speed to 120 mph
EE 308
Spring 2006
+ 1 x 2 +
+ 1 x 2 +
+ 1 x 2 +
+ 0 x 2 +
+ 1 x 2 +
+ 1 x 2 0 + 1 x 1
1 x 64 123 10
1 x 32
1 x 16
1 x 8
0 x 4
1 x 2
+ +
2 x 16 2 x 256
+ +
13 x 16 13 x 16
+ +
6 x 16 6 x 1
8 x 4096 33494 10
EE 308
Spring 2006
Q 45 2 0
721 10
2D1
16
EE 308
Spring 2006
10 11
12
13
4 0
110
010
101 100 5 4
011 3
EE 308
Spring 2006
6 5 4
3 2 1 0
0 0
110
010
101 100 3
011 3
EE 308
Spring 2006
6 5 4
3 2 1 0
4 3 2 1 0 0 1
110
010
101 100 3 4
7
011 3
EE 308
Spring 2006
Number Wheel: Carry and Overow Carry applies to unsigned numbers when adding or subtracting, result is incorrect. Overow applies to signed numbers when adding or subtracting, result is incorrect.
0 0 1 001 1
Carry 7
000 111
2 6
110
010
2 2
011 3 Overflow
EE 308
Spring 2006
Binary, Hex and Decimal (Signed & Unsigned) Numbers (4-bit representatio
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Hex 0 1 2 3 4 5 6 7 8 9 A B C D E F
Decimal US 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 S 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
EE 308
Spring 2006
+ 10 x 16 ) 10 + 10 x 1 )
10
If most significant bit is 1 (most significant hex digit 8F), number is negative. Get decimal equivalent by taking 2s complement of number, converting to decimal, and using sign. Example for 8bit number: A3
16
> ( 5D ) 16 ( 5 x 16 93 10
( 5 x 16 1
+ 13 x 16 0) 10 + 13 x 1 ) 10
10
EE 308
Spring 2006
0 1 2 3 4 5 6 7
F E D C B A 9 8
To take twos complement, add one to ones complement. Take twos complement of D0C3 :
2F3C + 1 = 2F3D
11
EE 308
Spring 2006
Overow and Carry assume you have a xed word size A carry is generated when you add two unsigned numbers together, and the result is too large to t in the xed word size. A carry is generated when you subtract two unsigned numbers, and the result should be negative. An overow is generated when you add or subtract two signed numbers, and the xed-length answer has the wrong sign. Addition and Subtraction of Binary and Hexadecimal Numbers
ADDITION AND SUBTRACTION OF BINARY AND HEXADECIMAL NUMBERS 1) Limit number of digits to specified word size. 4bit word: 1101 + 1011 1 1000 Keep only 4 bits in answer
2)
Does not matter if numbers are signed or unsigned mechanics the same Do the operation, then determine if carry and/or overflow bits are set. 4bit word: 1101 + 1011 1 1000 Neg Neg Neg
12
EE 308
Spring 2006
Condition Code Register 8 FFs N Negative : most significant bit of result Z Zero C Carry : 1 > result zero, 0 > result not zero : 1 > last operation generated a carry V Overflow : 1 > last operation generated an overflow
Note: Not all HC12 instructions change CCR bits. A bit in the CCR is the result of the last executed instruction which aects that bit. For example, consider the following instruction sequence: aba staa $0900 ; Add B to A ; Store A in address $0900
The ABA instruction will change the H, N, Z, V and C bits of the CCR. The STAA instruction will change the N and Z bit, and clear the V bit. After the two instructions, the H and C bits will reect the result of the ABA instruction; the N and Z bits will reect the result of the STAA instruction (was the number stored negative or zero), and the V bit will be 0.
13
EE 308
Spring 2006
Condition Code Register 8 FFs N Negative : most significant bit of result Z Zero C Carry : 1 > result zero, 0 > result not zero : 1 > last operation generated a carry V Overflow : 1 > last operation generated an overflow
If you add a positive and a negative number, on overow never occurs. If you subtract two positive numbers, an overow never occurs. If you subtract two negative numbers, and overow never occurs.
14