MICROPROCESSOR 8085
LECTURE 11
PROGRAMMING EXAMPLE
PROF. SANDIP DAS
WRITE A PROGRAM TO FIND ONE’S COMPLEMENT OF AN
8-BIT NUMBER
Memory address Labels Mnemonics, operands Comments
2000 LDA 2501H Get data in accumulator
2003 CMA Take its complement
2004 STA 2502H Store result in 2502H
2007 HLT Halt
Example-1
2501-96H
Result is stored in the memory location 2502H
2502-69H
WRITE A PROGRAM TO FIND TWO’S COMPLEMENT OF
AN 8-BIT NUMBER
Memory address Labels Mnemonics, operands Comments
2000 LDA 2501H Get data in accumulator
2003 CMA Take its complement
2004 ADI 01 Take 2’s complement
2005 STA 2502H Store result in 2502H
2008 HLT Halt
Example-1
2501-96H
Result is stored in the memory location 2502H
2502-6AH
WRITE A PROGRAM TO FIND SMALLER OF TWO NUMBERS
Memory address Labels Mnemonics, operands Comments
2000 LXI H,2501H Address of 1st number I H-L pair
2003 MOV A,M 1st number in accumulator
2004 INX H Address of 2nd number I H-L pair
2005 CMP M Compare 2nd number with 1st
number
Is 1st number<2nd number?
2006 JC AHEAD Yes, smaller number is in
accumulator.
Go to AHEAD.
2009 MOV A,M No, get 2nd number in accumulator.
200A AHEAD STA 2503H Store smaller number in 2503H
200D HLT HaltNOTE: when A>M then CS=0,
Z=0
when M>A then CS=1,
Z=0
when A=M then CS=0,
Z=1
WRITE A PROGRAM TO FIND THE NUMBER IN A ARRAY
Memory address Labels Mnemonics, operands Comments
2000 LXI H,2500H Address of count in H-L pair
2003 MOV C,M Count in C register
2004 INX H Address of 1st number in H-L pair
2005 MOV A,M 1st number in accumulator
2006 DCR C Decrement count.
2007 LOOP INX H Address of 2nd number in H-L pair.
2008 CMP M Compare 2nd number with 1st number
Is 2nd number>1st number?
2009 JNC AHEAD No, larger number is in accumulator.
Go to AHEAD
200C MOV A,M Yes, get larger number in
accumulator
200D AHEAD DCR C Decrement count.
200E JNZ LOOP
2011 STA 2504H Store result in 2504H
2014 HLT Halt
Data:
2500-
03
2501-
98
2502-
75
Result:
2504-
99
ASSIGNMENT-3
• Write a program to find 2’s complement of 16bit number
• Write a program to find decimal addition of two 8bit number,
result will be 16 bit.
• Write a program to add two 16 bit numbers, result will be 16bit
or more.

8. 8085 programming example

  • 1.
  • 2.
    WRITE A PROGRAMTO FIND ONE’S COMPLEMENT OF AN 8-BIT NUMBER Memory address Labels Mnemonics, operands Comments 2000 LDA 2501H Get data in accumulator 2003 CMA Take its complement 2004 STA 2502H Store result in 2502H 2007 HLT Halt Example-1 2501-96H Result is stored in the memory location 2502H 2502-69H
  • 3.
    WRITE A PROGRAMTO FIND TWO’S COMPLEMENT OF AN 8-BIT NUMBER Memory address Labels Mnemonics, operands Comments 2000 LDA 2501H Get data in accumulator 2003 CMA Take its complement 2004 ADI 01 Take 2’s complement 2005 STA 2502H Store result in 2502H 2008 HLT Halt Example-1 2501-96H Result is stored in the memory location 2502H 2502-6AH
  • 4.
    WRITE A PROGRAMTO FIND SMALLER OF TWO NUMBERS Memory address Labels Mnemonics, operands Comments 2000 LXI H,2501H Address of 1st number I H-L pair 2003 MOV A,M 1st number in accumulator 2004 INX H Address of 2nd number I H-L pair 2005 CMP M Compare 2nd number with 1st number Is 1st number<2nd number? 2006 JC AHEAD Yes, smaller number is in accumulator. Go to AHEAD. 2009 MOV A,M No, get 2nd number in accumulator. 200A AHEAD STA 2503H Store smaller number in 2503H 200D HLT HaltNOTE: when A>M then CS=0, Z=0 when M>A then CS=1, Z=0 when A=M then CS=0, Z=1
  • 5.
    WRITE A PROGRAMTO FIND THE NUMBER IN A ARRAY Memory address Labels Mnemonics, operands Comments 2000 LXI H,2500H Address of count in H-L pair 2003 MOV C,M Count in C register 2004 INX H Address of 1st number in H-L pair 2005 MOV A,M 1st number in accumulator 2006 DCR C Decrement count. 2007 LOOP INX H Address of 2nd number in H-L pair. 2008 CMP M Compare 2nd number with 1st number Is 2nd number>1st number? 2009 JNC AHEAD No, larger number is in accumulator. Go to AHEAD 200C MOV A,M Yes, get larger number in accumulator 200D AHEAD DCR C Decrement count. 200E JNZ LOOP 2011 STA 2504H Store result in 2504H 2014 HLT Halt Data: 2500- 03 2501- 98 2502- 75 Result: 2504- 99
  • 6.
    ASSIGNMENT-3 • Write aprogram to find 2’s complement of 16bit number • Write a program to find decimal addition of two 8bit number, result will be 16 bit. • Write a program to add two 16 bit numbers, result will be 16bit or more.