Basic Concepts
Profs. Leod & ECE3375, Winter 2022
As the first lesson in this course, these notes give some motivation for studying the subject of Microproces- sors & Microcomputers, and reviews a number of subjects that you should be proficient in from ECE2277. Finally some basic concepts about microcomputer architecture that provide an important foundation for understanding the lessons later on in this course are (re)introduced.
General Motivation
Copyright By PowCoder代写 加微信 powcoder
Students often ask us: “why should we study this subject?” 1 There are, in fact, many reasons to study microprocessors, microcon- trollers, and microcomputers depending on your interests.
If you are interested in hardware:
• Somebody has to build these systems! 1
1 Our answer is always the same: “great ques- tion, but we’re out of time, so let’s address it next class” — and then we never do. This is a technique called good time management.
• (Almost) all engineering digital or mechatronics systems have a microcontroller core.
• Designing hardware is a very specialized trade, which often translates into higher salaries.
If you are interested in software:
• It is useful to understand “what’s under the hood” of your
computer system.
• In portable electronics and other smaller devices the hardware may impose size or speed restrictions that must be accommo- dated in your software app.
• Low-level software programming is also a very specialized trade, which often translates into higher salaries.
If you are interested in systems:
• Selecting the appropriate microcontroller can greatly simplify
your design.
• Selecting the wrong microcontroller can make your project very costly, or even impossible to complete.
• Again, low-level software programming is a good skill for people who want a higher salary.
This course sits halfway between a high-level software program- ming course and the hardware-based digital logic of ECE2277.
High-level Language
Assembly Code (Mnemonics)
Machine Code (Binary)
Figure 1: Where this course is situated between computer programming and hardware design.
Review of Numbers
Hopefully you all remember about binary, hexadecimal, and binary- coded decimal numbers from ECE2277.
Definition: A bit is a binary digit, either 0 or 1. Often, a bit is physically encoded as a low voltage for 0 and a high voltage for 1.
Definition: A n-bit binary number is a sequence of n binary digits bi, which represent the number:
(bn−1bn−2…b1b0)2 =bn−1 × 2n−1 + bn−2 × 2n−2 + …
+b1 ×21 +b0 ×20. (1)
Definition: The most significant bit (MSb) in an n-bit binary number is the one representing the largest magnitude (i.e., the “2n’s place”). Typically this is the left-most bit in the sequence.
Definition: The least significant bit (LSb) in an n-bit binary number is the one representing the smallest magnitude (i.e., the 1’s place”). Typically this is the right-most bit in the sequence.
Definition: A hex (hexadecimal) number encodes a value in a base six-
teen system. Individual digits are from the set (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F).
Definition: A n-digit hex number is a sequence of n hex digits hi, which represent the number:
(hn−1hn−2…h1h0)16 = hn−1 × 16n−1 + hn−2 × 16n−2 + … + h1 × 16 + h0. 3
Binary 0000 0001 0010 0011 0100 0101 0110 0111 Decimal 0 1 2 3 4 5 6 7 Hex 01234567
Binary 1000 1001 1010 1011 1100 1101 1110 1111 Decimal 8 9 10 11 12 13 14 15 Hex 89ABCDEF
Definition: A nibble is a four bit binary number.
There is a simple mapping between binary numbers and hexadeci- mal numbers, as each nibble in the binary number corresponds to a single hex digit.
• It is straightforward to convert from hex to decimal, or from binary to decimal, but it is a bit cumbersome (especially as numbers get larger). It is also rarely useful.
• It is much more useful to convert from binary to hexadecimal (or vice versa)
• Converting from binary to hexadecimal (or vice versa) is also easy to do if you use the nibble-to-hex conversion shown in Table 1.
In previous iterations of the course we would advise students to memorize the nibble-to-hex conversion table. Since everything is online and probably open-book, you don’t have to memorize it but
Table 1: Mapping between nibbles (4-bit binary numbers), decimal numbers, and hex digits.
you should keep it handy at all times. To finish of this set of definitions:
2 When Prof. McLeod calls you at 3 am and demands to know the hex digit that corresponds to 11012, you should blurt out “D!” without even thinking, before you ask “wait, how did you get my number?”
Definition: A byte is an eight bit binary number (or two nibbles). Many (most?) computer systems use a byte as the size of the basic memory cells for data storage.
Definition: A word is a larger binary number, with various definitions de- pending on the context. The most common definition is that a word is the size of the memory registers in the computer pro- cessor. In the microprocessors used in the labs for this course, a word is 32 bits.
Review of Binary Coded Decimal
Some students may be unfortunate enough to remember binary coded decimal (BCD) from ECE2277. Other students will be even more unfortunate as now they will have to learn it all over again.
Definition: Binary coded decimal uses each nibble to encode a single decimal digit.
Since a nibble can store up to 16 distinct values, and there are only 10 distinct decimal digits, BCD is an inherently inefficient (i.e. less compact) method of storing data. The only advantage of BCD is that it makes it easier to convert from decimal into binary. If you, a human most familiar with decimal, need to hand-check the output from a computer system, then BCD is a good choice.
• Note that there is no way to tell whether a given set of nibbles is supposed to represent a BCD number or a standard binary value.
Fortunately, we don’t need to use BCD very much in this course.
Aside: The Y2K bug was caused by legacy banking computers using a single byte (two nibbles) to encode the year using BCD. 3 When the year 2000 rolled around some (not most, fortu- nately) computer systems had their dates rolled back to 1900. But that was (probably?) before you were born, so…
3 Apparently, memory was expensive enough that they could only dedicate one byte to storing the year, but also the computer system was untrustworthy enough that they needed to
code in BCD to make the raw data values more human-readable.
Review of Negative Numbers
In a pure binary system, the only symbols available are 0 and 1. Consequently all forms of information must be encoded using those symbols. This presents a challenge when trying to represent nega- tive numbers: sticking a − sign in front of the string of digits is not an option.
• There are several different ways of representing negative num- bers in binary: signed magnitude, one’s complement, and two’s complement.
• Two’s complement is the best and most common method, and the only one you need to know in this course.
Definition: The complement b of a bit b is found by “flipping” or “invert- ing” the bit — meaning to change its value from 1 to 0, or from 0 to 1.
Definition: The two’s complement representation of a negative binary number is found by taking the complement of each bit, then adding 1.
As an example, consider some 8 bit binary numbers:
• Decimal 510 is (0000 0101)2, so −510 in two’s complement is
(1111 1010)2 + 12 = (1111 1011)2.
• Decimal 3910 is (0010 0111)2, so −3910 in two’s complement is
(1101 1000)2 + 12 = (1101 1001)2. 7
The most significant bit in the a two’s complement number indi- cates the sign of the number: if that bit is a 1 the number is negative, if it is zero it is positive. Consequently, a n-bit two’s complement binary number can store values from −2n−1 (represented as a one followed by n − 1 zeros) up to 2n−1 − 1 (represented as a zero fol- lowed by n − 1 ones).
Definition: An alternative definition of two’s complement is to consider the MSb as a negative number. In an N-bit number, this has a value −bN−1 × 2N−1:
(bn−1bn−2…b1b0)2 =−bn−1 × 2n−1 + bn2 × 2n−2 + …
+b1 ×21 +b0 (2)
The red colours is used to highlight the difference between this definition of a two’s complement number the definition of an unsigned binary number from Equation 1.
As an example, consider the same binary numbers from before in two’s complement.
• Decimal −510 in two’s complement is (1111 1011)2, which is −(1000 0000)2 + (0111 1011)2 = −12810 + 12310 = −510.
• Decimal −3910 in two’s complement is (1101 1001)2, which is −(1000 000)2 + (0101 1001)2 = −12810 + 8910 = −3910.
This alternative definition also works for two’s complement num- bers which are not negative.
• Decimal +9710 in two’s complement is (0110 0001)2, which is −(0000 0000)2 + (0110 0001)2 = 9710.
Important! Suppose you find the binary sequence (1001 0110)2 stored in a computer system’s memory. As a hex code, 10012 = 916 and 01102 = 616. What is the corresponding number?
• Is it an unsigned decimal number, 15010?
• Is it a two’s complement decimal number, −10610? • Is it a BCD decimal code, 9610?
The answer is that there is no way to tell without some addi- tional information. They all look the same to the computer — we impose meaning on the data by what we do with it.
Review of Binary Arithmetic
Binary values can be added following the normal rules for arith- metic. To perform the subtraction A − B in binary, we should first take the two’s complement of B and then add the two values, 4 and then of course the normal rules for arithmetic addition are fol- lowed.
• There is a major potential problem with binary arithmetic, as binary sequences usually have finite width.
Definition: The width of a piece of information is the number of bits available to store that information.
Definition: Overflow occurs when an arithmetic operation exceeds the available width available for binary values.
There are two kinds of overflow, depending on whether the opera- tion is signed or unsigned arithmetic.
• When unsigned addition exceeds the available width, the highest order bit is lost. As an example, consider the follow- ing unsigned addition using 8-bit binary numbers:
(255)10 + 510 = (260)10
(1111 1111)2 + (0000 0101)2 = (0000 0100)2 + (1 0000 0000)2.
The last value (in red) is lost, because it is larger than the available width. Therefore the solution to 255 + 5 is incorrectly return as 410.
4 This is equivalent to A − B = A + (−B).
• When signed addition improperly changes the MSb, the re- sult of the arithmetic suddenly changes sign. As an example, consider the following signed addition using 8-bit binary numbers:
(127)10 + 110 = (128)10
(0111 1111)2 + (0000 0001)2 = (1000 0000)2.
The values did not exceed the available width, and the answer is correct if the values were unsigned. But if we are expecting an answer in two’s complement form, the result is incorrectly returned as (−128)10.
Unsigned overflow is handled by passing a carry-out bit back with the result of the arithmetic operation.
Definition: In a n-bit system, a carry-out bit can be thought of as the (n + 1)th digit (of value bn × 2n).
Unsigned overflow can be accommodated by allowing a single number to be spread across multiple data elements.
• Since memory cells are often in units of bytes, we can have a single number stored in multiple bytes.
• Each time an arithmetic operation returns a non-zero carry- out bit, we know we need to add another most significant byte (MSB) to store that number.
Signed overflow is more difficult to deal with, as the problem is not related to a lack of memory width.
• Without any other context (such as the words “signed” or “unsigned”), you can assume the term overflow applies to
signed overflow. 5
When adding signed numbers, the following rules apply for posi-
tive P and negative N numbers:
• PP: Adding two positive numbers should never cause a carry-
out, but if the sum is negative the result is invalid.
• NN: Adding two negative numbers should always cause a carry-out (which is ignored), but if the sum is positive the result is invalid.
• NP: Sometimes there will be a carry-out (which is ignored). The result is always valid.
How these concepts apply to microprocessors will be discussed in more detail later on.
5 This is what we did in ECE2277 as well.
Review of Combinational Logic
Hopefully you remember the symbols and truth tables for AND and OR gates, as shown in Figure 2 and Table 2. We will not make very heavy use of these logic gates in this course. Hopefully you also remember minterms, as they are rather important.
Definition: A minterm is a AND operation on n inputs (or their comple- ments). It returns true (1) when all inputs are true (1) and all complemented inputs are false (0).
Definition: An alternative definition of a minterm is that it detects a sin- gle binary value.
To demonstrate the second definition, consider the Boolean expres- sion:
f(A3,A2,A1,A0) = A3A2A1A0.
Thisreturnsanoutput1wheneverA3 =A0 =0andA2 =A1 =1si- multaneously. If the inputs are interpreted as a 4-bit binary number
(A3A2A1A0)2, then this minterm detects the value (0110)2 = 610.
• Consequently, we usually identify this minterm by the index 6
(as m6 or “minterm 6”).
• Every possible value of a n-bit binary number corresponds to
one and only one n-input minterm. 13
operations AND (xy) and OR (x + y). x y xy x+y
0000 0101 1001 1111
Table 2: Truth tables for the binary logic opera- tions AND (xy) and OR (x + y).
Figure 2: Circuit symbols for the binary logic
A decoder extends this concept. We talked about decoders in a gen- eral sense in ECE2277, but here we will consider using decoders to detect a set, or range, of numbers. Consider the following Boolean expression:
f(A3,A2,A1,A0) = A3A1.
Wecaninterpretthisasacircuitthatreturns1whenA3 =0and A1 =1,orbyconsideringimplementingthiscircuitasadecoder we can describe this as a circuit that detects all numbers in the set
(0x1x)2 ={0010,0011,0110,0111}2.6 Wewillseehowthisisuseful for microprocessors later on.
6 This is basically what we used to do with Karnaugh maps.
Review of Sequential Logic
Hopefully you remember something about flip flops. In this course, flip flops are considered one-bit memory cells. Flip flops are al- ways clocked, and usually have an asynchronous preset and reset (or clear).
Definition: A clock is a single bit that switches between 0 and 1 at a regu- lar, periodic interval. A clock is a special input for most of the components in a microprocessor. A clock helps keep all parts of the microprocessor synchronized.
A set of flip flops is a register. An n-bit register loads a n-bit binary value on a rising clock edge when the load input (LD) is 1.
• Depending on the context, you can consider a n-bit register as either storing a single n-bit number, or just a collection of n different bits held together for convenience.
• In other words, depending on the application, the contents of a register are not necessarily a single data value.
• For example, the ARM®Cortex-A9 microprocessor used in the lab have 32-bit registers (the size of a word for this system), while the memory has 8-bit cells. A register can hold a single 32-bit number (from four memory cells), or it could hold four different 8-bit numbers. Or it could hold thirty-two 1-bit control flags, or any combination thereof. We will see these situations later in this course.
Figure 3: Circuit symbols for the three most common flip flops.
A counter is a special kind of register that can be used to periodi- cally increment or decrement the bit sequence stored inside (this necessarily presumes that the contents of the counter are a single number, not a collection of independent bits).
• Counters with an enable input (EN) can be used as a stan- dard register when EN is 0.
• Counters will count up (or down, as configured) on every rising clock edge.
• When a counter reaches the maximum (or minimum) value, they wrap around to zero (or maximum) and emit a carry-out (or borrow).
As we will discuss later, a microprocessor has several counters. The ones that are user-accessible usually consist of more than one register — at least one for holding the count value, and at least one more for holding the instructions that control the counter’s operation.
• Only the counting register (the one that holds the count) would be called a “counter” in terms hardware circuitry, but in this course is it convenient to call the entire set of registers a
“counter”.
Circuit symbols for registers and counters are shown in Figure 4. Please note that the label “D[n]” is used for input data, regardless of how the register or counter is implemented — i.e., it is not neces- sarily the case that D-type flip flops are used.
D[n] Q[n] Register
Figure 4: Circuit symbol for a n-bit register and an n-bit counter. Here this counter allow the current count value to be read from Q[n]. Note that the line with a slash through it (for D[n] and Q[n]) is the symbol for a data bus — a set of n lines.
Computer Bus Structures
As a final topic to review, consider the circuit shown in Figure 5. This is something you can easily build on a breadboard — but you should not! What is the output F ?
• VCC is logical 1 and ground is logical 0.
• TheANDgatewillprovideanoutputof0,as1·0=0. • TheORgatewillprovideanoutputof1,as1+0=1.
• Wiring the two outputs together creates an ambiguous, and possibly dangerous, configuration (the high-voltage from the OR gate will try to force current to flow backwards into the AND gate).
The circuit from Figure 5 is a good circuit to build if you want an excuse to go shopping for new electronics. However the design principle behind this circuit is sound: often we want multiple com- ponents to connect to output.
• Obviously each component can’t “talk” at once, which is why we need some control element to select which component controls the output.
• This control element is called a tri-state driver (or “tri-state buffer”). 7
Definition: A tri-state driver is a circuit element with a single input bit, a single control bit, and a single output bit. Unlike most digital
Figure 5: A simple, but ill-advised, logic circuit.
7 We covered these briefly in ECE2277.
electronics, however, it has three possible output states: 1, 0, and high impedance.
It is this high impedance state that allows multiple components to
connect to the same output. The high impedance state is basically a “shut up” state, effectively disconnecting the input from the output line — so the other components in the circuit can set the logic value
for that line. To fix the circuit in Figure 5, we should connect tri- state drivers to the outputs from each gate, and have those drivers controlled by a common line so only one can be active at a time. This is shown in Figure 7.
Figure 6: A tri-state driver. When EN = 1, y = x. When EN = 0, y is floating — it is disconnected from x.
Figure 7: Fixing the pointless logic circuit from Figure 5. Now the control line c allows the output from only one of the two logic gates to be selected for F .
Microcontroller Architecture
What is the difference between a microprocessor, a microcontroller, and a microcomputer? I (Prof. McLeod) am pretty sloppy with these terms, but let’s get some definitions out of the way.
Definition: A bus is a set of wires used to move binary information be- tween various electronic circuits.
Definition: A microprocessor is a central processing unit (CPU) on a single integrated circuit (i.e., a chip). Outside of the registers in the CPU, a microprocessor has no memory storage, has no permanent memory storage, and has no other peripherals. The main bus for controlling all these components is therefore external to the chip.
• The normal laboratories in this course are based on an ARM®Cortex-A9 microprocessor.
Definition: A microcontroller contains a microprocess
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com