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

After Execution: Complement accumulator. 3001H: 7AH

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.

Gursharan Singh Tatla

Page 1 of 2

8085 Programs

Program 3: 1s complement of 16-bit number. Flowchart: Start

Load H-L pair with the 16bit operand.

Move the lower-order from register L to accumulator.

Complement accumulator.

Move the result from accumulator to register L.

Move the higher-order from register H to accumulator.

Complement accumulator.

Move the result from accumulator to register H.

Store the result from H-L pair to memory.

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

Gursharan Singh Tatla

Page 2 of 2

8085 Programs

Program 2: 2s complement of an 8-bit number. Flowchart: Start

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.

Output: Before Execution: 3000H: 85H

After Execution: 3001H: 7BH

Gursharan Singh Tatla

Page 2 of 2

8085 Programs

Program 4: 2s complement of 16-bit number. Flowchart: Start

Load H-L pair with the 16bit operand.

Move the lower-order from register L to accumulator.

Complement accumulator.

Move the result from accumulator to register L.

Move the higher-order from register H to accumulator.

Complement accumulator.

Move the result from accumulator to register H.

Increment H-L pair.

Store the result from H-L pair to memory.

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.

Move the result from accumulator to memory.

Increment H-L pair.

Increment H-L pair to point to next memory location.

Move the carry from register C to memory.

Stop Move the second operand from memory to register B.

Initialize register C with 0.

Add B with A.

No

If Carry?

Yes Increment register C.

Increment H-L pair.

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 200E 200F 2010 2011 Explanation: This program adds two operands stored in memory location 3000H and 3001H, along with considering the carry produced (if any). Let us assume that the operands stored at memory location 3000H is FAH and 3001H is 28H. Initially, H-L pair is loaded with the address of first memory location. The first operand is moved to accumulator from memory location 3000H and H-L pair is incremented to point to next memory location. The second operand is moved to register B from memory location 3001H. Register C is initialized to 00H. It stores the carry (if any). The two operands stored in register A and B are added and the result is stored in accumulator. Then, carry flag is checked for carry. If there is a carry, C register is incremented. H-L pair is incremented and the result is moved from accumulator to memory 3002H. H-L pair is again incremented and carry (either 0 or 1) is moved from register C to memory location 3003H. INR INX MOV INX MOV HLT C H M, A H M, C ADD JNC B 200D MOV INX MOV MVI A, M H B, M C, 00H Mnemonics LXI Operand H, 3000H Opcode 21 00 30 7E 23 46 0E 00 80 D2 0D 20 0C 23 77 23 71 76 Remarks Load H-L pair with address 3000H. Lower-order of 3000H. Higher-order of 3000H. Move the 1st operand from memory to reg. A. Increment H-L pair. Move the 2nd operand from memory to reg. B. Initialize reg. C with 00H. Immediate value 00H. Add B with A. Jump to address 200DH if there is no carry. Lower-order of 200DH. Higher-order of 200DH. Increment reg. C. Increment H-L pair. Move the result from reg. A to memory. Increment H-L pair. Move carry from reg. C to memory. Halt.

Gursharan Singh Tatla

Page 2 of 3

8085 Programs

Output: Before Execution: 3000H: 3001H: FAH 28H

After Execution: 3002H: 3003H: 22H 01H

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.

Move the first operand to D-E pair.

Load H-L pair with the second 16-bit operand.

Add two 16-bit numbers.

Store the 16-bit result from H-L pair to memory.

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

Gursharan Singh Tatla

Page 2 of 2