Top Banner
Lab 1: Familiarization with 8085 simulator and the size of instructions. i) Type the following program in simulator and run the program step by step. After the execution of the program, check the register contents and the memory location 2030H until 2032H and complete the table below: Mnemonics Size(in bytes) Address Machine Code Final Output LXI SP,3FF0 3 0000 - 0002 31 F0 3F A = 07 MVI A,05 2 0003 - 0004 3E 05 B = 05 MOV B,A 1 0005 47 C = 05 MOV C,B 1 0006 48 D = 05 MOV D,C 1 0007 51 E = 05 MOV E,D 1 0008 5A H = 20 INR A 1 0009 3C L = 32 STA 2030 3 000A – 000C 32 30 20 SP = 3FF0 INR A 1 000D 3C 2030H = 06 LXI H,2031 3 000E - 0010 21 31 20 2031H = 07 MOV M,A 1 0011 77 2032H = 07 LDA 2030 3 0012 - 0014 3A 30 20 INR A 1 0015 3C INX H 1 0016 23 MOV M,A 1 0017 77 HLT 1 0018 76 Assignment: a) The following program adds five bytes stored in memory locations starting from 2055H. The result is stored in location 2060H and 2061H. Set 1: 17, 1B, 21, 7F, 9D Set 2: F2, 87, A9, B8, C2 LXI H,2055 // Set HL as a memory pointer XRA A // Clear Accumulator LXI B,0005 // Clear B to save carries and set up C as counter LOOP2: ADC M // Add byte with carry JNC LOOP1 // Skip incrementing B if carry flag is not set INR B // Update counter LOOP1: DCR C // Update counter INX H // Next memory location JNZ LOOP2 // Go back to add next byte STA 2060 // Store low order sum MOV A,B // Get high order sum
16

8085 Programs

Dec 26, 2015

Download

Documents

Labin Ojha

Some basic intel-8085 microprocessor programs.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 8085 Programs

Lab 1: Familiarization with 8085 simulator and the size of instructions.

i) Type the following program in simulator and run the program step by step. After the execution of the program, check the register contents and the memory location 2030H until 2032H and complete the table below:

Mnemonics Size(in bytes) Address Machine Code Final OutputLXI SP,3FF0 3 0000 - 0002 31 F0 3F A = 07MVI A,05 2 0003 - 0004 3E 05 B = 05MOV B,A 1 0005 47 C = 05MOV C,B 1 0006 48 D = 05MOV D,C 1 0007 51 E = 05MOV E,D 1 0008 5A H = 20INR A 1 0009 3C L = 32STA 2030 3 000A – 000C 32 30 20 SP = 3FF0INR A 1 000D 3C 2030H = 06LXI H,2031 3 000E - 0010 21 31 20 2031H = 07MOV M,A 1 0011 77 2032H = 07LDA 2030 3 0012 - 0014 3A 30 20INR A 1 0015 3CINX H 1 0016 23MOV M,A 1 0017 77 HLT 1 0018 76

Assignment:

a) The following program adds five bytes stored in memory locations starting from 2055H. The result is stored in location 2060H and 2061H.

Set 1: 17, 1B, 21, 7F, 9DSet 2: F2, 87, A9, B8, C2

LXI H,2055 // Set HL as a memory pointer XRA A // Clear Accumulator LXI B,0005 // Clear B to save carries and set up C as counter

LOOP2: ADC M // Add byte with carry JNC LOOP1 // Skip incrementing B if carry flag is not set INR B // Update counter

LOOP1: DCR C // Update counter INX H // Next memory location JNZ LOOP2 // Go back to add next byte STA 2060 // Store low order sum MOV A,B // Get high order sum STA 2061 // Store high order sum HLT // Stop

Page 2: 8085 Programs

Set 1 Set 2A = 01 2060H = 6F A = 03 2060H = 9EB = 01 2061H = 01 B = 03 2061H = 03C = 00 CY = 1 C = 00 CY = 1D = 00 P = 1 D = 00 P = 1H = 20 AC = 1 H = 20 AC = 1L = 5A Z = 1 L = 5A Z = 1SP = 0000 S = 0 SP = 0000 S = 0

