microprocessors interfacing
play

Microprocessors & Interfacing Data Representation Number - PowerPoint PPT Presentation

Lecture Overview Microprocessor Hardware Structures Microprocessors & Interfacing Data Representation Number representation Instruction Set Basics of Computing with Microprocessor Systems Lecturer : Dr. Annie Guo S2,


  1. Lecture Overview • Microprocessor Hardware Structures Microprocessors & Interfacing • Data Representation – Number representation • Instruction Set Basics of Computing with Microprocessor Systems Lecturer : Dr. Annie Guo S2, 2008 COMP9032 Week1 1 S2, 2008 COMP9032 Week1 2 Fundamental Hardware Components in Execution Cycle Computing System IM DM I/O bus IF : Instruction Fetch IM DM I/O ID : Instruction decode CPU datapath RR : Read Register File CU datapath RF ALU EX : Execution CU RF ALU WR : Write result back • ALU : Arithmetic and Logic Unit • RF : Register File (a set of registers) • CU : Control Unit Note: ID and RR can be merged • IM/DM : Instruction/Data Memory • I/O : Input/Output Devices S2, 2008 COMP9032 Week1 3 S2, 2008 COMP9032 Week1 4

  2. Microprocessors Data Representation • A microprocessor is the • For digital microprocessor system being able datapath and control unit to compute and process data, the data must on a single chip. be properly represented • If a microprocessor, its – How to represent numbers for calculation? associated support – How to represent characters, symbols and other circuitry, memory and physical values for processing? peripheral I/O components • Will be covered later are implemented on a single chip, it is a microcontroller . – We use AVR microcontroller as the example in our course study S2, 2008 COMP9032 Week1 5 S2, 2008 COMP9032 Week1 6 Number Representation Decimal • Any number can be represented in the form • Example of (3597) 10 3 2 3 10 5 10 9 10 7 (a a ...a a . a ...a ) = = = = × × × × + + + + × × × × + + + + × × × × + + + + n n 1 1 0 - 1 - m r − − − − n n 1 1 m − − − − − − a r a r − − ... a r a a r − − ... a r − − = = = = × × × × + + + + × × × × + + + + + + + + × × × × + + + + + + + + × × × × + + + + + + + + × × × × n n 1 1 0 - 1 m − − − − − − − − – The place values, from right to left, are 1, 10, 100, r : radix, base 0 a r 1000 ≤ ≤ ≤ ≤ < < < < i – The base or radix is 10 – All digits must be less than the base, namely, 0~9 S2, 2008 COMP9032 Week1 7 S2, 2008 COMP9032 Week1 8

  3. Binary Hexadecimal • Example • Example (F24B) (1011) 16 32 2 3 2 1 2 0 2 1 2 1 F 16 2 16 4 16 B = = = = × × × × + + + + × × × × + + + + × × × × + + + + = = = = × × × × + + + + × × × × + + + + × × × × + + + + 3 2 15 16 2 16 4 16 11 = = = = × × × × + + + + × × × × + + + + × × × × + + + + – The place values, from right to left, are 1, 2, 4, 8 – The place values, from right to left, are 1, 16, 16 2 , 16 3 – The base or radix is 2 – The base or radix is 16 – All digits must be less than the base, namely, 0~1 – All digits must be less than the base, namely, 0~9, A,B,C,D,E,F S2, 2008 COMP9032 Week1 9 S2, 2008 COMP9032 Week1 10 Which numbers to use? Binary Arithmetic Operations • Binary numbers • Similar to decimal calculations – Used by digital systems • Examples of addition and multiplication are • Because digital devices can easily produce high or low given in the next two slides. level voltages, which can represent 1 or 0. • Decimals – Used by humans • Hexadecimals or sometimes octal numbers – For neat binary representation – For easy number conversion between binary and decimal • Please see the additional material provided S2, 2008 COMP9032 Week1 11 S2, 2008 COMP9032 Week1 12

  4. Binary Additions Binary Multiplications • Example: • Example: – Addition of two 4-bit unsigned binary numbers. – Multiplication of two 4-bit unsigned binary How many bits are required for holding the result? numbers. How many bits are required for holding the result? 1001+0110 = (__________) 1001*0110 = (____________________) S2, 2008 COMP9032 Week1 13 S2, 2008 COMP9032 Week1 14 Examples Negative Numbers & Subtraction 2’s complement numbers • Represent the following decimal numbers using 8- • Subtraction can be defined as addition of the additive bit 2’s complement format inverse: (a) 7 a – b = a + (-b) (b) 127 • To eliminate subtraction in binary arithmetic, we can (c) -12 represent –b by two’s complement of b . • Can all the above numbers be represented by 4 bits? • In n -bit binary arithmetic, 2’s complement of b is b* = 2 n – b • An n -bit binary number can be interpreted in two different ways: signed or unsigned. What value – (b*)* = b does the 4-bit number, 1011, represent? – The MSB (Most Significant Bit) of a 2’s complement number is the sign bit (a) if it is a signed number, or • For example, for a 4-bit 2’s complement system, (b) if it is an unsigned number • (1001) � -7, (0111) � 7 S2, 2008 COMP9032 Week1 15 S2, 2008 COMP9032 Week1 16

  5. Examples Overflow in Two’s-Complement 4-bit 2’s-complement additions/subtractions • Assume a , b are positive numbers in an n -bit (1) 0101 - 0010 (5 - 2): (3) -0101 - 0010 (-5 - 2): 2’s complement systems, 0101 1011 (= 0101*) – For a+b + 1110 (= 0010*) + 1110 (= 0010*) • If a+b > 2 n-1 - 1 , then a+b represents a negative number; = 10011 = 11001 this is positive overflow . Result is 0111 * (how?) – For -a-b (2) 0010 - 0101 (2 - 5): and means -7. • If –a-b < 2 n-1 , then –a-b results in a positive number; this 0010 is negative overflow . + 1011 (= 0101*) (4) 0101 + 0010 (5 + 2): = 1101 (= 0011*). This is trivial, as no conversions are Result means - 3. required. The result is 0111 (= 7). S2, 2008 COMP9032 Week1 17 S2, 2008 COMP9032 Week1 18 Positive Overflow Detection Negative Overflow Detection Addition of 4-bit positive Positive overflow looks Negative overflow: Addition of negative twos- numbers without like this: complement numbers 1xxx without overflow: overflow looks like this: 0xxx + 1xxx 1xxx 0xxx + 0xxx = 10xxx . + 1xxx + 0xxx = 1xxx . The carry in to the MSB = 11xxx . = 0xxx . The “carry in” to the MSB must have been 0, but The carry in to the MSB The “carry in” to the MSB must have been 1, but the carry out is 1. must have been 1 must have been 0, and the carry out is 0. So negative overflow, like (otherwise the sum bit the carry out is 0. Overflow occurs when positive, occurs when would be 0), and the carry out is 1. carry in carry out. ≠ carry in carry out. ≠ S2, 2008 COMP9032 Week1 19 S2, 2008 COMP9032 Week1 20

  6. Overflow Detection Examples • For n-bit 2’s complement systems, condition 1. Do the following calculations, where all of overflow for both addition and substraction: numbers are 4-bit 2’s complement numbers. Check whether there is any overflow. – The MSB has a carry-in different from the carry- out (a) 1000-0001 (b) 1000+0101 (c) 0101+0110 S2, 2008 COMP9032 Week1 21 S2, 2008 COMP9032 Week1 22 Microprocessor Applications Instruction Set • Instruction set provides the vocabulary and grammar • A microprocessor application system can be for programmer/software to communicate with the abstracted in a three-level architecture hardware machine. • It is machine oriented – ISA is the interface between hardware and – Different machine, different instruction set software • For example – 68K has more comprehensive instruction set than ARM machine FORTRAN 90 Assembly – Same operation, could be written differently in different C program program program machines FORTRAN 90 C program • AVR program compiled compiled to ISA program to ISA program – Addition: add r2, r1 ;r2 � r2+r1 Software – Branching: breq 6 ;branch if equal condition is true ISA level – Load: ldi r30, $F0 ;r30 � Mem[F0] Hardware • 68K: ISA program executed by hardware – Addition: add d1,d2 ;d2 � d2+d1 – Branching: breq 6 ;branch if equal condition is true – Load: mov # 1234, D3 ;d2 � 1234 Hardware S2, 2008 COMP9032 Week1 23 S2, 2008 COMP9032 Week1 24

  7. Instructions Machine Code vs. Assembly Code • Basically, there is a one-to-one mapping between the • Instructions can be written in two languages machine code and assembly code – Machine language – Example (Atmel AVR instruction): • Made of binary digits For increment register 16: • Used by machines • 1001010100000011 (machine code) – Assembly language • inc r16 (assembly language) • A textual representation of machine language • Assembly language also includes directives • Easier to understand than machine language – Instructions to the assembler • Used by human beings. • The assembler is a program to translate assembly code into machine code. – Example: • .def temp = r16 • .include “mega64def.inc” S2, 2008 COMP9032 Week1 25 S2, 2008 COMP9032 Week1 26 Example (AVR instruction) Instruction Set Architecture (ISA) • Subtraction with carry • ISA specifies all aspects of a computer architecture visible to a programmer – Syntax: sbc Rd, Rr – Operation: Rd ← Rd – Rr – C – Instructions (just mentioned) – Native data types – Rd: Destination register. 0 ≤ d ≤ 31 – Registers – Rr: Source register. 0 ≤ r ≤ 31, C: Carry – Memory models • Instruction format – Addressing modes 0 0 0 0 1 0 r d d d d d r r r r 15 0 S2, 2008 COMP9032 Week1 27 S2, 2008 COMP9032 Week1 28

Recommend


More recommend