Vous êtes sur la page 1sur 13

8085 Programs

Program 1: 1s complement of an 8-bit number. Flowchart: Start Output: Before Execution: Load accumulator with operand from memory. 3000H: 85H

Store the result from accumulator to memory.

Stop

Program: Address 2000 2001 2002 2003 2004 2005 2006 2007 Explanation: This program finds the 1s complement of an 8-bit number stored in memory location 3000H. Let us assume that the operand stored at memory location 3000H is 85H. The operand is moved to accumulator from memory location 3000H. Then, its complement is found by using CMA instruction. The result is stored at memory location 3001H. HLT CMA STA 3001H Mnemonics LDA Operand 3000H Opcode 3A 00 30 2F 32 01 30 76 Remarks Load H-L pair with data from 3000H. Lower-order of 3000H. Higher-order of 3000H. Complement accumulator. Store the result at memory location 3001H. Lower-order of 3001H. Higher-order of 3001H. Halt.

Page 1 of 2

8085 Programs

Move the lower-order from register L to accumulator.

Complement accumulator.

Move the higher-order from register H to accumulator.

Complement accumulator.

Stop

Gursharan Singh Tatla

Page 1 of 2

8085 Programs

Program: Address 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200A 200B 200C Explanation: This program finds the 1s complement of 16-bit number stored in memory 3000H-3001H. There is no direct way to find 1s complement of 16-bit number. Therefore, this can be accomplished by finding the 1s complement of two 8-bit numbers. Let us assume that the operand stored at memory locations 3000H-3001H is 45H-6AH. The operand is loaded into H-L pair from memory locations 3000H-3001H. The lower-order is moved from register L to accumulator. Its complement is found by using CMA instruction. The result obtained is moved back to register L. Then, the higher-order is moved from register H to accumulator. Its complement is found by using CMA instruction. The result obtained is moved back to register H. Now, the final result is in H-L pair. The result is stored from H-L pair to memory locations 3002H-3003H. HLT MOV CMA MOV MOV CMA MOV SHLD H, A 3002H L, A A, H A, L Mnemonics LHLD Operand 3000H Opcode 2A 00 30 7D 2F 6F 7C 2F 67 22 02 30 76 Remarks Load H-L pair with operand from 3000H. Lower-order of 3000H. Higher-order of 3000H. Move the lower-order from reg. L to reg. A. Complement accumulator. Move the result from reg. A to reg. L. Move the higher-order from reg. H to reg. A. Complement accumulator. Move the result from reg. A to reg. H. Store the result at address 3002H. Lower-order of 3002H. Higher-order of 3002H. Halt.

Output: Before Execution: 3000H: 3001H: 45H 6AH After Execution: 3002H: 3003H: BAH 95H

Page 2 of 2

8085 Programs

Load accumulator with operand from memory.

Complement accumulator.

Increment accumulator.

Store the result from accumulator to memory.

Stop

Program: Address 2000 2001 2002 2003 2004 2005 2006 2007 2008 HLT CMA INR STA A 3001H Mnemonics LDA Operand 3000H Opcode 3A 00 30 2F 2C 32 01 30 76 Remarks Load H-L pair with data from 3000H. Lower-order of 3000H. Higher-order of 3000H. Complement accumulator. Increment accumulator. Store the result at memory location 3001H. Lower-order of 3001H. Higher-order of 3001H. Halt.

Gursharan Singh Tatla

Page 1 of 2

8085 Programs

Explanation: This program finds the 2s complement of an 8-bit number stored in memory location 3000H. Let us assume that the operand stored at memory location 3000H is 85H. The operand is moved to accumulator from memory location 3000H. Then, its complement is found by using CMA instruction. One is added to accumulator by incrementing it to find its 2s complement. The result is stored at memory location 3001H.

Page 2 of 2

8085 Programs

Move the lower-order from register L to accumulator.

Complement accumulator.