Lab 2: Data transfer instructions

i) WAP to exchange the contents of HL register pair with DE register pair using MOV instruction.

# ORG 0000H# BEGIN 0000H

LXI H,1234 // load reg pair HL with 1234H LXI D,5678 // load reg pair DE with 5678H MOV A,H MOV H,D MOV D,A // these are MOV A,L // move instructions MOV L,E // used for swapping MOV E,A HLT

# END

Before After

ii) WAP to copy the content of memory location 5005H to 6050H.

# ORG 5005H# DB E5H# ORG 0000H# BEGIN 0000H

LDA 5005 // load contents of 5005H into accumulator STA 6050 // store contents of accumulator into 6050H HLT

# END

Page 3: 8085 Programs

a) WAP to store the content of register D to location 5005H using STA instruction.

# ORG 0000H# BEGIN 0000H

MVI D,12 // move some number to reg D MOV A,D // move content of D to Accumulator STA 5005 // store content of accumulator to 5005H HLT

# END

b) The data 55H and 66H are stored at 2000H and 2001H respectively. WAP using LHLD and SHLD to transfer the contents to memory locations 3000H and 3001H respectively.

# ORG 2000H# DB 55H,66H# ORG 0000H# BEGIN 0000H

LHLD 2000 // load contents of memory into L and H SHLD 3000 // store contents of L and H into memory locations HLT

# END

Page 4: 8085 Programs

Lab 3: Arithmetic operations

i) WAP to increment the content of 16 bit data located at 200AH and 200BH by 5.# ORG 200AH# DB 55H,66H# ORG 0000H# BEGIN 0000H

LDA 200A // load content of mem(200A) into acc MOV B,A // move content of acc into B LDA 200B // load content of mem(200B) into acc MOV C,A // move content of acc into C INX B INX B INX B // increment reg pair BC 5 times INX B INX B MOV A,B // move content of B into acc STA 200A // store content of acc into mem(200A) MOV A,C // move content of C into acc STA 200B // store content of acc into mem(200B) HLT

# END

OR# ORG 200AH# DB 55H,66H# ORG 0000H# BEGIN 0000H

MVI B,05 // Hold the additive number in B LDA 200B // load content of mem(200B) to acc ADD B // add content of B(05) to acc STA 200B // store content of acc in mem(200B) LDA 200A // load content of mem(200A) to acc ACI 00 // add 00 with carry to acc STA 200A // store content of acc in mem(200A) HLT

# END

Page 5: 8085 Programs

ii) WAP using ADI instruction to add the two hexadecimal numbers 3AH and 48H and store the result in memory location 2100H.

# ORG 0000H# BEGIN 0000H

MVI A,48 // move number to acc ADI 3A // add number to acc STA 2100 // store content of acc in mem(2100) HLT

# END

a) WAP to subtract 64H from 92H which is stored in memory location 2001H and 2002H. Store the final result in memory location 3200H.

# ORG 2001H# DB 64H,92H# ORG 0000H# BEGIN 0000H

LHLD 2001 // load L and H with content from memory locations MOV A,H // move content of H into acc SUB L // sub content of L from acc STA 3200 // store content of acc into mem(3200) HLT

# END

Page 6: 8085 Programs

Lab 4: Arithmetic Operations (continued)

i) WAP to add two 16-bit numbers stored in registers BC=2793H and DE = 3182H and place the sum in the memory locations 2050H and 2051H. And also do it using DAD instruction.# ORG 0000H# BEGIN 0000H

LXI B,2793 // load reg pair BC with data LXI D,3182 // load reg pair DE with data MOV A,C // move contents of C to acc ADD E // add contents of E to acc STA 2051 // store contents of acc to mem(2051) MOV A,B // move contents of B to acc ADC D // add contents of D to acc along with carry bit STA 2050 // store contents of acc to mem(2050) HLT

# END

OR

# ORG 0000H# BEGIN 0000H

LXI B,2793 // load reg pair BC with data LXI D,3182 // load reg pair DE with data

