0% found this document useful (0 votes)
46 views20 pages

Microprocessor 8085

The document provides an introduction to 8085 assembly language programming, detailing the instruction set categorized into data transfer, arithmetic, logical, branching, and machine control operations. It explains the structure of instructions, including opcodes and operands, and discusses the different instruction word sizes (1-byte, 2-byte, and 3-byte). Additionally, it covers data formats and memory storage relevant to the 8085 microprocessor, along with an illustrative example of adding two hexadecimal numbers.

Uploaded by

ranaswarnadeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
46 views20 pages

Microprocessor 8085

The document provides an introduction to 8085 assembly language programming, detailing the instruction set categorized into data transfer, arithmetic, logical, branching, and machine control operations. It explains the structure of instructions, including opcodes and operands, and discusses the different instruction word sizes (1-byte, 2-byte, and 3-byte). Additionally, it covers data formats and memory storage relevant to the 8085 microprocessor, along with an illustrative example of adding two hexadecimal numbers.

Uploaded by

ranaswarnadeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 20
INTRODUCTION TO 8085 ASSEMBLY LANGUAGE PROGRAMMING 2.2.1 The 8085 Instruction Set ‘The 8085 instructions can be sified into the following five functional categories: data transfer (copy) operations, arithmetic operations, logical operations, branching opera- tions, and machine-control operations. DATA TRANSFER (COPY) OPERATIONS This group of instructions copies data from a location called a source to another lo- cation, called a destination, without modifying the contents of the source. In techni- cal manuals, the term data transfer is used for this copying function. However, the term ‘ransfer is misleading; it creates the impression that the contents of a source are destroyed when, in fact, the contents are retained without any modification. The var- ious types of data transfer (copy) are listed below together with examples of each type: Types Examples © Between registers Copy the contents of register B into register D. G Specific data byte to a reg- Load register B with the data byte 32H. ister or a memory location Gi Between a memory location From the memory location 2000H to register B. and a register Between an /O device and From an input keyboard to the accumulator. the accumulator ARITHMETIC OPERATIONS These instructions perform arithmetic operations such as addition, subtraction, increment, and decrement. © Addition—Any 8-bit number, or the contents of a register, or the contents of a mem- ory location can be added to the contents of the accumulator and the sum is stored in. the accumulator. No two other 8-bit registers can be added directly (e.g., the contents. of register B cannot be added directly to the contents of register C). The instruction DAD is an exception; it adds 16-bit data directly in register pairs Subtraction—Any 8-bit number, or the contents of a register, or the contents of a mem- ory location can be subtracted from the contents of the accumulator and the results stored in the accumulator. The subtraction is performed in 2's complement, and the re- sults, if negative, are expressed in 2's complement, No two other registers can be sub- 35 36 MICROPROCESSOR-BASED SYSTEMS: HARDWARE AND INTERPACING LOGICAL OPERATIONS These instructions perform various logical operations with the contents of the accumulator 1 AND, OR, Exclusive-OR—Any &-bit number, or the contents of a register, or of a y ANDed, ORed, or Exclusive-ORed with the contents ts are stored in the accumulator wulator can be shifted either left or right fo the next po- memory location can be lo of the accumulator. The re © Rotate—Bach bit in the ace sition 1B Compare—Any 8-bit number, or the contents of a register, of a memory location can be compared for equality, greater than, or less than, with the contents of the accumulator, Complement—The contents of the accumulator can be complemented; all Os are re~ placed by 1s and all Is are replaced by Os BRANCHING OPERATIONS ‘This group of instructions alters the sequence of program execution either conditionally or unconditionally, B Jump—Conditional jumps are an important aspect of the decision-making process in Programming. These instructions test for a certain condition (e.g., Zero or Carry flag) and alter the program sequence when the condition is met. In addition, the instruction set includes an instruction called unconditional jump. © Call, Return, and Restart—These instructions change the sequence of a program ei- ther by calling a subroutine or returning from a subroutine. The conditional Call and Return instructions also can test condition flags. MACHINE CONTROL OPERATIONS ‘These instructions control machine functions such as Halt, Interrupt, or do nothing. 2.2.2 Review of the 8085 Operations The microprocessor operations related to data manipulation can be summarized in four functions: 1. copying data 2. performing arithmetic operations 3. performing logical operations 4. testing for a given condition and altering the program sequence ‘Some important aspects of the instruction set are noted below: In data t a INTRODUCTION TO 8085 ASSEMBLY LANGUAGE PROGRAMMING. 31 3. Anyr gister including memory can be used for increment and decrement. 4. A program sequence can be changed either conditionally or by testing for a given data condition. INSTRUCTION, DATA FORMAT, AND STORAGE 2 3 An instruction is a command to the microprocessor to perform a given task on specified data. Each instruction has two parts: one is the task to be performed, called the operation code (op- code), and the second is the data to be operated on, called the operand. The operand (or data) can be specified in various ways. It may include 8-bit (or 16-bit) data, an internal register, a memory location, or an 8-bit (or 16-bit) address. In some instructions, the operand is implicit. 2.31 Instruction Word Size The 8085 instruction set is classified into the following three groups according to word size or byte, size. In the 8085, “byte” and “word” are synonymous because it is an 8-bit microproces- sor. However, instructions are commonly referred to in terms of bytes rather than words. 1. 1-byte instructions 2. 2-byte instructions . 3-byte instructions ONE-BYTE INSTRUCTIONS ‘A L-byte instruction includes the opcode and the operand in the same byte. For example: Task Opcode Operand* —- Binary Code Hex Code Copy the contents of MOV GA 0100 L111 4FH the accumulator in register C. ‘Add the contents of ADD. B 1000 0000 80H register B to the contents of thé ac- cumulator. Invert (complement) each bit im the ac- ‘MICROPROCESSOR-BASED SYSTEMS: HARDWARE AND INTERFACING TWO-BYTE INSTRUCTIONS In a 2byte instruction, the first byte specifies the operation code and the second byte specifies the operand, For example: Hex ‘Task Opeode — Operand Code . > 3E First Byte Load an 8-bit_ = MVI Ayah galas ou i data byte en 0010 | 32 Second Byte in the ac- ee cumulator, Load an 8-bit MVI BF2H 0000.0 06 First Byte data byte in mM F2 Second Byte register B. These instructions would require two memory locations each to store the binary codes. The data bytes 32H and F2H are selected arbitrarily as examples. THREE-BYTE INSTRUCTIONS In a 3-byte instruction, the first byte specifies the opcode, and the following two bytes specify the 16-bit address. Note that the second byte is the low-order address and the third byte is the high-order address, For example: Binary Hex Task Opcode —_Operand Code Code* Load contents LDA 2050H OO TOI] «= 3A First Byte ‘of memory OT0T 0000) 50 Second Byte 2050H into A. 00100000) 20 Third Byte Transfer the JMP. 2085H, [1100 0077] G3 First Byte program 1000 0101 85 Second Byte sequence to (00100000. 20 4 Third Byte memory location 2085H. These instructions would require three memory locations each to store the binary codes. ys similar to our everyday conversation. For ex- may make the following requests and orders: These commands are in many wa ample, while eating in a restaurant, we INTRODUCTION TO 8085 ASSEMBLY LANGUAGE PROGRAMMING. 4. L will have combination 17 (on the menu). I will have what Susie ordered. The first request specifies the exact item; it is similar to the instruction for loading a specific data byte in a register. The second request mentions the bowl rather than the contents, even though one is interested in the contents of the bowl. It is similar to the in- struction MOV C,A where registers (bowls) are specified rather than data. The third sug- gestion (let us eat) assumes that one knows what to eat. It is similar to the instruction Complement, which implicitly assumes that the operand is the accumulator. In the fourth sentence, the location of the item on the menu is specified and not the actual item. It is similar to the instruction: Transfer the data byte from the location 2050H. The last order (what Susie ordered) is specified indirectly. It is similar to an instruction that specifies a memory location through the contents of a register pair. (Examples of the last two types of instruction are illustrated in later chapters.) ‘These various ways of specifying data are called the addressing modes. Although microprocessor instructions require one or more Words to specify the operands, the nota- tions and conventions used in specifying the operands have very little to do with the op- eration of the microprocessor. The mnemonic letters used to specify a command are cho- sen (somewhat arbitrarily) by the manufacturer. When an instruction is stored in memory, itis stored in binary code, the only code the microprocessor is capable of reading and un- derstanding, The conventions used in specifying the instructions are valuable in terms of keeping uniformity in different programs and in writing assemblers. The important point to remember is that the microprocessor neither reads nor understands mnemonics or hexa- decimal numbers 2.3.2 Opcode Format To understand operation codes, we need to examine how an instruction is designed into the microprocessor. This information will be useful in reading a user's manual, in which oper- ation codes are specified in binary format and 8-bits are divided in various groups. However, s information is not necessary to understand assembly language programming. Inthe design of the 8085 microprocessor chip, all operations, registers, and status flags are identified with a specific code, Fo ntified as follows: 33 MICROPROCESSOR-BASED SYSTEMS: HARDWARE AND INTERFACING Some of the operation codes are identified as follows: Function Operation Code 1. Rotate each bit of the ac- 00000111 i ‘cumulator to the left by (8-bit opcode) ‘one position. 2. Add the contents of a reg- 10000SSS C ister to the accumula- (5-bit opcode—3 bits are reserved for a register) tor. -This instruction is completed by adding the code of the register. For example, Add 10000 Register B 000 wA Implicit Binary Instruction: 10000 000 = 80H Add Rez B In assembly language, this is expressed as Opcode Operand —_— Hex Code ADD B 80H 3. MOVE (Copy) the content of 01 DDD sss register Rs (source) to reg- 2-bit Opcode Reg. Rd Reg. Rs ister Rd (destination) for MOVE 5 This instruction is completed by adding the codes of two registers. For example, Move (copy) the content: 01 To register C 00 1 (DDD) From register A 11 1 (S88) Binary Instruction 01001 111>4FH Opcode Operand In assembly language, this is expressed as oe INTRODUCTION TO 8085 ASSEMBLY LANGUAGE PROGRAMMING MOV tl. 12 bP PTSsIs 2.3.3 Data Format The 8085 is an 8-bit microprocessor, and it processes (copy, add, subtract, etc.) only bi- nary numbers. However, the real world operates in decimal numbers and languages of al- phabets and characters, Therefore, we need to code binary numbers into different media. Let us examine coding. What is the letter “A”? It is a symbol representing a certain sound in a visual medium that eyes can recognize. Similarly, we can represent or code groups of bits into different media, In 8-bit processor systems, commonly used codes and data for- mats are ASCII, BCD, signed integers, and unsigned integ lows. '. They are explained as fol- © ASCH Code—This is a 7-bit alphanumeric code that represents decimal numbers. English alphabets, and nonprintable characters such as carriage return, Extended ASCII is an 8-bit code. The additional numbers (beyond 7-bit ASCII code) represent graphical characters. This code was discussed in Chapter 1 (Section 1.24). 1 BCD Code—The term BCD stands for binary-coded decimal; it is used for decimal numbers. The decimal numbering system has ten digits, 0 to 9. Therefore, we need only four bits to represent ten digits from 0000 to 1001. The remaining numbers, 1010 (A) to L111), are considered invalid. An 8-bit register in the 8085 can accommodate two BCD numbers. D Signed Integer—A signed integer is either a positive number or a negative number, In an 8-bit processor, the most significant digit, D,, is used for the signs 0 represents the positive sign and | represents the negative sign. The remaining seven bits, Dy-Dp, rep- resent the magnitude of an integer. Therefore, the largest positive integer that can be processed by the 8085 at one time is O111 1111 (7FH): the remaining Hex numbers. 80H to FH, are considered negative numbers. However, all negative numbers in this microprocessor are represented in 2's complement format (see Appendix A.2 for adldi- tional explanation). Dy all the 8 bits in LONE handling only 8-bit num numbers) are processed that after performin mins 4 BASED SYSTEMS: HARDWARE AND INTERFACING MICROPROCESSOR: v FIGURE 2.2 a ‘Simphiied Memory Model zg cS AD WR Address: Lines 00 Ro in decimal; (2) it is a BCD number representing 41 decimal; (3) it is the ASCII capital let- ter “A; or (4) itis a group of 8 bits where bits D, and Dy turn on and the remaining bits tum off output devices. The processor processes binary bits; it is up to the user to inter- pret the result. In our example, the number 41H can be displayed on a screen as an ASCIL “A” or 41 BCD. TTT 8 Data Lines 2.3.4 Instruction and Data Storage: Memory Now the next question is: How do we provide this information to the processor? It is pro- vided by another electronic storage chip called memory. In some ways, the term memory is & misnomer, itis a storage of binary bits. Memory chips used in most systems are nothing but 8-bit registers stacked one above the other as shown in our memory model in Figure 2.2. It includes only four registers, and each register can store 8 bits. This chip can be referred to as a ¢-byte or 32 (4 X 8) bits memory chip. It has two address lines, Ay and Ay, to identify four registers, 8 data lines to store 8 bits, and three timing or control signals: Read (RD), Wate (WR), and Chip Select (CS); all control signals are designed to be active low, indicated by bars over the symbols. The processor can select this chip and identify its register, and store (Write) or access (Read) 8 bits ata time. Figure 2.2 shows only four registers to simplify the explanation; in reality, the size of a memory chip is in kilo- or megabytes. The memory ad. resees assigned to these registers are determined by the interfacing logic used in the system. nd interfacing in more detail. In Chapters 3 and 4, we will discuss memory addressing at INTRODUCTION TO 8085 ASSEMBLY LANGUAGE PROGRAMMING. can perform, then translate these steps into instructions. Writing a simple program of adding two numbers in the 8085 language is illustrated below. 2.4.1 Illustrative Program: Adding Two Hexadecimal Numbers PROBLEM STATEMENT Write instructions to load the two hexadecimal numbers 32H and 48H in registers A and B, respectively. Add the numbers, and display the sum at the LED output port PORTI. PROBLEM ANALYSIS Even though this is a simple problem, it is necessary to divide the problem into small steps to examine the process of writing programs. The wording of the problem provides sufficient clues for the necessary steps. They are as follows: 1. Load the numbers in the registers. 2. Add the numbers. 3. Display the sum at the output port PORT! FLOWCHART The steps listed in the problem analysis and the sequence can be represented in a block diagram, called a flowchart. Figure 2.3 shows such a flowchart representing the above steps. This is a simple flowchart, and the steps are self-explanatory. We will discuss flow- charting in the next chapter. ASSEMBLY LANGUAGE PROGRAM To write an assembly language program, we need to translate the blocks shown in the flowchart into 8085 operations and then, subsequently, into mnemonics. By examining the blocks, we can classify them into three types of operations: Blocks 1 and 3 are copy op- FIGURE 2.3 Flowchart: Adding Two Numbers 43 MICROPROCESSOR-BASED SYSTEMS: HARDWARE AND INTERFACING erations; Block 2 is an arithmetic oper machine-control operation. “To translate these steps into assembly and machine languages, Yt should review the in- struction set. The translation of each block into mnemonics with comments is shown as follows Block 1; MVIA32H Load register A with 32H MVIBa8H Load register B with 48H Block 2: ADD B ‘Add two bytes and save the sum in A Black 3. OUTOIH Display accumulator contents at port O1 H Block 4: HALT End FROM ASSEMBLY LANGUAGE TO HEX CODE "Tb convert the mnemonics into Hex code, we need to look up the code in the 8085 in- or hand assembly struction set; this is called either manu: Mnemonics — Hex Code MVIA,32H 3E 2-byte instruction 32 MVIB.48H 06 2-byte instruction 48 ADD B 80 1-byte instruction OUT 01H D3 2-byte instruction o1 HLT 76 1-byte instruction STORING IN MEMORY AND CONVERTING FROM HEX CODE TO BINARY CODE To store the program in R/W memory of a single-board microcomputer and display the output, we need to know the memory addresses and the output port address. Let on sume that R/W memory ranges from 2000H to 20FFH, and the system has an LED out- put port with the address 01H. Now, to enter the program: 1 as Reset the system by pushing the RESET key. Enter the first memory address usi ee aur east Hex keys where the program should be stored. 3; Be ee paced i bye posting Hex keys. For example, to enter the first machine s E. n i i ama ea keys. (The ey may be labeled differently in chine code in memory iaaasace Se 4. Repeat Step 3 until the last INTRODUCTION TO 8085 ASSEMBLY LANGUAGE PROGRAMMING To Memory for Storage Flowchart FIGURE 2.4 computer system. An important function of the Monitor program is to check the keys and con- vert Hex code into binary code. The entire process of manual assembly is shown in Figure 2.4 In this illustrative example, the program will be stored in memory as follows: Memory Mnemonics Hex Code Memory Contents Address MVIA,32H 3E [oo 11.11 100 2000 32 oo1l 0010 2001 MVIB.48H 06 0000 0110 S000) 48 0100 1000 ai ADD B 80 1000 0000 ae OUT 01H D3 1 ON OLORIME oa 01 0000 0001 3006 HLT 6 ORS LETBIND) COT This program has eight machine codes and will require eight memory locations to store the program. The critical concept that needs to be emphasized here is that the mi- croprocessor can understand and execute only the binary instructions (or data); everything else (mnemonics, Hex code, comments) is for the convenience of human beings. EXECUTING THE PROGRAM To execute the program, we need to tell the microprocessor where the program begins by entering the memory address 2000H. Now, we can push the Execute key (or the key with a similar label) to begin the execution. As soon as the Execute function key is pushed, the microprocessor loads 2000H in the program counter, and the program control is trans- ferred from the Monitor program to our program. The microprocessor begins to read one hin a time, and when it fetches the complete instruction, it execute 0 imple, chine codes stored in mé MICROPROGESSOR-BASED SYSTEMS: HARDWARE AND INTERFACING ina given instruction. The following clues can instruction of the 8085 microprocessor. assembly is in recognizing the number of by be used to recognize the number of bytes in an ‘ (ers) representi 1. One-byte instruction—A mnemonic followed by a letter (or two letters) f aan ffienecisters Gulch ss A,B, C, D, E, H, L, M, and SP) is 2 one-byte instruction i et e-by' structions. Instructions in which registers are implicit are also one-byte instructs Examples: (a) MOY A, B; (b) DCX SP; (¢) RRC ; 2. Two-byte instruction—A mnemonic followed by 8-bit (byte) is @ two-byte instruction, Examples: (a) MVI A, 8-bit; (b) ADI 8-bit 3. Three-byte instruction—A mnemonic followed by 16-bit (also terms such as adr or dble) is a three-byte instruction. ; Examples: (a) LXIB, 16-bit (dble); (b) JNZ 16-bit (adr); (c) CALL 16-bit (adr) In writing assembly language programs, we can assign memory addresses in a se- quence once we know the number of bytes in a given instruction. For example, a three- byte instruction has three Hex codes and requires three memory locations in a sequence, In hand assembly, omitting a byte inadvertently can have a disastrous effect on program execution, as explained in the next section, 2.4.2 How Does a Microprocessor Differentiate Between Data and Instruction Code? The microprocessor is a sequential machine. As soon as a microprocessor-based system is turned on, it begins the execution of the code in memory. The execution continues in a sequence, one code after another (one memory location after another) at the speed of its clock until the system is tuned off (or the clock stops). If an unconditional loop is set up in a program, the execution will continue until the system is either reset or turned off Now a puzzling question is: How does the microprocessor differentiate between a code and data when both are binary numbers? The answer lies in the fact that the micro- Processor interprets the first byte it fetches as an opcode. When the 8085 is reset, its pro- gram counter is cleared to 0000H and it fetches the first code from the location 0000H. In the example of the previous section, we tell the processor that our program begins at location 2000H. The first code it fetches is 3EH. When it decodes that code, it knows that it is a two-byte instruction. Therefore, it assumes that the second code, 32H, is a data byte. If we forget to enter 32H and enter the next code, 06H, instead, the 8085 will load OGH in the accumulator, interpret the next code, 48H, as an opcode, and c ecution in sequence, As a consequence, ontinue the ex- We may encounter a totally unexpected result. INTRODUCTION TO 8085 ASSEMBLY LANGUAGE PROGRAMMING. study these instructions. You are stro! advised not to attempt to read all these instruc- tions at one time, However, you should be able to grasp an overview of the set by exam- ining the frequently used instructions listed below.* The following notations are used in the descriptic of the instructions, R_ = 8085 8-bit register (A,B, C.D. E, H, L) M = Memory re; Rs = Register source Rd = Register destination (A,B,C, D, E, H, L) Rp = Register pair (BC, DE, HL, SP) © = Contents of ster (location) 1. Data Transfer (Copy) Instructions. These instructions perform the following six op- erations. + Load an 8-bit number ina register * Load 16-bit number in a register pair + Copy from register to register *+ Copy between register and memory + Copy between 1/0 and accumulator + Copy between registers and stack memory Mnemonics Examples Operation Ll MVIR#*8-bit_ — MVI-B, 4FH Load 8-bit data (byte) in a register 1.2 MOV Rd, Rs** MOV B.A Copy data from source register Rs into MOV C, B destination register Rd 1.3 LXIRp,** 16-bit LX1B,2050H Load 16-bit number in a register pair 14 OUT8bit OUT OIH Send (write) data byte from the (port address) accumulator to an output device 15 IN8-bit IN 07H Accept (read) data byte from an input (port address) device and place it in the accumulator 1.6 LDA 16-bit LDA 2050H Copy the data byte into A from the memory specified by 16-bit address 1.7 STA 16-bit STA 2070H Copy the data byte from A into the memory specified by 16-bit address 1.8 LDAX Rp LDAX B ort the data byte into A from the specified by the address in STAX Rp 41 MICROPROCESSOR-BASED SYSTEMS: HARDWARE AND INTERFACING 1.10 MOVR,M MOV B, M Copy the data byte into register from the memory specified by the address in HL register 11 MOVM,R MOV M, C Copy the data byte from the register into memory specified by the address in HL register 2. Arithmetic Instructions. The frequently used arithmetic operations are: * Add + Subtract * Increment (Add 1) + Decrement (Subtract 1) Mnemonics Examples Operation Add the contents of a register to the 21 ADDR ADD B register (0 the contents of A 22 ADIS-bit ADI 37H Add 8-bit data to the contents of A 23 ADDM ADD M ‘Add the contents of memory to A; the address of memory is in HL register 24 SUBR suB ¢ Subtract the contents of a register from the contents of A 25 SUTS-bit SUI 7FH Subtract 8-bit data from the contents of A SUB M SUB M Subtract the contents of memory from ‘A; the address of memory is in HL register 2.7 INRR INR D Increment the contents of a register 28 INRM INRM Increment the contents of memory, the address of which is in HL 29 DCRR DCRE Decrement the contents of a register 2.10 DCRM DCR M Decrement the contents of a memory, the address of which is in HL 2.11 INX Rp INX H Increment the contents of a register pair 2.12 DCX Rp DCX B Decrement the contents of a register pair 3. Logic and Bit Manipulation Instructions. These instructions include the following ‘operations: oe OR) + Compare + Rotate Bits CO INTRODUCTION TO 8085 ASSEMBLY LANGUAGE PROGRAMMING 49 3.2 ANIS-bit ANI 2FH Logically AND 8-bit data with the contents of A 3.3 ANAM ANAM Logically AND the contents of memory with the contents of A; the address of memory is in HL register 34 ORAR ORAE Logically OR the contents of a register with the contents of A 3.5 ORI 8-bit ORI 3FH Logically OR 8-bit data with the contents of A 3.6 ORAM ORAM Logically OR the contents of memory with the contents of A; the address ‘of memory is in HL register 37 XRAR XRAB Exclusive-OR the contents of a register with the contents of A 38 XRI8it XRI 6AH Exclusive-OR 8-bit data with the contents of A 39 XRAM XRA M Exclusive-OR the contents of memory with the contents of A; the address of memory is in HL register 3.10 CMPR CMP B Compare the contents of register with the contents of A for less than, equal to, or greater than 3.11 CPL8-bit CPI 4FH Compare 8-bit data with the contents of A for less than, equal to, or greater than 4, Branch Instructions. The following instructions change the program sequence, 4.1 JMP 16-bitaddress IMP 2050H Change the program sequence to the specified 16-bit address 42 JZ 16-bitaddress JZ 2080H Change the program sequence to the specified 16-bit address if the Zero flag is set 4.3. JNZ 16-bit address JNZ 2070H Change the program sequence to the specified 16-bit address if the Zero flag is reset 44 JC 2025H Change the program sequence tothe JC 16-bit address 45 46 47 50 ICROPROCESSOR-BASED SYSTEMS: HARDWARE AND INTERPAC Ic; 5, Machine Control Instructions. These instructions affect the operation of the proces. sor. Sa aL HLT Stop processing and wait 3.2 NOP NOP Do not perform any operation sample; it does not include various in- representative ional jump instructions, and conditional structions related to 16-bit data operations, addit Call and Return instructions. iz 6 WRITING AND HAND ASSEMBLING A PROGRAM In previous sections, we discussed the 8085 instructions, recognized the number of bytes per instruction, looked at the relationship between the number of bytes of an instruction and memory registers needed for storage, and examined the processor's computing capa: instruction set. Now let us pull together all these concepts in bility in the overview of th a simple illustrative program. 2.6.1 Illustrative Program: Subtracting Two Hexadecimal Numbers and Storing the Result in Memory PROBLEM STATEMENT Write instructions to subtract two bytes already stored in memory registers (also referred to as memory locations or memory addresses) 2051H and 2052H. Location 20511 holds the byte 49H and location 2052H holds the byte 9FH. Subtract the first byte, 49H, from the second byte, 9FH, and store the answer in memory location 2053H. Write instructions beginning at memory location 2030H. PROBLEM ANALYSIS This is a problem similar to the problem in Section 2.4. However, specif c points in this problem, detec d are already stored in memory registers 2081H and these bytes. You should store ‘a simulator, you Si locmeanenmnemeenmammemmenneenen comme INTRODUCTION TO 8085 ASSEMBLY LANGUAGE PROGRAMMING \ 3. The microprocessor performs arithmetic operations in the ALU, meaning the proces: sor must use accumulator A in performing the subtraction, 4. The data bytes must be copied from memory into the microprocessor registers (until you learn how to perform an arithmetic operation by using the accumulator and a memory register), WRITING MNEMONICS AND ASSEMBLING HEX CODE, ‘The flowchart for this problem is similar to that shown in igure 2.3. The steps in writing instructions are as follows: Copy two data bytes into processor registers. By examining Section 2.5, we find two instructions, LDA and STA (instructions 1.6 and 1.7), to copy a byte from memory into A and from A into memory. There are two other instructions (MOV R, M and MOV M, R) that can copy between memory and registers, but those instructions re- quire the concept of memory pointers, which will be discussed in Chapter 7. Now let us take a look at the instruction LDA in the 8085 Instruction Summary at the end of Appendix F. a. The instruction is: LDA 16-bit. LDA is the opcode with Hex code 3A. (For a complete description of the instruction LDA, see Appendix F—all instru explained in alphabetical order.) As we discussed in Section 2.4 (“Recognizing the Number of Bytes in an Instruction”), this must be a 3-byte instruction and will re- quire three memory locations. b. The operand is a 16-bit address of the memory location from which we want to copy the byte into A. First we want to copy a byte from memory location 2051H. ¢, The 3-byte code is 3A 51 20. Sce Section 2.3. A 16-bit address is always written in reverse ordet—low-order byte followed by high-order byte. Our program be- gins at location 2030H; therefore, these 3 bytes will be stored in locations with Hex addresses 2030, 31, and 32. And the instruction, when executed, will copy the first byte, 49H, into A. 4. Copying the second byte into A. If we copy the second byte, 9FH, from mem- ory location 2052H into A, we will destroy the frst byte, 49H, Therefore, the pre- vious byte, 49H, should be stored) ust in some other register such as B. $1 MICROPROCESSOR-BASED SYSTEMS: HARDWARE AND INTERFACING The instruction Is: SUB B with Hex code 90. (Look at Appendix F code.) This instruction subtracts B from A and s 5. The result in A should be stored in memory location STA 2053 with Hex code 32 53 20. _ Instruction Summary to find the aves the result in A 2053H. The instruction is 6. Each program must be terminated; otherwise the processor continues (0 fetch and ex- ters until it gets lost or caught up ecute instructions from the remaining memory regist srite loop. This step may appear trivial, but itis essential, Therefore, the las instruction is HALT with Hex code 76. In instructional trainers, the Restart (RST) instruction 15 used. to pass the contro! of running programs back to the monitor program of the trainer. 7. New we need to load the two data bytes 49H and 9FH in memory locations 2051H and 2052H. This step is a manual entry of the data bytes, independent of the program. 8, So far we have completed two steps: writing the program (as shown in Column 1 in Table 2.2) and entering the Hex code in the memory registers of a memory chip (as chown in Column 2 in Table 2.2). If you observe this program in a simulator (see ‘Appendix H), it should appear as shown in Column 2. Using the analogy of putting a radio Kit together, we now have a page of instructions. Now we need to find the page, begin to read, understand the instructions, and perform the task until the kit is inan TABLE 2.2 Mlustrative Program: Assembly ee Column 1 Column 2 ‘Column 3 Instructions Memory Hex ‘Comments Addresses Code LDA 2051H 2030 3A Copy the first byte, 49H, from memory location 2051H into A 2031 51 2032 20 MOV B.A 2033 47 Save the first byte i P wv yte in B LDA 2052H 2034 3A Copy the second byte. 9FH, from memory Jocation 2052H it pe a nm H into A 2036 20 2037 90 Subtract 49H from 9FH and save the result in A It in memory location 2053H DITRODUCTION TO 6085 ASSEMBLY LANGUAGE PROGRAYMIIG 82 tering Hex code in memory is similar to the instruction tell the processor where our instructions begin 30H. We board or simulatio Jot execute one instruction at a time, called sn. The Single Step execution is easily the processor know the start- 10.» imulator (see Appendix H). gly advisable to follow the Single Step execution. As you step through anges in the contents of registers. When you execute 56H (9FH~49H), and when you execute STA range from 00 to SH. lator should he h as misspelling and mispronouncing ly language instructions. But the proces- ‘ommon errors is 2s follows, with examples from SiH: Not entering the code of the 16-bit address in reversed order. 2. Forgetting to enter the code for the operand, such as 2051H. 3. MOV B. A: Assuming that this copies from B to A. 4. incrementing the address in decimal, from 2039H to 2040H. &. HLT: Not terminating a program 6 Confusing the entering of Hex code in memory as executing a program. SUMMARY EEUU TEES ERENINESEIEIISSSSSSST This chapter described the data manipulation functions of the 8085 microprocessor, provides an overview of the instruction set, and illustrated the execution of instructions in relation to the system's clock. The important concepts in this chapter can be summarized as follows.

You might also like