Lecture 4
Instruction : A command to the microprocessor to perform a given task on specified data. Each instruction has two parts One part is the task to be performed, called operation code or opcode in short The second part is the data to be operated on, called the operand. The operand (or data) can be specified in various ways. It may include 8 or 16 bit data, or an internal register, or a memory location or an 8 or 16 bit address. In some instructions, operand is implicit. In 8085, byte and word are synonymous because it is an 8-bit microprocessor 2
Say, we want to write an assembly program to add two hexadecimal numbers, 32H and 48H for example. This can be divided into 4 small steps: 1. Load the two numbers 32H and 48H in registers A and B respectively 2. Add the numbers 3. Display the sum at the output PORT 1 4. End To write an assembly language program, we need to translate the blocks (shown in the above 3 steps) into 8085 operations and then subsequently into mnemonics. Amongst the above 4 steps, steps 1 and 3 are copy i.e. data movement operations, step 2 is an arithmetic i.e. data manipulation operation and step 4 is a machine control i.e. program manipulation operation 3
The conversion of each step to mnemonics is shown below Step 1a: MVI A, 32H //Load register A with 32H MVI B, 48H //Load register B with 48H Step 2: ADD B //Add two bytes and save the sum in A Step 3: OUT 01H // Display accumulator contents at port 01H Step 4: HLT //End 4
To convert mnemonics to Hex codes, look up for the code in the 8085 instruction set Mnemonics Hex code MVI A, 32H 3E //2-byte instruction 32 MVI B, 48H 06 //2-byte instruction 48 ADD B 80 //1-byte instruction OUT PORT1 D3 //2-byte instruction 01 HLT 76 //1-byte instruction 5
To store the program in memory, need to know the memory and output port address. Let s assume that memory ranges from 2000H to 20FFH and the system has LED output port with the address 01H. Reset the system by pushing the RESET key. Enter the first memory address i.e. 2000H using Hex keys Enter each machine code by pushing HEX keys e.g. to enter first machine code 3E, push the 3, E and STORE keys Repeat the previous step until the last machine code, 76H Reset the system Steps of instruction 8085 Mnemonics Manual Lookup Hex Code Monitor Program Binary Code To memory For Storage 6
To execute the program, we need to tell the microprocessor where the program begins by entering the memory address (2000H in this case) Then the EXECUTE key should be pushed As soon as EXECUTE key is pushed, the microprocessor loads 2000H in the program counter and the program control is transferred from the Monitor program to the specific program under execution The microprocessor reads one machine code at a time. Once the complete instruction is fetched, it executes that instruction. For example, it will fetch machine codes in the memory locations 2000H and 2001H and execute the instruction MVI A, 32H. It continues to execute instructions until it fetches the HLT instruction. 7
Following clues can be used to recognize the number of bytes of an instruction One-byte instruction A mnemonic followed by a letter (or two letters) representing registers. E.g. MOV A,B; RRC; DCX SP, etc. Two-byte instruction A mnemonic followed by 8-bit i.e. a byte. E.g. MVI A, <<8-bit data>>; ADI <<8-bit data>> Three-byte instruction A mnemonic followed by 16 bits or 2 bytes, mostly address. E.g. LXI B, 16 bit (double); JMP <<16-bit address>>; CALL <<16-bit address>> In writing assembly language programs, memory addresses can be assigned once the number of bytes in a given instruction is known. For example, a three-byte instruction has 3 Hex codes and requires 3 memory locations in a sequence. 8
The microprocessor interprets the first byte it fetches as an opcode. When the 8085 is reset, the program counter is cleared to 0000H and it fetches the first code from location 0000H. In the previous example though, the program counter begins from the location 2000H. The first code it fetches is 3EH. When the code 3E is decoded, it knows that it is a 2-byte instruction. Therefore it assumes that the next byte, 32H, is a data. In case 32H is missed out, and directly the next code 06H is entered, the 8085 will load 06H to accumulator as an operand of opcode 3EH. So, the next code 48H will be treated as an opcode by 8085, and this sequence will continue. As a result, the outcome of the program will be completely erroneous. 9
10