ADDLOOP: INX D // increment reg pair DE by 1 DCX B // decrement reg pair BC by 1 MOV A,C // move contents of C to acc ORA B // logical OR B with acc JNZ ADDLOOP // if not zero goto ADDLOOP MOV A,D // move contents of D to acc STA 2050 // store contents of acc to mem(2050) MOV A,E // move contents of E to acc STA 2051 // store contents of acc to mem(2050) HLT

# END

Page 7: 8085 Programs

b) Using DAD instruction:# ORG 0000H# BEGIN 0000H

LXI B,2793 // load reg pair BC with data LXI D,3182 // load reg pair DE with data XCHG // exchange contents of DE reg pair with HL reg pair DAD B // add reg pair BC with and in reg pair HL MOV A,H // move contents of D to acc STA 2050 // store contents of acc to mem(2050) MOV A,L // move contents of E to acc STA 2051 // store contents of acc to mem(2050) HLT

# END

a) Two sixteen bit data are stored from location 5000H.WAP to subtract these two numbers and store the result from 5009H.

# ORG 5000H# DB 6FH,5AH,34H,45H# ORG 0000H# BEGIN 0000H

LHLD 5000 // load into L and H contents of memory locations XCHG // exchange contents of HL and DE reg pairs LHLD 5002 // load into L and H contents of memory locations MOV A,H // move contents of H into acc

Page 8: 8085 Programs

SUB D // subtract contents of D from contents of acc STA 500A // store low order byte from acc into mem(500A) MOV A,L // move contents of L into acc SBB E // subtract contents of E and borrow flag from contents of acc STA 5009 // store high order byte from acc into mem(5009) HLT

# END

Lab 5: Logical operations

a) WAP to find the smallest value between two numbers stored at memory locations 2800H and 2801H and store the value at memory location 3000H.# ORG 2800H# DB 05H,04H# ORG 0000H# BEGIN 0000H

LHLD 2800 // load into L and H contents of memory locations MOV A,H // move content of H into acc CMP L // compare contents of L with contents of acc JZ EQ // skip to end if zero flag is set JC LESSA // implies that content of acc is less than that of L, so proceed to LESSA MOV A,L // no other conditions are met so content of acc is greater than that of L

LESSA: STA 3000 // store content of acc into mem(3000)

EQ: HLT# END

Lab 6: Logical operations (continued)

i) A table having starting address 3060H contains ten 8-bit data. WAP in 8085 that transfers the data to the next table having starting address 3070H if the data is less than 90H else store it to the next table at 3080H.# ORG 3060H# DB 05H,04H,01H,8FH,A6H,7FH,C7H,7BH,BCH,AFH# ORG 0000H# BEGIN 0000H

Page 9: 8085 Programs

LXI D,3070 // Pass1 LXI H,3060 MVI C,0A

CHECK1: MOV A,M CPI 90 JNC LOOP1 // check if the content of accumulator is less than 90 STAX D // case of acc content being less than 90, store accumulator content to mem pointed

by DE reg pair INX D // increment content of DE reg pair

LOOP1: INX H // increment content of HL reg pair DCR C // decrement counter JNZ CHECK1 // loop until counter is zero

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

LXI D,3080 // Pass2 LXI H,3060 MVI C,0A

CHECK2: MOV A,M CPI 90 JC LOOP2 // check if the content of accumulator is not less than 90 STAX D // case of acc content being not less than 90, store accumulator content to mem

pointed by DE reg pair INX D // increment content of DE reg pair

LOOP2: INX H // case of acc content being less than 90, increment content of HL reg pair DCR C // decrement counter JNZ CHECK2 // loop until counter is zero HLT

# END

Page 10: 8085 Programs

a) WAP to find the sum of 16 bytes of data stored in memory. Store the sum at memory location 6060H and 6061H (This is similar to Lab 7, it is done next).

Lab 7: Branching and Stack

i) WAP to add six bytes of data stored in memory locations starting at 2050H.Use register B to save any carries generated, while adding the data bytes. Store the sum at two consecutive memory locations 2070H and 2071H. Given data: A2,FA,DF,E5,98,8B# ORG 2050H# DB A2H,FAH,DFH,E5H,98H,8BH# ORG 0000H# BEGIN 0000H

