Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a...

91
Compiled by 03IT44 - 1 - Microprocessor Basics The majority of people think that computers are some kind of complicated device that is impossible to learn and infinitely intelligent, able to think better than a person. The truth is much less glamorous. A computer can only do what the programmer has told it to do, in the form of a program. A program is just a sequence of very simple commands that lead the computer to solve some problem. Once the program is written and debugged (you hardly ever get it right the first time), the computer can execute the instructions very fast, and always do it the same, every time, without a mistake. And herein lies the power of a computer. Even though the program consists of very simple instructions, the overall result can be very impressive, due mostly to the speed at which the computer can process the instructions. Even though each step in the program is very simple, the sequence of instructions, executing at millions of steps per second, can appear to be very complicated, when taken as a whole. The trick is not to think of it as a whole, but as a series of very simple steps, or commands. The microprocessor itself is usually a single integrated circuit (IC). Most microprocessors, or very small computers, (here after referred to simply as micro's) have much the same commands or instructions that they can perform. They vary mostly in the names used to describe each command. In a typical micro, there are commands to move

Transcript of Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a...

Page 1: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 1 -

Microprocessor Basics

The majority of people think that computers are some kind of complicated device that is impossible to learn and infinitely intelligent, able to think better than a person. The truth is much less glamorous.

A computer can only do what the programmer has told it to do, in the form of a program. A program is just a sequence of very simple commands that lead the computer to solve some problem. Once the program is written and debugged (you hardly ever get it right the first time), the computer can execute the instructions very fast, and always do it the same, every time, without a mistake.

And herein lies the power of a computer. Even though the program consists of very simple instructions, the overall result can be very impressive, due mostly to the speed at which the computer can process the instructions. Even though each step in the program is very simple, the sequence of instructions, executing at millions of steps per second, can appear to be very complicated, when taken as a whole. The trick is not to think of it as a whole, but as a series of very simple steps, or commands.

The microprocessor itself is usually a single integrated circuit (IC). Most microprocessors, or very small computers, (here after referred to simply as micro's) have much the same commands or instructions that they can perform. They vary mostly in the names used to describe each command. In a typical micro, there are commands to move data around, do simple math (add, subtract, multiply, and divide), bring data into the micro from the outside world, and send data out of the micro to the outside world. Sounds too simple....right?

A typical micro has three basic parts inside. They are the Program Counter (PC), Memory, and Input / Output (I/O). The Program Counter keeps track of which command is to be executed. The Memory contains the commands to be executed. The Input / Output handles the transfer of data to and from the outside world (outside the micro's physical package). The micro we'll be using is housed inside a 40 pin package, or chip or IC. There are many other actual parts inside our micro however, we will learn about each and every single one, one step at a time.

A Simple Program

As stated before, a program is a sequence or series of very simple commands or instructions. A real world example program might be the problem of crossing a busy street.

Step 1: Walk up to the traffic lights and stop. Step 2: Look at the traffic light. Step 3: Is your light green? Step 4: If the light is red, goto step 2. (otherwise continue to step 5) Step 5: Look to the left.

Page 2: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 2 -

Step 6: Are there cars still passing by?Step 7: If yes, goto step 5. (otherwise continue to step 8)Step 8: Look to the right. Step 9: Are there cars still passing by? (there shouldn't be any by now, but, you never know!) Step 10: If yes, goto step 8. (otherwise continue to step 11) Step 11: Proceed across the street, carefully!Now this may seem childish at first glance, but this is exactly what you do every time you cross a busy street, that has a traffic light (at least, I hope you do). This is also exactly how you would tell a micro to cross the street, if one could. This is what I mean by a sequence or series of very simple steps. Taken as a whole, the steps lead you across a busy intersection, which, if a computer did it, would seem very intelligent. It is intelligence, people are intelligent. A programmer that programmed these steps into a micro, would impart that intelligence to the micro. The micro would not, however, in this case, know what to do when it got to the other side, since we didn't tell it. A person, on the other hand, could decide what to do next, at a moments notice, without any apparent programming. In the case of a person, though, there has been some programming, it's called past experiences. Another program might be to fill a glass with water from a tap. Step 1: Turn on the water. Step 2: Put the glass under the tap. Step 3: Look at the glass. Step 4: Is it full?Step 5: If no, goto step 3.(otherwise, continue to step 6) Step 6: Remove the glass from under the tap Step 7: Turn off the water. This is a simpler program, with fewer steps, but it solves a problem, to fill a glass with water. In a micro, the problems are different but the logical steps to solve the problem are similar, that is, a series of very simple steps, leading to the solution of a larger problem. Also notice that since the steps are numbered, 1 through 7, that is the order in which they're executed. The Program Counter, in this case, is you, reading each line, starting with 1 and ending with 7, doing what each one says. In a micro, the Program Counter automatically advances to the next step, after doing what the current step says, unless a branch, or jump, is encountered. A branch is an instruction that directs the Program Counter to go to a specific step, other than the next in the sequence. The branch in this example is step 5. Not only is this a branch, but it is a conditional branch. In other words, based on whether the glass is full or not, the branch is taken, or not. A micro has both branch and conditional branch instructions. Without this ability to reuse instructions, in a sort of looping action, a solution would take many more steps, if it would be possible at all. The point of this lesson is to show how a simple set of instructions can solve a bigger problem. Taken as a whole, the solution could appear to be more complicated than any of the separate steps it took to solve it. The most difficult problem to be solved in programming a micro is to define the problem you are trying to solve. Sounds silly but I assure you, it's not. This is the Logical Thought Process I mentioned earlier. It is having a good understanding of the problem you're

Page 3: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 3 -

trying to solve. You must understand the information I'm presenting in order pass the course. Trying to remember everything does not work at university.

Decimal, Binary & Hex Most people have learned to use the Decimal numbering system for counting and calculations. But micros use a different system. It's called Binary and that’s why our computers are called binary computers! All numbering systems follow the same rules. Decimal is Base 10, Binary is Base 2, and Hex(adecimal) is Base 16. The base of a system refers to how many possible numbers can be in each digit position. In decimal, a single digit number is 0 through 9. In binary a single digit number is 0 or 1. In hex a single digit number is 0 through 9, A,B,C,D,E, and F. In decimal, as you count up from 0, when you reach 9, you add 1 more, then you have to add another digit position to the left and carry a 1 into it to get 10 (ten). Ten is a two digit decimal number. In binary, as you count up from 0, when you reach 1, you add 1 more, then you have to add another digit position to the left and carry a 1 into it to get 10B (two decimal). While this is exactly what you do in decimal, the result looks like ten so we usually write the letter ‘B’ after to distinguish it from ten decimal. [ We should really denote ten decimal as 10D but we usually leave off the ‘D’]. So while decimal 10 (ten) looks like binary 10 (two decimal) they represent different decimal values. It is still useful to think in decimal, since that's what we're used to, but we have to get used to seeing numbers represented in binary. In hexadecimal (hex), as you count up from 0, when you reach 9, you then go to A ten decimal), then B (eleven decimal), etc., until you reach F (15 decimal). When you reach F, you then add 1 more, then you have to add another digit position to the left and carry a 1 into it to get 10H (sixteen decimal). While this is exactly what you do in decimal, the result looks like ten or 10B, so we usually write the letter ‘H’ after to distinguish it from ten decimal and binary 10B. So while decimal 10 (ten) and binary 10B looks like hex 10H, they represent different values. It is still useful to think in decimal, since that's what we're used to, but we have to get used to seeing numbers represented in binary and hex. Another small difference between decimal terminology and binary is that in binary a digit is called a bit. It gets even more confusing by the fact that 4 bits make a nibble. Two nibbles make a byte. Two bytes make a word. Most numbers used in a micro don't go beyond this, although there are others. Using what I've just said, if two nibbles make a byte, you could also say that a byte is eight bits. To represent a binary number larger than 4 bits, or a nibble, a different numbering system is normally used. It is called hexadecimal, or Base 16. A shorter name for hexadecimal is simply hex, and that's what we'll use here after. In this system there are 16 possible numbers for each digit. For the first 10, 0 through 9, it looks like decimal. Unlike decimal, when you add 1 more to 9, you get A. I know that having a letter to represent a number is really confusing, but they had to call it something, and A is what they chose. So a hex A is a decimal 10 (ten). The numbers count up from A through F. Just to clarify this here is the sequence of counting in hex from 0 to where you have to add another digit position to the left... 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F (no G). This represents adecimal count of 0 through 15. At a count of F (15 decimal), if you add 1 more you get 10 (oh no! .. not another 10 that means something else!!). Sad but true.

Page 4: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 4 -

Let's regroup here. A binary 10 (one zero) is decimal 2, a decimal 10 is ten, and a hex 10 is decimal 16. If you can get this concept, you will have conquered the most difficult part of learning micros. I need to get past one more obstacle, the idea of significance. In a decimal number like 123, 3 is the least significant digit position (the right most digit) and 1 is the most significant digit position (the left most digit). Significance means the relative value of one digit to the next. In the number 123 (one hundred twenty three) , each number in the right hand most digit position (3) is worth 1. The value of each number in the next most significant digit position (2) is worth ten and in the most significant digit position (1) each is worth a hundred. I'm not trying to insult your intelligence here, but rather to point out the rule behind this. The rule is that no matter what base you're working in, as you start adding digits to the left, each one is worth the base times (multiplied) the digit to the right. In the decimal number 123 (base 10), the 2 digit position is worth 10 times the 3 digit position and the 1 digit position is worth 10 times the 2 digit position. Hence the familiar units, tens, hundreds, and so on. For some reason, for most people, this makes sense for decimal (base 10) but not for any other base numbering system. The very same is true for binary. The only difference is the base. Binary is base 2. So in binary the least significant bit (remember bits?) is worth 1 ( this happens to be the same for all bases). The next most significant bit is worth 2, the next worth 4, the next worth 8, and so on. Each is 2 times (base 2) the previous one. So in an 8 bit binary number (or byte, remember bytes?), starting from the right and moving left, the values for each of the 8 bit positions are 1, 2, 4, 8, 16, 32, 64 , and 128. If you've got this, you have passed a major milestone, you should go celebrate your passage. If you haven't, I would re-read the above until you do, and then go celebrate!! ( By the way, if you didn't get this the first time through, join the crowd. I didn't either!!) In hex (base 16) the same rule applies. In a 4 digit hex number, starting at the right and working left, the first digit is worth 1 ( hey that's just like decimal and binary!!), the next is worth 16 (base times the previous digit), the next is worth 256 (16 X 16), and the most significant is worth 4096 (256 X 16). One last note, hex is just binary described another way. A hex digit is a binary nibble ( remember nibbles?). Both are 4 bit binary values. Trying to wrap all this confusion up in review, 4 bits is a nibble or a hex digit. Two hex digits is a byte or 8 bit binary. A 4 digit hex number is a word, or 16 bit binary or 4 nibbles, or 2 bytes. You may have to review the previous paragraphs a few times (I did!!) to get all the relationships down pat, but it is crucial that you are comfortable with all I've said, so that what follows will make more sense. Let's take a few example numbers and find the decimal equivalent of each. Let's start with the binary number 1011, a nibble. Starting at the right and moving left, the first digit is worth one, because there is a 1 there. The next is worth two, because there is a 1 in it. The next would be worth 4, but since there is a 0, it's worth zero. The last or most significant is worth eight, since there is a 1 in it. Add all these up and you get eleven. So a binary 1011 is decimal 11. Also, since this could be a hex digit, the hex value would be B. Let's take a longer binary number 10100101. Starting at the right moving left, the first is worth 1, the next is worth 0, the next is worth 4, the next is 0, the next is 0, the next is worth 32, the next is 0, and the last is 128. Adding all these up you get decimal 165. Dividing this number up into two hex digits, you get A5. So binary 10100101, decimal

Page 5: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 5 -

165, and hex A5 are all the same value. Using hex, the rightmost digit is worth 5, and the most significant digit is worth 160 (10 X 16), resulting in decimal 165. If you understand this, you’re ready to move on, leaving the different systems behind. If you don't, keep reviewing and studying until you do. If you don't understand and still continue, you will be confused by what follows. I promise that once you get this, the rest is easier. This ends the second lesson. I hope this wasn't too daunting or difficult, but there was a lot to get through. The rest of the course should be a little easier. Learning a new numbering system is like learning a new language. It's a little cumbersome at first, but it gets easier.

Microprocessor Instructions As mentioned earlier, we refer to a binary number like 1111 as 1111b, a decimal number like 123 as 123, and a hex number like A5 as A5h. So don't be confused by the letters following numbers, we use both caps and lowercase to denote binary, decimal, or hexadecimal so there is no doubt what base a multidigit, or multibit, number is in. Also there is another kind of memory, called flags. Flags are single bit numbers used to indicate different conditions. They are called flags because they flag the program of events or conditions. If a flag is raised, or has a 1 in it, it is said to be SET. If it is a 0, it is said to be CLEARED or RESET. One other thing, in an 8-bit byte, the 8 bits are referred to as bits 0 through 7, with bit 0 being the right most, or least significant (lsb), and bit 7 as the left most or most significant (msb). Lastly, there are various Registers inside a microprocessor or Central Processing Unit (CPU). These vary from CPU to CPU, but all contain a register called the Accumulator. It is also referred to in some as the A register. We will be using the accumulator in the following discussion. It is a type of memory for storing temporary results and is 8 bits wide, or a byte, as are most places that data can be put inside the CPU. In the CPU we will be using, there are 5 different types of instructions and several variations of each, resulting in over 100 different instructions. These 4 types are ARITHMETIC, LOGICAL, BRANCHING, and DATA TRANSFER.

ARITHMETIC The arithmetic instructions usually include addition, subtraction, division, multiplication, incrementing, and decrementing although division & multiplication were not available in most early CPU’s. There are two flags used with arithmetic that tell the program what was the outcome of an instruction. One is the Carry (C) flag. The other is the Zero (Z) flag. The C flag will be explained in the following example of addition. The Z flag, if set, says that the result of the instruction left a value of 0 in the accumulator. We will see the Z flag used in a later lesson.

Addition This is straightforward and is simply to add two numbers together and get the result. However there is one more thing. If, in the addition, the result was too big to fit into the accumulator, part of it might be lost. There is a safeguard against this. Take the case of 11111111b (255) and 11111111b (255). These are the largest numbers that can fit into an 8-bit register or memory location. You can add these as decimal numbers, since I gave

Page 6: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 6 -

you their values in decimal also, and you would get 510. The binary value for 510 is 111111110b (9 bits). The accumulator is only 8 bits wide, it is a byte. How do you fit a 9bit number into 8 bits of space? The answer is, you can't, and it’s called an OVERFLOW condition. So how do we get around this dilemma? We do it with the CARRY (C) flag. If the result of the addition is greater than 8 bits, the CARRY (C) flag will hold the 9 th bit. In this case the accumulator would have in 11111110b (254) and the C flag would be a 1, or set. This 1 has the value of 256 because this is the 9th bit. We haven't covered a 9-bit number, but they come up all the time as overflows in addition. Since we are using base 2, and we found out in lesson 2 that the 8th bit (bit 7) in a byte is worth 128, then the 9th bit is worth 2 times that, or 256. Adding 254 and 256, we get 510, the answer, and we didn't loose anything, because of the C flag. Had the result of the addition not caused an overflow, the C flag would be 0, or cleared.

Subtraction In the case of subtraction, the process is more difficult to explain, and as such, I'm not going to cover it here. It involves 1's compliment and 2's compliment representation. But I will tell you this, you can subtract two numbers and if there is an under flow, the C flag will be a 1, otherwise it will be a 0. An under flow is where you subtract a larger number from a smaller number.

Multiplication and Division In the micro we will be using, the 8085, multiply and divide instructions are not available so we will wait till later (EL31G-Microprocessors II) to talk about them. They do, however, do just what the names suggest.

Increment & Decrement Two other instructions are included in the arithmetic group. They are increment and decrement. These instructions are used to count events or loops in a program. Each time an increment is executed, the value is incremented by 1. A decrement, decrements the value by 1. These can be used with conditional jumps to loop a section of program, a certain number of times. We will see these used later.

LOGICAL In micros there are other mathematical instructions called logical instructions. These are OR , AND, XOR, ROTATE, COMPLEMENT and CLEAR. These commands are usually not concerned with the value of the data they work with, but, instead, the value, or state, of each bit in the data.

OR The OR function can be demonstrate by taking two binary numbers, 1010b and 0110b. When OR'ing two numbers, it doesn't matter at which end you start, right or left. Let's start from the left. In the first bit position there is a 1 in the first number and a 0 in the second number. This would result in a 1. The next bit has a 0 in the first number and a 1 in the second number. The result would be 1. The next bit has a 1 in the first number and a 1 in the second number. The result would be a 1. The last bit has a 0 in the first number

Page 7: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 7 -

and a 0 in the second number, resulting in a 0. So the answer would be 1110b. The rule that gives this answer says that with an OR, a 1 in either number result in a 1, or said another way, any 1 in, gives a 1 out.

AND AND'ing uses a different rule. The rule here is a 0 in either number will result in a 0 , for each corresponding bit position. Using the same two numbers 1010b and 0110b the result would be 0010b. You can see that every bit position except the third has a zero in one or the other number. Another way of defining an AND is to say that a 1 AND a 1 results in a

1. XOR (eXclusive OR) XOR'ing is similar to OR'ing with one exception. An OR can also be called an inclusive OR. This means that a 1 in either number or both will result in a 1. An eXclusive OR says that if either number has a 1 in it, but not both, a 1 will result. A seemingly small difference, but crucial. Using the same two numbers, the result would be 1100b. The first two bits have a 1 in either the first or the second number but not both. The third bit has a 1 in both numbers, which results in a 0. The fourth has no 1's at all, so the result is 0. The difference may seem small, even though the OR and XOR result in different answers. The main use of an XOR is to test two numbers against each other. If they are the same, the result will be all 0's, otherwise the answer will have 1's where there are differences.

Compliment Complimenting a number results in the opposite state of all the 1's and 0's. Take the number 1111b. Complimenting results in 0000b. This is the simplest operator of all and the easiest to understand. Its uses are varied, but necessary, as you'll see later.

Rotate These instructions rotate bits in a byte. The rotation can be left or right, and is done one bit each instruction. An example might be where the accumulator has a 11000011b in it. If we rotate left, the result will be 10000111b. You can see that bit 7 has now been moved into bit 0 and all the other bits have move 1 bit position in, the left direction.

Clear This instruction clears, or zero's out the accumulator. This is the same as moving a 0 into the accumulator. This also clears the C flag and sets the Z flag.

BRANCHING There are also program flow commands. These are branches or jumps. They have several different names reflecting the way they do the jump or on what condition causes the jump, like an overflow or under flow, or the results being zero or not zero. But all stop the normal sequential execution of the program, and jump to another location, other than the next instruction in sequence.

Jump on Condition (of a Bit) These instructions let you make a jump based on whether a certain bit is set (a 1) or

Page 8: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 8 -

cleared (a 0). This bit can be the CY (carry) flag, the Z (zero) flag, or any other bit.

Call There is also a variation on a jump that is referred to as a CALL. A CALL does a jump, but then eventually comes back to the place where the CALL instruction was executed and continues with the next instruction after the CALL. This allows the programmer to create little sub-programs, or subroutines, that do repetitive tasks needed by the main program. This saves programming time because once the subroutine is written, it can be used by the main program whenever it needs it, a kind of way to create your own instructions.

DATA TRANSFER

Moving These instructions do exactly what you would think. They move data around between the various registers and memory.

Exchanging Exchanging is a variation on the move instruction. Here data is exchanged between two places. This is the end of lesson 3. I've tried to briefly explain all the possible instructions without actually showing each. I will, in a later lesson, go into each of the 100+ different instructions and explain each one. In the next lesson we will learn more about memory and all the possible ways to get to a memory location.

Memory and AddressingThere are several different types of memory in a micro. One is Program memory. This is where the program is located. Another is Data memory. This is where data, that might be used by the program, is located. The neat (or strange) thing is that they both reside in the same memory space and can be altered by the program. That’s right, a program can actually alter itself if that was necessary. Two terms are used when talking about memory. Reading (load) is getting a value from memory and Writing (store) is putting a value into memory. There are three buses (not the kind you ride in) associated with the memory subsystem. One is the address bus, the second is the data bus, and the third is the control bus. It's important for you to know exactly how all this works, because these busses transport data and addresses everywhere. All three are connected to the memory subsystem. Its also good to know the function of each to better understand what's happening. In the 8085 CPU, the address bus is 16 bits wide. It acts to select one of the unique 216 (64K) memory locations. The control bus determines whether this will be a read or a write. In the case of an instruction fetch, the control bus is set up for a read operation. Data is read or written through the data bus, which is 8 bits wide. This is why all registers and memory are 8 bits wide, it's the width of the data bus on the 8085 CPU. A bus is just a group of connections that all share a common function. Instead of speaking of each bit or connection in the address separately, for example, all 16 are taken together and referred to simply as the address bus. The same is true for the control and data buses.

Page 9: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 9 -

A byte is the most used number in a micro because each memory location or register is one byte wide. Memory has to be thought of as a sort of file cabinet with each location in it being a folder in the cabinet. In a file cabinet, you go through the tabs on the folders until you find the right one. To get to each memory location, a different method is used. Instead, a unique address is assigned to each location. In most micros this address is a word or 16 bits, or 4 digit hex. This allows for a maximum of 65536 (216 or 64K) unique addresses or memory locations that can be accessed. These addresses are usually referred to by a 4 digit hex number. Memory usually starts at address 0000h and could go up to FFFFh (216 or 64K or 65536 in total). To access these locations, a 16 bit address is presented to memory and the byte at that location is either read or written. The Program Counter is what holds this address when the micro is executing instructions. The reason instructions are read sequentially, is because the program counter automatically increments after fetching the current instruction. It does this even before the current instruction is acted upon. The sequence is that the program counter's contents are placed on the memory address bus and the instruction is fetched from memory through the data bus, and immediately the program counter is incremented by 1. Then the micro looks at the instruction and starts processing it. If the instruction is not some kind of jump or call, the instruction is completed and the program counter is presented to the memory address bus again and the next instruction is fetched, the program counter is incremented and the process starts over. This is referred to, in computer jargon, as fetch, decode, and execute. In the case of reading or writing data, the process is a little different. Data can be read from or written to memory in similar fashion to the fetch. But data does not need the decode & execute steps. In the next lesson we will see this in more detail.

What is Assembly Language? Inside the 8085, instructions are really stored as binary numbers, not a very good way to look at them and extremely difficult to decipher. An assembler is a program that allows you to write instructions in, more or less, English form, much more easily read and understood, and then converted or assembled into hex numbers and finally into binary numbers. The program is written with a text editor (NOTEPAD or similar), saved as an ASM file, and then assembled by the assembler (TASM or MASM or similar) program. The final result is an OBJ file you download to the 8085. Here is an example of the problem of adding 2 plus 2: mvi A,2 mvi B,2 add B reg. A ; move 2 into the A register ; move 2 into the B register ;add reg. B to reg. A, store result in The first line moves a 2 into register A. The second moves a 2 into register B. This is all the data we need for the program. The third line adds the accumulator with register B and stores the result back into the accumulator, destroying the 2 that was originally in it. The accumulator has a 4 in it now and B still has a 2 in it. In the program above all text after

Page 10: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 10 -

the ‘;’ are treated as comments, and not executed. This is a very important habit to acquire. Assembly language follows some rules that I will describe as they come up. With most instructions, especially those involving data transfer, the instruction is first, followed by at least 1 space, then the destination followed by a comma, and then the source. The destination is where the result of the instruction will end up and the source is where the data is coming from. Next we will read a switch, and light an LED if the switch is pressed. This happens quite often in your lab experiments. Bit 0 of Port 0 will be the switch. When the switch is closed or pressed, bit 0 will be a 1, and if the switch is open or not pressed, bit 0 will be a 0. Bit 0 of Port l be the LED. If bit 0 is a 0 the LED is off and if bit 0 is a 1, the LED will be on. All the other bits of reg. A will be ignored and assumed to be all 0's, for the sake of discussion start: IN 0 ; read Port 0 into reg. A CMP 1 ; compare reg. A with the value 1 JNZ start ; jump to start if the comparison does not yield 0 OUT 1 ; send a 1 to Port 1, turning the LED on JMP start The first line has something new. It's called a label. In this case it is start: . A label is a way of telling the assembler that this line has a name that can be referred to later to get back to it. All labels are followed by the symbol : , which tells the assembler that this is a label. In the first line we also read the switch by reading Port and putting it into the accumulator. Reg. A is the only register that can read in/send out data via ports or perform compares. Thus, we need not write ‘A’ in the command…it’s implied! The next line compares the value in reg. A with the value 1. If they are equal, the Zero flag is set (to 1). The next line then jumps to start: only if the Zero flag is not set ie: the value in reg. A is not 1 therefore the switch was not pressed. The program will therefore keep looping until the switch is pressed! If the switch is pressed then the penultimate line writes the value 1 to the accumulator, therefore bit 0 = 1, and the LED comes on. The last line jumps back to start. This completes the loop of reading the switch and writing to the LED. This particular problem could have been solved with just a switch connected to an LED, like a light is connected to a wall switch in your house. But with a micro in the loop, much more could be done. We could have a clock that also turns on and off the LED based on time. Or we could monitor the temperature and turn the LED on and off based on what temperature it is. Or we could monitor several switches and turn the LED on and off based on a combination of switches, etc….it’s up to the imagination what can be controlled. In the above example we assumed that the other bits of ports 0 and 1 were all zeros. But in reality, each of these bits could have a function assigned to them. Then we would need to look only at bit 0 in port 0 and bit 0 in port 1. This further complicates the problem. Also, we assume that port 0 was previously defined as an input port whereas port 1 was defined as an output port. In assembly we can assign a name to a port and refer to it by that name, instead of port 0

Page 11: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 11 -

or port 1. This is done with an equate directive. Directives are assembler commands that don't result in program but instead direct the assembler to some action. All directives start with a period. .equ switch, 0 ;port 0 is now called switch.equ LED,1 ;port 1 is now called LEDstart: IN switch ; read Port 0 into reg. A CMP 1 ; compare reg. A with the value 1 JNZ start ; jump to start if the comparison does not yield 0 OUT LED ; send a 1 to Port 1, turning the LED on JMP start This has the same result as the previous program. Also the equate only has to be made once at the start of the program, and thereafter the name or label is used instead of the port number. This makes things much simpler for the programmer. All equates must be defined before they are used in a program. This holds true for labels also. Another advantage of naming ports with an equate is that if, later in the design process, you decide to use a different port for the LED or the switch, only the equate has to be changed, not the program itself. Please note that comments are very important. When you initially write a program, the tendancy is not to write much in the comment field because you're in a hurry. But if you have to come back to it a few weeks later, it's much easier to understand what you've written if you've taken the time to write good comments. Also good comments help in debugging. To digress just a little here, an instruction like add B is a one byte instruction. In other words this instruction would end up inside the 8085 as one byte. Part of the byte is the opcode and the other part is which register is affected or used. The reason for this is that a prime concern in programming a micro is how may bytes the program will actually take up inside the micro, after it's been assembled. The idea is to cram as much as possible into as few bytes as possible. This is why implied addressing is used. It limits choices in the use of the instruction, you always have to use the accumulator as either the source or the destination, but it shrinks the size of the instruction, so that more instructions can fit inside the micro. This is a choice made by the maker of the micro, and is not up for discussion. It's a trade off of flexibility vs. size. That's why you'll see lots of instructions that use the accumulator. This is the best way to describe implied addressing. In the case of an instruction like mvi A,1 ,two bytes are assembled. The first byte says that this is an move instruction and that the accumulator is the destination. The second byte is the immediate data itself. Thus we see that an instruction can have it’s data ‘next’ to it. It is transparent to the programmer where the bytes are actually stored in memory. Once we can ‘find’ it by an instruction is all that matters. We will get into this again, later. Another form of addressing variables is called register indirect or just plain indirect addressing. This is a little more complicated. Here the address is held in a register, usually the H & L registers but sometimes the B & C or D & E. Since an address is 16 bits long, we need two registers (a register pair) to store an address. We will also get into this again, later.

Lastly, I want to explain something else about the assembler. The source file is what the

Page 12: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 12 -

above program, or any program that has been written, is referred to. It is the source for the assembler, or the file that is going to be read by the assembler to generate the object file (the object of the assembler) from. The object file is the file that will be download to the 8085 kit in the lab. They are two different files. One you've written with a text editor (the source or ASM file) and the other is created by the assembler (the object or OBJ file) when you assemble the source file. You use an assembler with the object in mind of generating a file to download to the micro, hence the name, object file. I've left out some directives, for simplicities sake, that I need to mention now. One is the .org directive. It is the originate or origin directive. This tells the assembler at what address the first byte of assembled code is to be placed inside the 8085. It is the origin of the program or the beginning. Here's how this would look for our last example program: .org 2000H ; begin using memory address 2000H

Well we've covered quite a lot in this lesson, and I hope you've gotten most of it. If not, I would suggest re-reading it until you do. I would also suggest that you print out all of these lessons so you can refer to them later. In the next lesson we will actually be assembling some programs and looking at the object files.

Using an Assembler If you are using a DOS based assembler, you'll need to get to DOS.

The first step in writing a program is to define the problem as completely as possible. You will always think of things as you go along that you left out. After thinking out the problem, you start by typing up a source file. Source files all end with the .asm extension. The extensions created by the assembler are .obj which is the object file and .lst which is the listing file. The listing file shows all the addresses resolved by the assembler, all the code generated and all the comments. This file is very important in for assisting you in the lab. The listing file also shows any errors in the assembly process so that you can correct them. It is crucial that you look at the listing file to be sure that there are no errors listed. The way you would use a program in real life is to write each program, assemble it, and then execute it. For instructions on how to use the 8085 microprocessor kit used in the lab (the SDK-85), please purchase the book “Using the SDK-85 Microprocessor Trainer” which is a required text for the course and available in the university bookstore.

Address Decoding

As an assembly language programmer, you know that the CPU registers have no address. Instead, you specify them by name eg: A, B, C, etc.. As a result, it may seem confusing to you that to access an I/O port, you use an address, even though they may be thought of as similar to registers. CPU registers use the fastest (and most expensive) memory technology, then cache memory uses a slightly slower technology and then system RAM uses a slower and cheaper technology. Nevertheless, all are forms of memory. In fact, you could think of standard RAM as a large collection of slow registers. The difference is simply in the way that we name them. You should also realize (especially if you have installed additional memory in your own

Page 13: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 13 -

computer) that RAM consists of multiple chips, each of which contains a number of memory locations. Each chip is physically just like every other chip. There is nothing about the chip itself that makes it hold a particular range of addresses. The locations on a single chips are linearly ordered, but there is no inherent ordering among the separate chips. The ordering comes from the way the chips are connected to the address bus. When you specify a particular address, the corresponding location exists only in one of those chips. In a very real sense, part of the address selects the correct chip (the upper part of the address), while the rest of the address selects the correct location on that chip. You can look at the low order bits as forming an offset from the first location on the chip to the correct location on the chip for the address you are specifying. The method that we use to select the correct location on the correct chip is called address decoding and we use the voltages carried on the wires of the address bus to accomplish the selection. Notice that it is critical that each address selects a unique location. In additon to talking about memory addresses in memory space (or area), we also have an area the microprocessor treats slightly different called the port (I/O) space or area. On the 8085 CPU, we know the memory space is 64K bytes as there are 16 address lines. The port (I/O) space on the 8085 is 256 bytes as there are only 8 address lines used to select a port address. More on this later. Each chip (whether it is a memory chip or a peripheral device chip) has an input called chip select ( ) or similar. To activate the chip, we must send a logic "0" (0 volts) to this input because it uses negative logic. If there is a logic "1" (+5 volts) on the wire connected to this input, the chip is inactive. Some chips also have an enable (EN) input. Chips of this type must receive a logic "1" on this input and a logic "0" on the input to be active. The fact that we can "turn on" (activate) or "turn off" (deactivate) a chip using signals like these allows us to select the correct chip for a particular address. In order to see how this works in practice, we can design an address decoder for a very tiny memory, made up in part of "conventional RAM" and in part of I/O ports. You will recall from the beginning of the semester that the number of wires on the address bus determines the number of memory locations to which we have access. Conversely, the number of locations to which we need access determines the number of address lines we need. For this example, there will be sixteen 8-bit memory locations to which we want access. This means that we will need four address lines (24 = 16). Assume that we have eight memory locations in conventional memory and eight I/O ports. If we assume that each conventional memory chip contains four memory locations, we will need two chips or banks of memory. Assume the I/O ports are on eight separate chips, each with one register (in reality, peripheral devices typically have several registers each, but the concept is the same). Arbitrarily, we will say that the eight lowest addresses will be on the conventional memory chips and the eight highest addresses will correspond to the I/O ports on peripheral devices. First, we will specify all sixteen addresses in binary, so that we can see easily which address lines will have high voltage and which will have low voltage for any particular address.

A3 A2 A1 A0

Page 14: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 14 -

0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1

1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1

The first thing we need to do is figure out how we can use the first eight patterns to activate the conventional memory chips and the second eight patterns to activate the I/O ports.

InterruptsIn a typical computer system, the software can be divided into 3 possible groups. One is the Operating Loop, another is the Interrupt Service Routines, and the last is the BIOS/OS functions and subroutines. The Operating Loop is the main part of the system. It will usually end up being a sequence of calls to BIOS/OS subroutines, arranged in an order that accomplishes what we set out to do, with a little manipulation and data transfer in between. At the same time, at least it looks like it's happening at the same time, interrupts are being serviced as they happen. In the 8085, there are thirteen (13) possible events that can trigger an interrupt. Five of them are from external hardware interrupt inputs (TRAP, RST 7.5, 6.5, 5.5, and INTR), that can be from whatever hardware we've added to the 8085 that we deem to need servicing as soon as they happen. The remainder are software instructions that cause an interrupt when they are executed (RST 0 – 7). To digress just a moment, there are two ways to service, or act on, events that happen in the system. One is to scan or poll them and the other is to use interrupts. Scanning is just what is sounds like. Each possible event is scanned in a sequence, one at a time. This is ok for things that don't require immediate action. Interrupts, on the other hand, cause the current process to be suspended temporarily and the event that caused the interrupt is serviced, or handled, immediately. The routine that is executed as a result of an interrupt is called the interrupt service routine (ISR), or recently, the interrupt handler routine. In the 8085, as with any CPU that has interrupt capability, there is a method by which the interrupt gets serviced in a timely manner. When the interrupt occurs, and the current instruction that is being processed is finished, the address of the next instruction to be executed is pushed onto the Stack. Then a jump is made to a dedicated location where the ISR is located.. Some interrupts have their own vector, or unique location where it's

Page 15: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 15 -

service routine starts. These are hard coded into the 8085 and can't be changed (see below).

TRAP -has highest priority and cannot be masked or disabled. A rising-edge pulse will cause a jump to location 0024H.

RST 7.5- 2nd priority and can be masked or disabled. Rising-edge pulse will cause a jump to location 7.5 * 8 = 003CH.

This interrupt is latched internally and must be reset before it can be used again.

RST 6.5 – 3rd priority and can be masked or disabled. A high logic level will cause a jump to location 6.5 * 8 = 0034H.

RST 5.5 – 4th priority and can be masked or disabled. A high logic level will cause a jump to location 5.5 * 8 = 002CH.

INTR – 5th priority and can be masked or disabled. A high logic level will cause a jump to specific location as follows:

When the interrupt request (INTR) is made, the CPU first completes it’s current execution. Provided no other interrupts are pending, the CPU will take the INTA pin low thereby acknowledging the interrupt. It is up to the hardware device that first triggered the interrupt, to now place an 8-bit number on the data bus, as the CPU will then read whatever number it finds on that data bus and do the following: multiply it by 8 and jump to the resulting address location. Since the 8-bit data bus can hold any number from 00 – FFH (0 – 255) then this interrupt can actually jump you to any area of memory between 0*8 and 255*8 ie: 0000 and 07FFH ( a 2K space). N.B: This interrupt does not save the PC on the stack, like all other hardware and software interrupts! You will notice that there isn't many locations between vector addresses. What is normally done is that at the start of each vector address, a jump instruction (3 bytes) is placed, that jumps to the actual start of the service routine which may be in RAM.. This way the service routines can be anywhere in program memory. The vector address jumps to the service routine. There is more than enough room between each vector address to put a jump instruction. Looking at the table above, there are at least 8 locations for each of the vectors except RST 5.5, 6.5, and 7.5. When actually writing the software, at address 0000h will be a jump instruction that jumps around the other vector locations. Besides being able to disable/enable all of the interrupts at once (DI / EI) ie: except TRAP, there is a way to enable or disable them individually using the SIM instruction and also, check their status using RIM. There are other things about interrupts that we will cover as they come up, but this lesson was to get you used to the idea of interrupts and what they're used for in a typical system. It’s similar to the scene where one is standing at a busy intersection waiting for the traffic light to change, when a person came up and tapped us on the shoulder and asked what

Page 16: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 16 -

time it was. It didn't stop us from going across the street, it just temporarily interrupted us long enough to tell them what time it was. This is the essence of interrupts. They interrupt normal program execution long enough to handle some event that has occurred in the system. Polling, or scanning, is the other method used to handle events in the system. It is much slower than interrupts because the servicing of any single event has to wait its turn in line while other events are checked to see if they have occurred. There can be any number of polled events but a limited number of interrupt driven events. The choice of which method to use is determined by the speed at which the event must be handled. The software interrupts are the instructions RST n, where n = 0 – 7. The value n is multiplied by 8 and the result forms an address that the program jumps to as it vector address ie: RST 4 would jump to location 4*8 = 32 (20H).

The STACKThe stack is one of the most important things you must know when programming. Think of the stack as a deck of cards. When you put a card on the deck, it will be the top card. Then you put another card, then another. When you remove the cards, you remove them backwards, the last card first and so on. The stack works the same way, you put (push) words (addresses or register pairs) on the stack and then remove (pop) them backwards. That's called LIFO, Last In First Out. The 8085 uses a 16 bit register to know where the stack top is located, and that register is called the SP (Stack Pointer). There are instructions that allow you to modify it’s contents but you should NOT change the contents of that register if you don't know what you're doing!

PUSH & POP As you may have guessed, push and pop “pushes” bytes on the stack and then takes them off. When you push something, the stack counter will decrease with 2 (the stack "grows" down, from higher addresses to lower) and then the register pair is loaded onto the stack. When you pop, the register pair is first lifted of the stack, and then SP increases by 2. N.B: Push and Pop only operate on words (2 bytes ie: 16 bits). You can push (and pop) all register pairs: BC, DE, HL and PSW (Register A and Flags). When you pop PSW, remember that all flags may be changed. You can't push an immediate value. If you want, you'll have to load a register pair with the value and then push it. Perhaps it's worth noting that when you push something, the contents of the registers will still be the same; they won't be erased or something. Also, if you push DE, you can pop it back as HL (you don't have to pop it back to the same register where you got it from). The stack is also updated when you CALL and RETurn from subroutines. The PC (program counter which points at the next instruction to be executed) is pushed to the stack and the calling address is loaded into PC. When returning, the PC is loaded with the word popped from the top of the stack (TOS). So, when is this useful? It's almost always used when you call subroutines. For example, you have an often used value stored in HL. You have to call a subroutine that you know will destroy HL (with destroy I mean that HL will be changed to another value, which you perhaps don't know). Instead of first saving HL in a memory location and then

Page 17: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 17 -

loading it back after the subroutine, you can push HL before calling and directly after the calling pop it back. Of course, it's often better to use the pushes and pops inside the subroutine. All registers you know will be changed are often pushed in the beginning of a subroutine and then popped at the end, in reverse order! Don't forget - last in first out. If you want to only push one 8 bit register, you still have to push it's "friend". Therefore, be aware that if you want to store away D with pushing and popping, remember that E will also be changed back to what it was before. In those cases, if you don't want that to happen, you should try first to change register (try to store the information in E in another register if you can) or else you have to store it in a temporary variable. Before executing a program, you should keep track of your pushes and pops, since they are responsible for 99% of all computer crashes! For example, if you push HL and then forget to pop it back, the next RET instruction will cause a jump to HL, which can be anywhere in the ROM/RAM and the ccomputer will crash. Note however, it’s also a way to jump to the location stored in HL, but then you should really use the JMP instruction, to do the same thing. Push and pop doesn't change any flags, so you can use them between a compare and jump instructions, depending on a condition, which is often very useful.

THE MICROPROCESSOR AGE

• The world’s 1st microprocessor was Intel 4004. It was a programmablecontroller on a chip that was meagre by today’s standards. It addressed amere, 4,096 4-bit wide memory locations. It was fabricated with the thencurrentstate-of-the-art P-channel MOSFET technology that only allowed itto execute instructions at the slow rate of 50 KIPs (kilo-instruction persecond). The 4004 weighed much less than an ounce.• The evolution of the 4-bit microprocessor ended when Intel released the4040, an updated version of the earlier 4004. The 4004 operated at higherspeed, although it lacked improvements in word width & memory size. The4-bit microprocessor still survives in low-end applications such asmicrowave ovens & small control systems & still available from somemicroprocessor manufacturers. Most calculators are also still based on 4-bitmicroprocessors that process 4-bit BCD (binary coded decimal) codes.• Later in 1971, realizing that the microprocessor was a commerciallyavailable product, Intel corporation released the 8008 – an extended 8-bitversion of 6KB memory, & 48 instructions. As technology advanced &engineers finds more demand of 8008 M.P. They feel it as small memory,slow speed & limited instructions.• Therefore in 1973 a most modern 8-bit microprocessor was developednamed as 8080. It was also designed by Intel, but after six months Motorolaintroduces MC-6800 8-bit M.P. Soon other companies also introduces then8-bit M.P.What was special about 8080?Not only 8080 could address more memory & execute external instructions,but also it executed them 10 times faster then 8008. Also, 8080 was compatiblewith TTL, whereas 8008 was 8080 made the interfacing more easier & less

Page 18: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 18 -

expensive. It was able to address four times greater memory then 8008, (16 KB).The 8085 microprocessor;In 1977, Intel Corporation introduced an updated version of 8080 – the8085. This was last 8-bit general purpose microprocessor developed by Intel.Although only slightly advanced than 8080, the 8085 executed software at an evenhigher speed. An addition that took 2.0 μ-s (500,00 instruction per second) on the8080 required only 1.3 μ-s (769,230 instructions per second) on the 8085. Themain advantages of the 8085 were its internal clock generator, internal systemcontroller, & higher clock frequency. This higher level of component integrationreduced the 8085’s cost & increased its usefulness. Another company that sold500 millions 8-bit microprocessor is Zilog corporation, which produced the Z-80microprocessor.The Modern microprocessor;In 1978, Intel released the 8086 microprocessor, a year or so later, itreleased the 8088. Both devices were 16-bit microprocessor, which executedinstructions in as little as 400 μ-s (2.5 million instruction per second). Thisrepresented the major improvement over the execution of 8085. This higherexecution speed & larger memory size allowed the 8086 & 8088 to replace smallermini-computers in many applications. One other feature found in the 8085 / 8088was a small 4- or 6-byte instructions cache or queue that prefetches a fewinstructions before they are executed.Improvements to the instruction set included the multiply - & - divideinstruction, which were missing on earlier microprocessors. Also the number ofinstructions increased from 45 on the 4004, to 246 on the 8085, to well over20,000 variations on the 8086 & 8088 microprocessors. Note that thesemicroprocessors were called CISC (complex instruction set computer) b/c of thenumber & complexity of instructions.The 16-bit microprocessor also provided more internal register storage space thanthe 8-bit microprocessor. The additional registers allowed software to be writtenmore efficiently.The popularity of the Intel family was ensured in 1981 when IBMCorporation decided to use the 8088 microprocessors in its PCs.Applications such as spreadsheets, word processors, spelling checkers, &computer based thesauruses (dictionary containing words of certain types) werememory intensive & memory required more than the 64 K bytes of memory forthese applications. Soon even 1M byte of memory proved limiting for largespreadsheets & other applications. This led Intel to introduce the 80286microprocessor, an updated 8086, in 1983.The 80286 Microprocessor;The 80286 microprocessor (also a 16-bit architecture microprocessor) wasalmost identical to the 8086 & 8088 except it addressed a 16 M byte memorysystem instead of 1M Byte systems. The clock speed of the 80286 was increased,so it executed some instruction in as little as 250 ns (4.0 MIPs) with the originalrelease 8.0 MHz version.The 32-bit Microprocessor (80386);Applications began demand faster microprocessor speeds, more memory &

Page 19: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 19 -

wider data paths. This led arrival of the 80386 in 1986, by Intel Corporation. The80386 represented a major over haul of the 16-bit 80286 microprocessor’sarchitecture. The 80386 was Intel 1st practical 32-bit microprocessor that containeda 32 data bus & a 32-bit memory address. (Note that Intel produced an earlier,although unsuccessful 32-bit microprocessor called the iapx-432).Through these 32-bit buses, the 80386 addressed up to 4 G-bytes of memory (1Gof memory contains 1024 M).The 80386 was also available in a modified versions such as the 80386 SXwhich addressed 16MB of memory through a 16-bit data and 24-bit address bus, &the 80386 SL / 80386 SLC, which addressed 32 M bytes of memory through a 16-bit data & 25-bit address bus.In 1995, Intel released the 80386 EX microprocessor. The 80386 EX iscalled an embedded PC, containing the all components of the AT class PC on asingle integrated circuit.The instruction set of the 80386 microprocessor was upward compatiblewith the earlier 8086, 8088, & 80286 microprocessors. Note that memorymanagement instructions & techniques used by the 80286 were also compatiblewith the 80386 microprocessor.

The 80486 Microprocessor;In 1989, Intel released the 80486 microprocessor, which incorporated an80386-like microprocessor, an 80387-like numeric coprocessor, & an 8K-bytecache memory system into one integrated package. Although the 80486 were notradically different from the 80386, it did include one substantial change. Theinternal structure was modified from the 80386 so about half of its instructionsexecuted in one clock instead of tow clocks. Because the 80486 was available in a50 MHz version, about half of its instructions executed in 25 ns (50 MIPs).Later versions of 80486 executed at higher speeds, 80486 DX4 triple clocked 100MHz. 80486 DX4 executed instructions at the same speed as the 60 MHz Pentium.The Pentium Microprocessor;The Pentium, introduced in 1993, was similar to the 80386 & 80486 MPs.This MP was originally labelled as P500 (80586). The two introductory versionsoperated with a clocking frequency of 60 MHz & 66 MHz & a speed of 110MIPS. The double clocked Pentium operating at 10 MHz & 133 MHz, was alsoavailable, as where higher speed versions (200 MHz). Another difference was thatthe cash size was increased to 16 K bytes from 8 K cash found in the basic versionof 80486. The memory system contain up to a full 64-bits.Probably the most ingenious features of the Pentium are its dual integersprocessors (DIP). The Pentium executes two instructions, not dependent eachother, simultaneously b/c it contains two independent internal integer processorscalled “Super-scalar technology”. This allows the Pentium to often execute twoinstructions per clocking period. Another feature that enhances performance is ajump prediction technology that speeds the execution of programs that includeloops.Motorola, Apple, & IBM has recently produced the Power PC, a RICS(reduced instruction set computer) MP that has two integer units & one floatingpoint

Page 20: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 20 -

unit.The Pentium Pro Microprocessors;The latest entry (in 1995) from Intel is the Pentium Pro MP, formerly code namedthe P6 microprocessor. The Pentium Pro MP contain 21 million transistors, 3integer units, as well as floating-point unit to increase the performance of mostsoftware. The basic clock frequency is 150 MHz & 166 MHz in initial offeringmade available in the late 1995.One other significant change is that the Pentium Pro processor uses threeexecution engines, so it can execute up to three instructions at a time, which canconflict & still execute in parallel. The Pentium Pro has 32-bit address bus ifconfigured for 64 G memory system. Currently the Super-scalar technology usesmany MPs, but they all share the same register set. This new untried technologybeing developed jointly by Intel & Hewlett-Packard, to be used in the P7, containmany MPs, that each contains their own register sets that are linked with otherMPs.

Computer is an electronic device, which has speed, accuracy and memory.Block diagram shows a simple computer. The major ports are CPU, memory, I /Ocircuitry. These three parts are connected by parallel sets of line called buses.They are, address bus, control bus, and data bus.CPU: -The central processing unit controls the operation of the computer. Itfetches binary codes instructions from memory; decode the instructions into theseries of simple actions, and carries out these actions. The CPU contains thearithmetic logic unit (ALU), which can perform add, OR, AND, invert and otheroperations on binary codes.The CPU also contains the address counter, which is used to hold theaddress of next instruction or data to be fetched from memory, general purposeregisters, which are used of temporary storage of data.

Page 21: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 21 -

I /O: -This section allows the computer to take in data from the outside world orsend to the outside world. Peripherals such as Keyboards, video display terminals,and printers are connected to the I/O section. These allow the computer and user tocommunicate with each other.The actual physical devices used to interface this computer buses toexternal system are called ports. An input port allows data from the keyboard to ananalog–to-digital (A/D) converter. The output port is used to send data fromcomputer to some peripherals or digital-to-analog (D/A) converter.Memory: -Memory section usually consists of two types of memories i-e: RAM andROM.Memory has two purposes,1. To store the binary codes for the sequence of instructions you want thecomputer to carry out.2. To store the binary code data with which the computer is going to beworking.Address Bus: -The address bus consists of 16,20,24 or more single lines. On these linesthe CPU sends out the address of the memory location that is to be written or to beread from. The number of lines can determine the number of memory locationsthat the CPU can address. Suppose a CPU has N address lines that it can bedirectly address to the power N.i-e: If 16-address lines then 210 = 65,536If 20-address lines then 220 = 1,048,576 locations.Data Bus: -Data bus consists of 8, 16, 32 or more parallel signal lines. As indicated bythe double-ended arrow on data bus in fig: These are bi-directional. Means CPUcan take or read data from these lines and as well can send data out of these lines.Control Bus: -The control bus consists of 4-10 parallel signals lines. CPU sends outsignals on the control bus to enable the outputs of address memory devices.The typical control bus signals are memory read, memory write, I/O readand I/O write.For example: To read a byte of data from a memory location, the CPUsends out the address of desired byte on the address bus and then sends out amemory read signals on control bus.Hardware, Software, and Firmware: -When working around the computer you hear these terms, that means,• Physical devices and circuitry are called Hardware.• Program written for computer are called Software.• And Firmware is the term given to the programs stored inROM.TYPES OF COMPUTER.1. Main Frame: - Computer comes in wide variety of sizes andcapabilities. The largest and most powerful computer is called

Page 22: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 22 -

mainframe computer. They are designed to workout at very highspeed with large data words, typically 64-bit or greater. These typesof computers are used in military defence control system, business,and data processing.Examples of this type are IBM-4381, 4331, and CRAY X-MP/4.2. Mini-computers: - Scaled down version of mainframe computersare often called Mini-computers. A mini-computer works slowlythan the mainframe and works with smaller data word as 32-bit anddoes not have as much memory as a mainframe has.Computers of this type are used in business, data processing, industrialcontrol and scientific research.Example: - VAX 11/730 and MV 8000/II.3. Micro-computer: - As the name implies micro-computers are smallcomputers. They range from small controllers that work with 4-bitwords and can address only few thousands of bytes of memory tolarger units that works directly with 32-bit words and can addressbillions of bytes of memory. Some of the most powerfulmicrocomputers have same features of mini computer. It has becomevery hard to allow a sharp line between two.Microcomputers are used in every thing from smart sewing machine tocomputer added-design systems.Example of micro computers: - Intel 8051 single chip controller. SDK-86 asingle board computer, IBM PC, etc.4. Microprocessor: - One distinguishing feature of micro computer isthat the CPU is usually a single Integrated circuit, called amicroprocessor.Old books also use the term microcomputer and microprocessor is theCPU in which you adds ROM, RAM and ports to make a microcomputer.

The figure shows the generalized model of MP. The MP is digital device with:1. A data bus2. An address bus

Page 23: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 23 -

3. A control bus.The MP is able to input information in the form of digital signals, process itaccording to the stored programs, and O/P the information in the form of digitalsignals. The stored program may in some cases reside in internal memory to theMP itself. In other cases program may be stored in external memory. In addition tothese three major buses, the MP requires one or more power supply voltages topower its internal circuitry and provide a voltage reference for the MP signal lines.

SEMI-CONDUCTOR MEMORIES & THEIR USE;The flip-flop or latch is the basic memory cell used in many semi-conductormemories. Semi-conductor memories are usually divided into two groups.(a). Read/write memories.(b). Read only memories.A ROM is a non-volatile memory with its binary pattern of 0’s & 1’s,permanently programmed by manufacturers.Read/Write memory is a memory that can be easily programmed, erased,& reprogrammed by the user. The programming is called ‘writing into thememory’. Copying data from memory without destroying the contents is called‘reading from the memory’. There fore read/write memory is often called RAM(Random Access Memory). Generally RAM’s programs are volatile, which meansit will be lost if power of the ICs is turned off, even for instant. The MSC typicallycontain both ROM & RAM types of Semi-conductor storage. The ROM & RAMstorage locations are usually kept in separate ICs.THE ROM COMES IN FOUR VERSIONS.1. Standard ROM. Manufacturer programs this.2. PROM. The user or distributor using special equipment can programProgrammable ROM permanently. It can be programmed only once3. EPROM. Erasable PROM can be erased & programmed by the user.Stored data in EPROM can be erased by shining high Intensityultraviolet light through a special transparent equipment having windowin the top of IC.4. EAROM. Electrically Alterable ROM can be erased & programmed bythe user with special equipment. The EAROM can be erased electricallyrather than ultraviolet light.There fore ROM, PROM, & EAROM are all considered permanent nonvolatilememories & don’t lose their data when the power of IC is turned OFF.THE RAM COMES IN TWO TYPES.1. Static RAM. If the RAM contains flip-flops like circuits as memorycells then it is called Static RAM. The Static RAM needs no refreshingof these cells and will holds its binary information as long as IC ispowered2. Dynamic RAM. If the RAM contains the capacitors like circuits asmemory cell then it is called Dynamic RAM. The Dynamic RAM cellsmust be refreshed hundreds of times per second.In MC the RAMs are used for temporary storage of user programs & data.ROMs are most often used for storing machine language instructions that may be

Page 24: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 24 -

referred to as the monitor programs, which contains unchangeable initialisationroutines, I/O routines & arithmetic algorithms.

One can easily understand the organization of RAM & ROM byconsidering the table of figure, which shows one possible organization of memorylocations. This table represents the organization of 16X4 bit RAM. The tableshows that data in the memory is the organized into sixteen 4-bit groups referredto as words in this table. In above fig: most of boxes are empty except word 12,which contain stored data 0101.A logic symbol for 16X4 Bit RAM is given in figure. It shows 64 bits RAMis in process of writing Input data 0101 into memory location (1100). The data

Page 25: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 25 -

Input contains the data to be stored is 0101 & word location 1100 is located bysetting the address I/Ps to (1100).

Next the two controls CS & WE place the RAM is write mode of operation.Here it must be noted that write enable and chip select inputs must be low forwrite operation to take place.The mode Truth Table for this 64-bit RAM is detailed in fig: Here RAM isin write mode, when CS and WE are low. During the write operation the 4-bit data(D4, D3, D2, D1) are loaded into the memory location pointed to by the address.During the write operation outputs (04, 03, 02, 01) float HIGH, with control CS = 0& WE = 1the RAM comes in Read mode. During the Read mode the complementof the data word pointed to by the address inputs appears at the output. The datastored in RAM is not destroyed by the read operation.In the Hold mode, the outputs all go HIGH and no data enters from theROM data inputs.The 64-bit RAM can be purchased as a TTL IC i-e (7489 IC) othercommon RAM ICs are 256, 1024, 14096, 41024, 256X4, 1024X8 etc.

Page 26: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 26 -

A ROM IC would operate similarly to the Ram, when it is in its Read andHold mode. The ROM comparable to RAM would have all the inputs & outputs ofthe RAM except the data inputs D4, D3, D2, D1 and WE input. A word would beRead from ROM by addressing a specific word location & the pulsing the CSinput with a LOW.ROM: -The read-only-memory (ROM) permanently stores programs and data thatare resident to the system and must not changed when power is disconnected. Thistype of memory is often called non-volatile memory. The ROM is available inmany forms today. A device we call a ROM is purchased in mass quantities from amanufacturer and programmed during its fabrication at the factory. The EPROM(Erasable Programmable ROM) a type of ROM is more commonly used whensoftware must be changed often or when too limited a number are in demand tomake the ROM economical.An EPROM is programmed in the field on a device called an EPROMprogrammer. The EPROM is also erasable if exposed to high-intensity ultra violetlight for about 20 minutes or less depending on the type of EPROM.The PROM (Programmable ROM) is also programmed in the field byburning open tiny Nichrome or silicon oxide fuses, but once programmed it can’tbe erased.Still another, newer type of read-mostly memory (RMM) is called theflash memory. The flash memory is also often called an EEPROM (ElectricallyErasable PROM), EAROM (Electrically Alterable ROM), or a NOVRAM (NonvolatileRAM). These memory devices are electrically erasable in the system, butrequire more time to erase them a normal RAM. The flash memory device is usedto store set-up information systems such as the video card in the computer. It mayalso soon replace the EPROM in the computer for the BIOS memory. Somesystems contain a password stored in the flash memory device.Static RAM (SRAM) devices: -Static RAM memory devices retain data for as long as DC power is applied.Because no special action (except power) is required to retain stored data, thesedevices are called Static memory. They are also called volatile memory becausethey will not retain data without power. The main difference b/w the ROM and aRAM is that a RAM is written under normal operation while a ROM isprogrammed outside the computer and is only normally read.Dynamic RAM (DRAM) memory: -About the largest Static RAM available today (in 19996) is a 128K x 8.Dynamic RAMs, on the other hand are available in much larger sizes, up to 16M x1. In all other respects, DRAM is essentially the same as SRAM, except that itretains data for only 2 or 4 ms on integrated capacitors, which store a logical 1 orlogical 0, lose their changes.Instead of requiring the almost impossible task of reading the contest ofeach memory location with a program and then rewriting them, the manufacturerhas internally constructed the DRAM so that, in the 64K x 1 version, the entirecontents of the memory is refreshed with 256 reads in 4 ms interval. Refreshingalso occurs during a write, a read or during a special refresh cycle.

Page 27: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 27 -

Another advantage of DRAM memory is that it requires so many address pins thatthe manufacturers have multiplexed the address inputs.

Page 28: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 28 -

Page 29: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 29 -

Page 30: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 30 -

Page 31: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 31 -

Page 32: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 32 -

Page 33: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 33 -

Page 34: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 34 -

The Microprocessor.At the heart of microprocessor based computer system is themicroprocessor integrated circuit. The microprocessor is the controlling element ina computer system and is some times referred to as the CPU. The MP controlsmemory & I/O through a series of connections called buses.The microprocessor performs three main tasks for the computer system:(1). Data transfer b/w itself and the memory or I/O systems.(2). Simple arithmetic and logic operation(3). Program flow via simple decisions.All these are simple tasks, but through them, the MP performs virtuallyany series of operations or tasks.The power of MP is in its ability to execute millions of instructions persecond from a program or software (group of instructions) stored in the memorysystem. This stored program concept has made the MP and computer system avery powerful device.Table shows the arithmetic and logic operations executed by the Intelfamily of microprocessor. These operations are basic, but through them, verycomplex problems are solved. Data are operated upon from the memory system orinternal registers.

Page 35: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 35 -

Another feature that makes the microprocessor powerful is its ability tomake simple decisions. Decisions are based upon numerical facts.For Example: - A microprocessor can decide if a number is zero, if it ispositive, and so fourth.These simple decisions allow the microprocessor to modify the programflow so programs appear to think through these simple decisions.

Microprocessor Characteristics.A MP may be defined as very large scale integration (VLSI) chip thatperforms as a CPU of a MC or any other automatic control system. Almost all 8-bit and 16-bit MP share same characteristics. Following some majorcharacteristics are explained.• Power Connections: - Microprocessor requires 5v dc regulated supply.• Bit-size: - MPs are commonly classified as 8, 16, 32 or more bits. Bit sizeof microprocessor is actually word size of MP that a MP can process.• Data-Lines: - They are used to transfer the data or instruction b/w theMPU and memory as I/O via bi-directional data bus. Actually according tothe length of the word size of data bus. The Mps are classified as 8, 16, 32bit MPs.• Address Lines: - Generally MPs use 8- or 16-bit address lines to carry theaddress of the instructions. It is unidirectional.• Control Lines: - Most MP use all or few of the following control signals:1. Clock lines2. Read/Write lines3. I/O lines4. Interrupt lines5. Reset lines6. Bus control lines7. Cycle status lines.Internal Registers: -

Page 36: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 36 -

All MPs contain the following internal registers.1. Program Counter (PC): -Holds the address of next program instruction. Itswidth matches with the address bus.2. Accumulator: -It is a register where a result of all instructions goesfinally. It is associated with ALU operations and I/Ooperations. It may be of 8-, 16-, 32-bit wide. Some MPU haveonly general-purpose registers, which are used asaccumulators.3. Status Registers: -This is available in all MPs. The individual bits in theregister are called flags that show a condition. The conditionof flag is associated with ALU operations.4. General Purpose Registers: -They are used for temporary storage of data or canhold an address. They are not assigned a specific task. In 8-bitMPs general-purpose register cannot function as accumulatorin ALU & I/O operations, but in 16-bit MPs usually all GPRare used as accumulators.5. Index Registers: -This register is used when index mode of addressingwill be used. It is used to hold the address of the operand.Some MPs use the GPR as index registers.6. Stack Pointer Registers: -It is special register that keeps track of the next availablememory location in the stack. Stack reserved area in RAMused for temporary storage of data, return address and contentof registers. Stack is used during sub-routine calls andinterrupts.Addressing Modes: -An addressing mode is the technique used to fetch the desired operandduring the execution of an instruction. Following is given the list of modes, butindividual microprocessors do not use all modes.1. Implied mode2. Immediate mode3. Extended mode4. Register mode5. Register indirect mode6. Index mode7. Direct mode8. Relative mode9. Based mode10. Based index mode11. I/O mode

Page 37: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 37 -

12. Status Register mode.

Instruction Set of MicroprocessorThe group of instructions that a specific microprocessor can execute iscalled its instruction set. A microprocessor can have instructions from 8 to 200 forit’s basic operations. Instruction sets of microprocessor are not standardized due tothe design of microprocessor. This is because of the individual design of amicroprocessor according to it’s architecture, requirements and use.One can categorize the instruction of the microprocessor instructions setaccording to the operations performed by that microprocessor.Generally, microprocessors have the following types of instruction sets:1. Arithmetic Instructions: - A simple arithmetic instruction setwould include the following arithmetic instructions.a. Add b. Subtract c. Increment d. Decremente. Compare f. Negate g. Add with carry h. Subtractwith borrows i. Multiply j. Divide.2. Logical Instructions: - Simplified logical instructions of MP areas:a. AND b. OR c. EXCLUSIVE OR d.NOTe. Shift Right f. Rotate left g. Rotate right through carry.3. Data Transfer Functions: - The basic MP would contain variationof the following data transfer instructions:a. Load b. Store c. Move d. Input e. Outputf. Exchange g. Clear i. Set.4. Branch Instructions: - Microprocessor contains the followingbranch instructions:a. Unconditional Branch b. Branch if zero c. Branch ifnot zerod. Branch if equal e. Branch if not equal f. Branch ifpositiveg. Branch if negative.Other conditional branch instructions used by the some M.P might dependon the condition such as Greater than, Less than, carry, no carry, overflow, nooverflow. Actually they are decision-making instruction of M.P.5. Sub-routine call instructions: - They are referred as CALLinstructions to make the program to jump to specific group ofinstructions for performing a specific task. All M.P haveunconditional call instructions & some have conditional callinstructions. Conditional calls are:a. Call if zero b. Call if not zero c. Call if +VE d.Call if not +VE6. Return Instructions: - After the execution of sub-routineinstructions, the program must return at the original sequencepoint/instruction from where jump was occurred. This is performedby return instruction. Return might be:

Page 38: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 38 -

a. Return from sub-routine b. Return from Interruptoperation.Returns are usually unconditional.7. Miscellaneous Instructions: - Simplified miscellaneous are:a. No operation b. Push c. Pop d. Waite.Haltf. Enable interrupt g. Disable interrupt h. Break i. Decimal.j.Adjust operations.PUSH / POP:The Push and Pop instructions are important instruction thatstore and retrieve from the LIFO (last-in, first-out) stack memory. Themicroprocessor has six forms of the Push and Pop instructions: registers, memory,immediate, segment register, flags, and all registers.PUSH instructions always transfers 2-4 bytes of data to the stack,depending on the register or size of the memory location. The PUSHA (PUSHALL) instruction that copies the contents of the internal register set, except thesegment register, to the stack. The PUSHF (PUSH FLAGS) instruction copies thecontents of the flags register to the stack. The PUSHAD & POPAD instructionpush and pop the contents of the 32-bit register set found in the 80386 through thePentium Pro.The POP instruction performs the inverse operation of a PUSH instruction.String Data Transfer: -There are five string data transfers functions:LODS, STOS, MOVS, INS, OUTS.Miscellaneous Data Transfer Instructions: -The Data Transfer Instructions are:XCHG, LAHF, SAHF, XLAT, IN, OUT, MOVSX, MOVZX, BSWAP andCMOV.XCHG: This instruction exchanges the contents of a register with thecontents of any other register.LAHF & SAHF: These instructions allowed translating soft wares of 8085to 8086 by a translation program. These instructions have little application today.The LAHF instruction transfers the right most 8-bits of the flag register into theAH register. And for SAHF vice-versa.XLAT: The XLAT (translate) instruction converts the contents of the ALregister into a number stored in the memory table.IN & OUT: IN and OUT instructions, which performs I/O operations.MOVSX & MOVZX: The MOVSX (move and sign-extend) and MOVZX(move and zero-extend) instructions move data and at the same time either signorzero-extend it.BSWAP: (Byte SWAP) Instruction takes the contents of any 32-bit registerand swaps the first byte with the fourth and second with the third.CMOV: The CMOV (Conditional move) moves the data if the condition istrue.

Page 39: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 39 -

ARITHMATIC & LOGIC Instruction.ADDITION:Addition (ADD) appears in many forms, ADD, ADC(Addition-with-Carry). Finally the INC increment instruction is presented.Increment is a special type of addition that adds a one to a number. INC BL,BL=BL+1Immediate Addition: Immediate addition is employed whenever constantor known data are added.Memory-to-Registration addition: This will be used to add the memorydata to the AL register.Array Addition: Memory arrays are sequential lists of data. The ADDAL, ARRAY [SI], will cause the summation of Array to the AL register, which isalready set=0. The loop will cause to increase the value of SI.Addition-with-carry: ADC adds the bit in the carry flag (c) to the operanddata.Exchange-and –add for the 80486- Pentium Pro Processors:A new type of addition called exchange and add (XADD). The XADDinstruction adds the source to the destination and stores the sum in the destination,as with any addition. The difference is that after the addition takes place, theoriginal value of the destination is copied into the source operand. This is one ofthe few instruction that change the source.SUBTRACTION:Many forms of subtraction (SUB) appears in the instruction set. A specialform of subtraction (decrement or DEC) subtracts a 1 from any register or memorylocation. The Subtract-with-Borrow instruction (SBB) performs the subtractionwhen numbers are wider than 16-bits and 32-bits. There are well over 1,000possible subtraction instructs.Immediate Subtraction: As with addition, the microprocessor also allowsimmediate operands for the subtraction of constant data.Register Subtraction: SUB BX, CX, SUB BX, DX: This example subtractsthe 16-bit contents of register CX and DX from the contents of register BX.COMPARISON:The comparison instruction (CMP) is a subtraction that changes only theflag bits. A comparison is useful for checking the entire contents of a register or amemory location against an other value.Compare & Exchange: The compare and exchange instruction(CMPXCHG) found only in the 80486 through the Pentium Pro instruction setscompares the destination operand with the accumulator. If they are equal, thesource operand is copied into the destination. If they are not equal the destinationoperand is copied into the accumulator.MULTIPLICATION & DIVISION:Only modern microprocessor contains multiplication and divisioninstructions. Earlier 8-bit microprocessors could not multiply or divide withoutthat use a program that multiplied or divided by using a series of shits, andaddition or subtractions.Multiplication: Multiplication is performed on the bytes, words, or double

Page 40: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 40 -

words and can be signed integer (IMUL) or unsigned (MUL).Division: The division occurs on 8- or 16-bitnumbers and also 32-bitnumbers in the 80386 through the Pentium Pro. These numbers are signed (IDIV)or unsigned integers (DIV).BASIC LOGIC INSTRUCTIONSThe basic logic instruction include AND, OR, Exclusive-OR, and NOT.Another logic instruction is TEST.AND: -The AND operation performs logical multiplication.

OR: -The OR operation performs logical addition and is often calledinclusive-OR.

Exclusive-OR: -The Exclusive-OR instruction (XOR) differs from inclusive-OR.The difference is that a 1,1 condition of the OR function produces a 1,while 1,1 condition of the XOR operation produces a 0.

Test & Bit-Test InstructionThe TEST instruction performs the AND operation. The TEST instructionfunctions in the same manner as a comparison instruction. The difference is thatthe TEST instruction normally tests a single bit (or occasionally multiple bits),while the comparison instruction tests the entire byte or word.NOT & NEG:Logical inversion or the one’s complement (NOT) and arithmetic signinversion or the two’s complement (NEG) are the two logical functions.The NOT instruction inverts all bits of a byte, word, or double word. TheNEG instruction two’s complements –a number, which means that the arithmeticsign of a signed number changes from +VE to –VE or –VE to +VE. The NOTfunction is considered logical, and the NEG function is considered an arithmeticoperation.Shift & Rotate:Shift & rotate instructions manipulate binary number at the binary bit level.Shift instructions position or move number to the left or right within aregister or memory location. They also perform simple arithmetic such asmultiplication by powers 2+n (left shift) and division by the power 2-n (right shift).Rotate instructions position binary data by rotating the information in a

Page 41: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 41 -

register or memory location either from one end to another through the carry flag.

Program Control InstructionsThe Jump Group: -The main program control instruction, jump (JMP), allows the programmerto skip sections of a program, & branch to any part of the memory for the nextinstruction.Unconditional Jump: -Three types of unconditional jump instructions are available to themicroprocessor, * Short jump, * Near jump, & * Far jump. The short and nearjumps are often called intrasegment jumps, and far jumps are often calledintersement jumps.Conditional Jumps and Conditional Sets: -The conditional jump instructions test the following flag bits:Sign (S), zero (Z), carry (C), parity (P), and overflow (O). If the conditionunder test is true, a branch to the label associated with jump instruction occurs. Ifthe condition is false, the next sequential step in the program executes.LOOP: -The LOOP instruction is a combination of a decrement CX and the INZconditional jump.CALL: -The CALL instruction transfers the flow of the program to the procedure. TheCALL instruction differs from the jump instruction because a CALL saves a returnaddress on the stack. Two types of CALL, 1. Near CALL 2. Far CALL.

Z80 Processor

DESCRIPTIONThe Z80 microprocessor is an 8-bit CPU with a 16-bit address bus capable of directaccess of 64k of memory space. It has a language of 252 root instructions and with thereserved 4 bytes as prefixes, acceses an additional 308 instructions. The Z80 wasmodeled after the 8088 and contains the 78 - 8088 opcodes as a subset to it's language.Programming features include an accumulator and six eight-bit registers that can bepaired as 3-16 bit registers. In addition to the general registers, a stack-pointer, programcounter,and two index (memory pointers) registers are provided. While not in the sameleauge as the 80486 or 68000 series, the Z80 is extremely useful for low cost controlapplications. One of the more useful features of the Z80 is the built-in refresh circuitryfor ease of design with DRAMs.The Z80 comes in a 40 pin DIP package. It has been manufactured in A, B, and C models, differingonly in maximum clock speed. It also has been manufactured as a stand-alone microcontroler withvarious configurations of on-chip RAM and EPROM.DEVICE SPECIFICATIONSMax. Clock Speed: Z80 - 2.5MHz, Z80A - 4MHz

Page 42: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 42 -

Power Requirements: Z80 - 5V@60mA, Z80A - 5V@90mAOperating Temp: 0 - 70 deg C.Min. Instruction time: 1uS (@4MHz)Max. Instruction time: 5.75uS (@4MHz)No. of Instructions: 158 (78 instructions of 8088 are a subset)Internal Registers: 14Stack: RAM

BINARY OPERATIONSANDThis operation takes the contents of the A-register, and another 8-bit field, andexamines these, bit by bit. Only if corresponding bits are both "1" does it put a "1"back in this position in the A-register. Otherwise it inserts a "0".For instance, AND A, 07 has the following effect:

ORThis works in a similar way to AND, but this time, the resulting bit is a "1" if either ofthe initial bits is a "1". So OR A, 05 gives:

XORHere the initial bit values must be different for the result to be a "1". XOR A, B3gives:

It's particularly useful for flipping a register from 0 to 1 and back again. If the Aregistercontains 0 to start with, every time the instruction XOR A, 01 is executed,the value in the A-register will flip. (0 to 1, back to 0, back to 1 and so on.)SETSets one bit of a byte, for example:SET 3, Asets the third bit of A, adding 8 to it.BITTests one bit of a byte, for example:BIT 3, Achecks the third bit of A, and sets the Zero flag if set.

ADDRESSING MODES OF Z 80.There are five different addressing modes.

Page 43: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 43 -

1. Direct AddressingLD A, (0F1C)This loads the contents of 0F1C into the A-register. Note that, by convention, themovement is from right to left, so that we can write:LD (0F1C), Aand mean "copy the contents of the A-register into 0F1C".The A-register is the only 8-bit register that can be directly addressed.2. Indirect AddressingLD A, (HL)This means "load the A-register through (ie from the address contained in) the HLregister". To pass data in the opposite direction we could have:LD (HL), Awhich puts the contents of A into the address contained in HL. (For this instruction,registers other than A are allowed.)3. Indexed addressingHere, we need to indicate which index register is in use, and the amount of theoffset:LD A, (IX+2E)Note that in direct addressing, I showed an address of 4 hex digits, because 16 bits(2 bytes) are allowed for the address. The offset value in an indexed addressinstruction must be held in 1 byte, however, so I've only shown two hex digits.4. Register-to-registerWe can transfer data between registers like this:LD D, Bwhich means "load the contents of B into D".5. ImmediateHere, data itself, rather than the address of data, is placed in the address field. Sowe can write:LD B, 07to mean "put the number 7 in B". Note again that the number is two hex digits, sinceit has to be stored in the single byte of the B-register. Note also that a "LD" is reallya copy: the numbers are retained in their original addresses or registers, but a copyis placed at the destination.THE JUMPSAll the conditional jumps branch (or not) depending on the contents of the flags. So,for instance, JPZ says 'jump if the Zero flag is set'. Now we can see how the CPinstruction can be used. Suppose, for example, that we wish to see if a particularbyte, pointed at by HL, contains 1E hex. If it does, we want to branch to address447B. The code is:LD A, 1ECP A, (HL)JP Z, 447BhAll the other jumps behave similarly, as can be seen here:JPNZ - jump on a non-zero result (zero flag not set)JPZ - jump on a zero result (zero flag set)JPP - jump on a positive result (sign flag not set)

Page 44: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 44 -

JPM - jump on a negative result (sign flag set)JPNC - jump on no carry (carry flag not set)JPC - jump on carry (carry flag set)CP(COMPARE INSTRUCTION)This is the 'compare' instruction. The contents of the A-register are compared withthose of another 8-bit field. That raises a problem, though: how is the result of thecomparison signalled?This is what the F (or flags) register is used for. Each bit of the F-register holds someinformation about the effect of the last instruction to alter them. (Not all instructionsdo alter them.)The flags which most interest us are the Carry, Zero, Overflow and Sign flags. CP canalter any of these, but the one of most significance here is the Zero flag, which is setif the two values being compared are equal.If the A-register contents are less than those of the compared byte, the sign flag isset. This is the equivalent of saying 'the result is negative'.

Page 45: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 45 -

Page 46: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 46 -

Page 47: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 47 -

Page 48: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 48 -

Page 49: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 49 -

Page 50: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 50 -

Page 51: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 51 -

Page 52: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 52 -

Page 53: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 53 -

Page 54: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 54 -

Page 55: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 55 -

Page 56: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 56 -

Page 57: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 57 -

Page 58: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 58 -

Page 59: Microprocessor Basicszma44.tripod.com/sitebuildercontent/sitebuilderfiles/... · Web viewcross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

Compiled by 03IT44 - 59 -