Move the higher-order from register H to accumulator.

Complement accumulator.

Stop

Gursharan Singh Tatla

Page 1 of 3

8085 Programs

Program: Address 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200A 200B 200C 200D Explanation: This program finds the 2s complement of 16-bit number stored in memory locations 3000H3001H. There is no direct way to find 2s complement of 16-bit number. Therefore, this can be accomplished by finding the 1s complement of two 8-bit numbers and then incrementing it to get 2s complement. Let us assume that the operand stored at memory locations 3000H-3001H is 12H-05H. The operand is loaded into H-L pair from memory locations 3000H-3001H. The lower-order is moved from register L to accumulator. Its complement is found by using CMA instruction. The result obtained is moved back to register L. Then, the higher-order is moved from register H to accumulator. Its complement is found by using CMA instruction. The result obtained is moved back to register H. H-L pair is incremented to get 2s complement. Now, the final result is in H-L pair. The result is stored from H-L pair to memory locations 3002H-3003H. HLT MOV CMA MOV MOV CMA MOV INX SHLD H, A H 3002H L, A A, H A, L Mnemonics LHLD Operand 3000H Opcode 2A 00 30 7D 2F 6F 7C 2F 67 23 22 02 30 76 Remarks Load H-L pair with operand from 3000H. Lower-order of 3000H. Higher-order of 3000H. Move the lower-order from reg. L to reg. A. Complement accumulator. Move the result from reg. A to reg. L. Move the higher-order from reg. H to reg. A. Complement accumulator. Move the result from reg. A to reg. H. Increment H-L pair to find 2s complement. Store the result at address 3002H. Lower-order of 3002H. Higher-order of 3002H. Halt.

Gursharan Singh Tatla

Page 2 of 3

8085 Programs

Output: Before Execution: 3000H: 3001H: 12H 05H After Execution: 3002H: 3003H: EEH FAH

Gursharan Singh Tatla

Page 3 of 3

8085 Programs

Program 10: Add two 8-bit numbers along with considering the carry. Flowchart: Start

Load H-L pair with address of first operands memory location. Move the first operand from memory to accumulator.

No

If Carry?

Page 1 of 3

8085 Programs

Page 2 of 3

8085 Programs

Gursharan Singh Tatla

Page 3 of 3

8085 Programs

Program 13: Add two 16-bit numbers without considering the carry. Flowchart: Start Load H-L pair with the first 16-bit operand.

Stop

Gursharan Singh Tatla

Page 1 of 2

8085 Programs

Program: Address 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200A 200B Explanation: This program adds two 16-bit operands stored in memory locations 3000H-3001H and 3002H-3003H, without considering the carry produced (if any). Let us assume that the operands stored at memory locations 3000H-3001H is 02H-04H and 3002H-3003H is 04H-03H. The H-L pair is loaded with the first 16-bit operand 0204H from memory locations 3000H3001H. Then, the first 16-bit operand is moved to D-E pair. The second 16-bit operand 0403H is loaded to H-L pair from memory locations 3002H3003H. The two operands are added and the result is stored in H-L pair. The result is stored from H-L pair to memory locations 3004H-3005H. HLT DAD SHLD D 3004H XCHG LHLD 3002H Mnemonics LHLD Operand 3000H Opcode 2A 00 30 EB 2A 02 30 19 22 04 30 76 Remarks Load H-L pair with 1st operand from 3000H. Lower-order of 3000H. Higher-order of 3000H. Exchange H-L pair with D-E pair. Load H-L pair with 2nd operand from 3002H. Lower-order of 3002H. Higher-order of 3002H. Add D-E pair with H-L pair. Store the result at address 3004H. Lower-order of 3004H. Higher-order of 3004H. Halt.

Output: Before Execution: 3000H: 3001H: 3002H: 3003H: 02H 04H 04H 03H After Execution: 3004H: 3005H: 06H 07H

Page 2 of 2