LXI H,2050 // load reg pair HL with data XRA A // clear acc LXI B,0006 // load B with 00 as carry holder and load C with 06 as counter

ADD: ADD M // add the contents of memory pointed by HL to the acc JNC NEXT // if carry flag is not set goto NEXT INR B // increment carry bit

NEXT: INX H // increment content of HL pair, which also is the memory pointer DCR C JNZ ADD // loop through until counter is zero STA 2071 MOV A,B STA 2070 // store the results in mem(2070(high order bit) and 2071(low order bit)) HLT

# END

Page 11: 8085 Programs

Lab 8: Branching

i) WAP in 8085 assembly program to read 8 bytes stored in memory location starting at 2060H and add all positive numbers only. Store FFH in the memory location 2070H when the sum exceeds eight bits, otherwise store the sum.# ORG 2060H# DB 5AH,6AH,DFH,E5H,98H,8BH,12H,FCH# ORG 0000H# BEGIN 0000H

LXI H,2060 // load reg pair HL with data MVI B,00 // load b with zero MVI C,08 // set C as counter

LOOP: MOV A,M // move the contents of memory pointed by HL reg pair to the acc RAL // rotate accumulator left through carry flag JC NOSUM // carry flag through d7 is 1 means the number is negative, in signed representation so

addition is skipped RAR // rotate accumulator right to restore the accumulator state ADD B // add content of B to the acc JC STOP // if carry flag is set the sum now exceeds 8 bits so proceed to STOP MOV B,A // store the current sum from acc into B

NOSUM: INX H // increment reg pair HL(mem pointer) DCR C // decrement counter JNZ LOOP // loop until counter reaches zero MOV A,B STA 2070 // store sum HLT

Page 12: 8085 Programs

STOP: MVI A,FF STA 2070 // store default overflow value HLT

# END

Lab 9: Multiplication

i) WAP in 8-bit microprocessor to multiply two 16-bit numbers and store in memory location starting from 3500H.

# ORG 1000H# DB A3H,4CH,B1H,8CH# ORG 0000H# BEGIN 0000H

LHLD 1000 MOV B,L MOV C,H LHLD 1002 // load reg pairs BC and DE with multiplicand and multiplier MOV D,L MOV E,H LXI H,0000

START: DAD D JNC NOCARRY LDA 3501 ADI 01 STA 3501 // repeated addition with saving of carry bits if occurred JNC NOCARRY LDA 3500 ADI 01 STA 3500

NOCARRY: DCX B

Page 13: 8085 Programs

MOV A,C ORA B JNZ START MOV A,L // decrement counter multiplicand and loop until zero STA 3503 MOV A,H STA 3502 HLT

# END

Lab 10: Miscellaneous

i) 16-bit data are stored in two tables starting at 8040H and 8060H having ten data each. Write an 8085 program to store the sum in the corresponding index of the third table starting at 8080H (Assume the sum will not exceed 16 bit).# ORG 8020# DB 40,80,60,80,80,80,0A# ORG 8040# DB 12,23,34,A4,5C,6B,7F,8D,E4,F2,22,2F,3A,F4,DC,65,79,86,E3,FA# ORG 8060# DB 22,2F,3A,F4,DC,65,79,86,E3,FA,12,23,34,A4,5C,6B,7F,8D,E4,F2# ORG 0000H# BEGIN 0000H

LOADNEXT: LDA 8026 XRI 00 JZ STOP LHLD 8020 MOV B,H MOV C,L INX H INX H SHLD 8020 LHLD 8024 // loadnext creates variables in memory MOV D,H // pertaining to the memory locations MOV E,L // corresponding to the current table INX H // rows being operated, they are updated INX H // each loop, the variables are memory

Page 14: 8085 Programs

SHLD 8024 // locations of augend and the addend and LHLD 8022 // the counter variable INX H INX H SHLD 8022 DCX H DCX H DCR A STA 8026

SUM: LDAX B ADD M // this section does 16 bit addition STAX D INX B INX H INX D LDAX B JNC NOCARRY// check carry out from 8 bit addition ADC M // higher order bit addition with carry

NOCARRY: ADD M // higher order bit normal addition STAX D CALL LOADNEXT

STOP: HLT

# END