2.05k likes | 2.31k Views
Microprocessor Systems and Instrumentation SOE2121. Microprocessor Systems and Instrumentation SOE2121 Number Systems. Machine code:
E N D
Microprocessor Systems and Instrumentation SOE2121 Number Systems
Machine code: 01010011010100101010010010101001010010010000111100010100110010010100101000100010010101010010010010100101000010101010100101110001011100010010101000101001000100101001010100100101000100010010100010101001001010010100001010101010010111000101110001001010100010100100010010100101010010010100010001001010001010100100101001010000101010101001011100010111000100101010001010010001001010010101001001010001000100110010010100010001001100100101000100010011001001010001000100110010010100010001001010001010100100101001010000101010101001011100010111000100101010001010010001001010010101001001010001000100101000101010001111100100101001001010010100001000100010010111
Machine code: 01010001 01010010 10100100 10101001 01001001 00001111 00010100 11001001 01001010 00100010 01010101 00100100 10100101 00001010 10101001 01110001 01110001 00101010 00101001 00010010 10010101 00100101 00010001 00101000 10101001 00101001 01000010 10101010 01011100 01011100 01001010 10001010 01000100 10100101 01001001 01000100 01001010 00101010 01001010 01010000 10101010 10010111 00010111 00010010 10100010 10010001 00101001 01010010 01010001 00010011 00100101 00010001 00110010 01010001 00010011 00100101 00010001 00110010 01010001 00010010 10001010 10010010 10010100 00101010 10100101 11000101 11000100 10101000 10100100 01001010
Machine code: DB 33 37 56 5E 4B 67 85 44 34 77 62 A3 D9 FF 03 74 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 76 F5 E2 AB 72 97 43...
The Decimal System Decimal Number 38O7: 3 x 1OOO ( = 1O3) 3OOO 8 x 1OO ( = 1O2) 8OO O x 1O ( = 1O1) OO 7 x 1 ( = 1OO) 7 ---- Total: 38O7
The Binary System Binary Number 1O11: 1 x 8 ( = 23) 8 O x 4 ( = 22) O 1 x 2 ( = 21) 2 1 x 1 ( = 2O) 1 -- Total: 11
The Binary System Bit value: 128 64 32 16 8 4 2 1 Power of 2: 27 26 25 24 23 22 21 2O Number: 1 0 0 1 0 1 1 0
The Decimal and Binary Systems Decimal Number 38O7: 3 x 1OOO ( = 1O3) 3OOO 8 x 1OO ( = 1O2) 8OO O x 1O ( = 1O1) OO 7 x 1 ( = 1OO) 7 ---- Total: 38O7 Binary Number 1O11: 1 x 8 ( = 23) 8 O x 4 ( = 22) O 1 x 2 ( = 21) 2 1 x 1 ( = 2O) 1 -- Total: 11
The Hexadecimal System Hexadecimal Number 21AF: (Base 16) 2 x 4O96 ( = 163) 8192 1 x 256 ( = 162) 256 A x 16 ( = 161) 16O F x 1 ( = 16O) 15 ---- Total: 8623
Number Systems Decimal Numbers (Base 1O) 1O symbols: O 1 2 3 4 5 6 7 8 9 Binary Numbers (Base 2) 2 symbols: O 1 Hexadecimal Numbers(Base 16) 16 symbols: O 1 2 3 4 5 6 7 8 9 A B C D E F
Brain Exercises (Neurobics) * Binary counting on fingers (and toes after ?) * Binary Arithmetic - + Addition - Subtraction / Division * Multiplication * Hexadecimal Arithmetic - + Addition - Subtraction / Division * Multiplication
HEX BINARY DECIMAL O OOOO O 1 OOO1 1 2 OO1O 2 3 OO11 3 4 O1OO 4 5 O1O1 5 6 O11O 6 7 O111 7 8 1OOO 8 9 1OO1 9 A 1O1O 1O B 1O11 11 C 11OO 12 D 11O1 13 E 111O 14 F 1111 15
Converting between Binary and Hexadecimal Binary: 0010 1100 32+8+4=44 Hex: 2 C 32+12=44
Converting between Binary and Hexadecimal 111O1OO111O1 = 111O 1OO1 11O1 E 9 D 12AB = 1 2 A B OOO1 OO1O 1O1O 1O11
Number conversions - Hex to Decimal: Convert 1234 hex to decimal: 163 162 161 160 4096 256 16 1 1 2 3 4 1 x 4096 = 4096 2 x 256 = 512 3 x 16 = 48 4 x 1 = 4 + -----
Number conversions - Decimal to Binary: Convert 1234 decimal to binary: 210 1024 - 1 1234 - 1024 = 210 29 512 - 0 28 256 - 0 27 128 - 1 210 - 128 = 82 26 64 - 1 82 - 64 = 18 25 32 - 0 24 16 - 1 18 - 16 = 2 23 8 - 0 22 4 - 0 21 2 - 1 2 - 2 = 0 20 1 - 0 So 1234 decimal = 100 1101 0010 binary
Number conversions - Binary to Hex: eg binary number 11010011101011010 First divide up FROM THE RIGHT into groups of 4 bits: 1 1010 0111 0101 1010 Then use the hex table (or better your brain) to write the hex values: 1 1010 0111 0101 1010 1 A 7 5 A Note: learn 0-9 and remember A=1010 and C=1100
HEX BINARY DECIMAL O OOOO O 1 OOO1 1 2 OO1O 2 3 OO11 3 4 O1OO 4 5 O1O1 5 6 O11O 6 7 O111 7 8 1OOO 8 9 1OO1 9 A 1O1O 1O B 1O11 11 C 11OO 12 D 11O1 13 E 111O 14 F 1111 15
Negative Numbers - Twos Complement form: To form a negative number, for example -3, first invert (ones complement) the positive number of the same magnitude (+3), then add one: 00000011 +3 invert to give 11111100 ones complement 00000001+ add one -------- 11111101 result is -3 (Hex FD)
7 0 1 0 0 0 0 0 0 0 Negative Numbers: Most negative number -128 Most positive number +127 Note: bit 7 carries the sign information 1=negative 0=positive 7 0 0 1 1 1 1 1 1 1
Negative Numbers: 0111 1111 7F +127 0111 1110 7E +126 | 0000 0011 03 +3 0000 0010 02 +2 0000 0001 01 +1 0000 0000 00 0 1111 1111 FF -1 1111 1110 FE -2 1111 1101 FD -3 | 1000 0001 81 -127 1000 0000 80 -128
Signed and Unsigned Arithmetic: Why does it work for both unsigned numbers (0 to 255) and signed numbers (-128 to +127)? Unsigned Data Signed 253 FD -3 1 01+ +1 --- --- --- 254 FE -2
Binary Coded Decimal: Each decimal digit is encoded as a 4 bit binary number: O OOOO 1 OOO1 2 OO1O 3 OO11 4 O1OO 5 O1O1 6 O11O 7 O111 8 1OOO 9 1OO1 eg decimal 42 0100 0010 4 2 What is this value in Hexadecimal? (Note 42 in binary is 0010 1010 Hex 2A)
Binary Coded Decimal: Range of BCD numbers in one byte 00 - 99 Reading a BCD number in hex gives the decimal value
HEX BINARY DECIMAL O OOOO O 1 OOO1 1 2 OO1O 2 3 OO11 3 4 O1OO 4 5 O1O1 5 6 O11O 6 7 O111 7 8 1OOO 8 9 1OO1 9 A 1O1O 1O B 1O11 11 C 11OO 12 D 11O1 13 E 111O 14 F 1111 15
ASCII Table: MSD->0 1 2 3 4 5 6 7 LSD 0 NUL DLE SP 0 @ P ` p 1 SOH DC1 ! 1 A Q a q 2 STX DC2 " 2 B R b r 3 ETX DC3 # 3 C S c s 4 EOT DC4 $ 4 D T d t 5 ENQ NAK % 5 E U e u 6 ACK SYN & 6 F V f v 7 BEL ETB ' 7 G W g w 8 BS CAN ( 8 H X h x 9 HT EM ) 9 I Y i y A LF SUB * : J Z j z B VT ESC + ; K [ k { C FF FS , < L ` l | D CR GS - = M ] m } E SO RS . > N ^ n ~ F SI VS / ? O _ o DEL
The Byte 7 6 5 4 3 2 1 0 1 Byte = 8 bits Contains one of 256 possible patterns OOOOOOOO OOOOOOO1 OOOOOO1O OOOOOO11 OOOOO1OO | 11111111 Range $OO-$FF = O to 255
The Byte 7 6 5 4 3 2 1 0 Most Significant Bit Least Significant Bit
Which is Most Significant? A typical lecturer’s salary might be: £93,878 Least Significant Digit Most Significant Digit
Hexadecimal Representation: BinaryHexMeaning Value 0100 0001 41 Unsigned Binary 65 Decimal 0100 0001 41 ASCII code A 0100 0001 41 BCD number 41 Decimal 1111 1111 FF Signed Binary -1 Decimal 1111 1111 FF Unsigned Binary 255 Decimal 1010 0101 A5 Opcode LDA 7 6 5 4 3 2 1 0
Brain Exercises (Neurobics) * Binary counting on fingers (and toes after ?) * Binary Arithmetic - + Addition - Subtraction / Division * Multiplication * Hexadecimal Arithmetic - + Addition - Subtraction / Division * Multiplication
Introduction Load and Store Transfer
Not Recommended Book: 65O2 Assembly Language Programming by L A Leventhal Pub: Osborne/McGraw-Hill
Assembly Language Advantages: Fastest possible program (on a particular processor) Smallest size program (cheaper ROM) Smallest RAM requirement (cheaper RAM)Disadvantages: Much longer software development time Programs more difficult to debug Programs not portable
Assembly Language: When is it used? MASS PRODUCTIONWhere the lowest possible production cost is required and longer more expensive software development time is acceptable. eg microwave oven, mobile phone HIGH SPEED APPLICATIONSWhere a high level language would not respond quickly enough. eg high speed data acquisition system Notes: faster processors, critical bits in assembler, smallest physical size eg Pacemaker where power consumption is also a consideration.
Microprocessor Systems and Instrumentation SOE2121 Number Systems
Machine code: 01010011010100101010010010101001010010010000111100010100110010010100101000100010010101010010010010100101000010101010100101110001011100010010101000101001000100101001010100100101000100010010100010101001001010010100001010101010010111000101110001001010100010100100010010100101010010010100010001001010001010100100101001010000101010101001011100010111000100101010001010010001001010010101001001010001000100110010010100010001001100100101000100010011001001010001000100110010010100010001001010001010100100101001010000101010101001011100010111000100101010001010010001001010010101001001010001000100101000101010001111100100101001001010010100001000100010010111
Machine code: 01010001 01010010 10100100 10101001 01001001 00001111 00010100 11001001 01001010 00100010 01010101 00100100 10100101 00001010 10101001 01110001 01110001 00101010 00101001 00010010 10010101 00100101 00010001 00101000 10101001 00101001 01000010 10101010 01011100 01011100 01001010 10001010 01000100 10100101 01001001 01000100 01001010 00101010 01001010 01010000 10101010 10010111 00010111 00010010 10100010 10010001 00101001 01010010 01010001 00010011 00100101 00010001 00110010 01010001 00010011 00100101 00010001 00110010 01010001 00010010 10001010 10010010 10010100 00101010 10100101 11000101 11000100 10101000 10100100 01001010
Machine code: DB 33 37 56 5E 4B 67 85 44 34 77 62 A3 D9 FF 03 74 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 99 55 64 EE E7 F2 83 82 99 55 76 F5 E2 AB 72 97 43...
HEX BINARY DECIMAL O OOOO O 1 OOO1 1 2 OO1O 2 3 OO11 3 4 O1OO 4 5 O1O1 5 6 O11O 6 7 O111 7 8 1OOO 8 9 1OO1 9 A 1O1O 1O B 1O11 11 C 11OO 12 D 11O1 13 E 111O 14 F 1111 15
The Byte 7 6 5 4 3 2 1 0 1 Byte = 8 bits Contains one of 256 possible patterns OOOOOOOO OOOOOOO1 OOOOOO1O OOOOOO11 OOOOO1OO | 11111111 Range $OO-$FF = O to 255
The Byte 7 6 5 4 3 2 1 0 Most Significant Bit Least Significant Bit
Which is Most Significant? A typical lecturer’s salary might be: £93,878 Least Significant Digit Most Significant Digit
The Byte 7 6 5 4 3 2 1 0 1 Byte = 8 bits Contains one of 256 possible patterns OOOOOOOO OOOOOOO1 OOOOOO1O OOOOOO11 OOOOO1OO | 11111111 Range $OO-$FF = O to 255
Hexadecimal Representation: BinaryHexMeaning Value 0100 0001 41 Unsigned Binary 65 Decimal 0100 0001 41 ASCII code A 0100 0001 41 BCD number 41 Decimal 1111 1111 FF Signed Binary -1 Decimal 1111 1111 FF Unsigned Binary 255 Decimal 1010 0101 A5 Opcode LDA 7 6 5 4 3 2 1 0
Memory 7 0 Microprocessor FFFF 0200 01FF 0100 00FF 0000 7 0 A X Y 15 8 PC 6502 Programmer’s Model 00000001 SP NV-BDIZC STACK PS PAGE ZERO
Memory 65536 bytes numbered in decimal: O - 65535 in hex: OOOO - FFFF in binary: OOOO OOOO OOOO OOOO - 1111 1111 1111 1111 The number of each memory location is known as its ADDRESS2 Bytes are required to hold an address which is 16 bits
One byte instructions: OPCODE Two byte instructions: OPCODE OPERAND Instruction Formats Three byte instructions: OPCODE OPER AND