Skip to content
Advanced Microprocessor

8085 Assembly Language Programming

16 core syllabus programs with full opcode tables, data transfer, arithmetic, BCD, code conversion, array max, and bubble sort.

Knova editors15 min readQuick checkSources

Intel 8085 Assembly Language Programming

Assembly language programming in the Intel 8085 requires understanding the internal register architecture, memory pointer manipulation using the HLHL pair, condition flag updates, and loop counter structures.

Foundational 8085 Assembly Programs

The following programs form the core assembly programming curriculum for Intel 8085 from the standard textbook and syllabus. Each program is documented with its algorithm, complete memory address map, hex opcodes, mnemonics, operands, comments, and verified sample test data.

Program 1: Store 8-Bit Data Directly in Memory (Ex. 5.1)

Problem Statement: Store the immediate data A8H\text{A8H} in memory location 2501H2501\text{H}.

AddressOpcodeMnemonicOperandComments
20003EMVIA, A8HLoad accumulator with immediate byte A8H
2001A8Immediate data byte
200232STA2501H2501\text{H}Store accumulator data to memory 2501H
200301Lower byte of memory address
200425Higher byte of memory address
200576HLTHalt execution
assembly
1; Program 1: Store 8-bit Data Directly in Memory
2START: MVI A, A8H ; Load accumulator with immediate byte A8H
3 STA 2501H ; Store accumulator data directly to memory 2501H
4 HLT ; Halt processor

Sample Result: Memory location (2501H)=A8H(2501\text{H}) = \text{A8H}.

Program 2: Direct Memory Read into Register (Ex. 5.2)

Problem Statement: Read the 8-bit content of memory location 2501H2501\text{H} and transfer it into register CC.

AddressOpcodeMnemonicOperandComments
20003ALDA2501H2501\text{H}Load accumulator with data from memory 2501H
200101Lower-order address byte (01H)
200225Higher-order address byte (25H)
20034FMOVC, ACopy data from accumulator to register C
200476HLTHalt processor
assembly
1; Program 2: Direct Memory Read into Register
2START: LDA 2501H ; Load accumulator with content of memory 2501H
3 MOV C, A ; Copy data from A into register C
4 HLT ; Halt

Sample Result: If (2501H)=47H(2501\text{H}) = 47\text{H}, after execution register C=47HC = 47\text{H} and A=47HA = 47\text{H}.

Program 3: Register Indirect Memory Read (Ex. 5.3)

Problem Statement: Move the content of memory location 2501H2501\text{H} to register CC using indirect addressing via HL register pair.

AddressOpcodeMnemonicOperandComments
200021LXIH, 2501HLoad H-L pair with address 2501H
200101Lower-order address byte (01H)
200225Higher-order address byte (25H)
20034EMOVC, MMove data from memory [HL] to register C
200476HLTHalt processor
assembly
1; Program 3: Register Indirect Memory Read
2START: LXI H, 2501H ; Point HL pointer to 2501H
3 MOV C, M ; Move data from memory [HL] into register C
4 HLT ; Halt

Sample Result: If (2501H)=99H(2501\text{H}) = 99\text{H}, after execution register C=99HC = 99\text{H}.

Program 4: Memory-to-Memory Transfer via Direct Addressing (Ex. 5.4)

Problem Statement: Copy the 8-bit content of memory location 2501H2501\text{H} into adjacent memory location 2502H2502\text{H}.

AddressOpcodeMnemonicOperandComments
20003ALDA2501H2501\text{H}Load accumulator with data from 2501H
200101Lower-order byte (01H)
200225Higher-order byte (25H)
200332STA2502H2502\text{H}Store accumulator data to memory 2502H
200402Lower-order byte (02H)
200525Higher-order byte (25H)
200676HLTHalt processor
assembly
1; Program 4: Memory-to-Memory Transfer via Direct Addressing
2START: LDA 2501H ; Load byte from source 2501H into A
3 STA 2502H ; Store byte from A into destination 2502H
4 HLT ; Halt

Sample Result: If (2501H)=35H(2501\text{H}) = 35\text{H}, after execution (2502H)=35H(2502\text{H}) = 35\text{H}.

Program 5: Memory-to-Memory Transfer via Indirect Addressing (Ex. 5.5)

Problem Statement: Move the content of memory location 2501H2501\text{H} to 2502H2502\text{H} using the HL pointer and INX H.

AddressOpcodeMnemonicOperandComments
200021LXIH, 2501HLoad H-L pair with address 2501H
200101Lower-order address byte (01H)
200225Higher-order address byte (25H)
20037EMOVA, MMove data from memory 2501H to register A
200423INXHIncrement H-L pair to point to 2502H
200577MOVM, AMove data from register A to memory 2502H
200676HLTHalt processor
assembly
1; Program 5: Memory-to-Memory Transfer via Indirect Addressing
2START: LXI H, 2501H ; Point HL to source address 2501H
3 MOV A, M ; Fetch source byte into Accumulator
4 INX H ; Advance pointer to destination address 2502H
5 MOV M, A ; Write byte into memory [HL]
6 HLT ; Halt

Sample Result: If (2501H)=5BH(2501\text{H}) = 5\text{BH}, after execution (2502H)=5BH(2502\text{H}) = 5\text{BH}.

Program 6: Increment Memory Content & Save (Ex. 5.6)

Problem Statement: Increment the byte stored at memory location 2501H2501\text{H} by 11 and write it to memory location 2502H2502\text{H}.

AddressOpcodeMnemonicOperandComments
200021LXIH, 2501HLoad H-L pair with address 2501H
200101Lower-order address byte (01H)
200225Higher-order address byte (25H)
20037EMOVA, MMove data from memory 2501H to register A
20043CINRAIncrement accumulator by 1
200523INXHIncrement H-L pair to point to 2502H
200677MOVM, AStore incremented data to memory 2502H
200776HLTHalt processor
assembly
1; Program 6: Increment Memory Content and Save
2START: LXI H, 2501H ; Point HL to 2501H
3 MOV A, M ; Read byte into Accumulator
4 INR A ; Increment Accumulator by 1
5 INX H ; Advance HL to 2502H
6 MOV M, A ; Store incremented result to 2502H
7 HLT ; Halt

Sample Result: If (2501H)=14H(2501\text{H}) = 14\text{H}, after execution (2502H)=15H(2502\text{H}) = 15\text{H}.

Program 7: 8-Bit Addition Without Carry (Section 5.5 / Ex. 5.7)

Problem Statement: Add two 8-bit numbers stored at 2501H2501\text{H} and 2502H2502\text{H}, and store the sum at 2503H2503\text{H} (without considering carry).

AddressOpcodeMnemonicOperandComments
200021LXIH, 2501HLoad H-L pair with address 2501H
200101Lower-order byte (01H)
200225Higher-order byte (25H)
20037EMOVA, MMove 1st operand to register A
200423INXHIncrement H-L pair to 2502H
200546MOVB, MMove 2nd operand to register B
200680ADDBAdd B with A (A <- A + B)
200723INXHIncrement H-L pair to 2503H
200877MOVM, AStore result from A to memory 2503H
200976HLTHalt processor
assembly
1; Program 7: 8-Bit Addition Without Carry
2START: LXI H, 2501H ; Point HL to 1st operand
3 MOV A, M ; A = [2501H]
4 INX H ; Point to 2nd operand
5 MOV B, M ; B = [2502H]
6 ADD B ; A = A + B
7 INX H ; Point to destination 2503H
8 MOV M, A ; [2503H] = Sum
9 HLT ; Halt

Sample Result: If (2501H)=05H(2501\text{H}) = 05\text{H} and (2502H)=03H(2502\text{H}) = 03\text{H}, after execution (2503H)=08H(2503\text{H}) = 08\text{H}.

Program 8: 8-Bit Subtraction Without Borrow (Section 5.6 / Ex. 5.8)

Problem Statement: Subtract the 8-bit operand stored at 2502H2502\text{H} from the operand at 2501H2501\text{H}, and store the difference at 2503H2503\text{H}.

AddressOpcodeMnemonicOperandComments
200021LXIH, 2501HLoad H-L pair with address 2501H
200101Lower-order byte (01H)
200225Higher-order byte (25H)
20037EMOVA, MMove 1st operand (minuend) to A
200423INXHIncrement H-L pair to 2502H
200546MOVB, MMove 2nd operand (subtrahend) to B
200690SUBBSubtract B from A (A <- A - B)
200723INXHIncrement H-L pair to 2503H
200877MOVM, AStore difference to memory 2503H
200976HLTHalt processor
assembly
1; Program 8: 8-Bit Subtraction Without Borrow
2START: LXI H, 2501H ; Point HL to minuend
3 MOV A, M ; A = [2501H]
4 INX H ; Point to subtrahend
5 MOV B, M ; B = [2502H]
6 SUB B ; A = A - B
7 INX H ; Point to 2503H
8 MOV M, A ; [2503H] = Difference
9 HLT ; Halt

Sample Result: If (2501H)=05H(2501\text{H}) = 05\text{H} and (2502H)=03H(2502\text{H}) = 03\text{H}, after execution (2503H)=02H(2503\text{H}) = 02\text{H}.

Program 9: 8-Bit Addition Considering Carry (Section 5.7)

Problem Statement: Add two 8-bit numbers stored at 2501H2501\text{H} and 2502H2502\text{H}. Store the 8-bit sum at 2503H2503\text{H} and the generated carry (00H00\text{H} or 01H01\text{H}) at 2504H2504\text{H}.

AddressOpcodeMnemonicOperandComments
200021LXIH, 2501HLoad H-L pair with address 2501H
200101Lower-order byte (01H)
200225Higher-order byte (25H)
20030E0\text{E}MVIC, 00HInitialize register C = 00H (carry register)
200400Immediate byte 00H
20057EMOVA, MMove 1st operand to register A
200623INXHIncrement H-L pair to 2502H
200786ADDMAdd 2nd operand from memory to A
2008D2JNC200CH200\text{CH}Jump to AHEAD (200CH) if no carry
20090C0\text{C}Lower address byte (0CH)
200A200\text{A}20Higher address byte (20H)
200B200\text{B}0C0\text{C}INRCIncrement register C (Carry = 1)
200C200\text{C}23INXHAHEAD: Increment H-L pair to 2503H
200D200\text{D}77MOVM, AStore 8-bit sum to memory 2503H
200E200\text{E}23INXHIncrement H-L pair to 2504H
200F200\text{F}71MOVM, CStore carry from register C to 2504H
201076HLTHalt processor
assembly
1; Program 9: 8-Bit Addition Considering Carry
2START: LXI H, 2501H ; Point HL to 1st operand
3 MVI C, 00H ; Clear carry register C = 00H
4 MOV A, M ; A = [2501H]
5 INX H ; Point to 2nd operand
6 ADD M ; A = A + [2502H]
7 JNC AHEAD ; If Carry flag = 0, jump to AHEAD
8 INR C ; If Carry flag = 1, increment C
9AHEAD: INX H ; Point to sum location 2503H
10 MOV M, A ; [2503H] = Sum
11 INX H ; Point to carry location 2504H
12 MOV M, C ; [2504H] = Carry (00H or 01H)
13 HLT ; Halt

Sample Test Data:

  • Input: (2501H)=F5H(2501\text{H}) = \text{F5H}, (2502H)=8AH(2502\text{H}) = 8\text{AH}
  • Calculation: F5H+8AH=17FH\text{F5H} + 8\text{AH} = 17\text{FH} (Sum=7FH\text{Sum} = 7\text{FH}, Carry=01H\text{Carry} = 01\text{H})
  • Output: (2503H)=7FH(2503\text{H}) = 7\text{FH}, (2504H)=01H(2504\text{H}) = 01\text{H}

Program 10: 8-Bit Subtraction Considering Borrow (Section 5.8)

Problem Statement: Subtract the 8-bit operand at 2502H2502\text{H} from 2501H2501\text{H}. Store the 8-bit difference at 2503H2503\text{H} and the generated borrow (00H00\text{H} or 01H01\text{H}) at 2504H2504\text{H}.

AddressOpcodeMnemonicOperandComments
200021LXIH, 2501HLoad H-L pair with address 2501H
200101Lower-order byte (01H)
200225Higher-order byte (25H)
20030E0\text{E}MVIC, 00HInitialize register C = 00H (borrow register)
200400Immediate byte 00H
20057EMOVA, MMove 1st operand to register A
200623INXHIncrement H-L pair to 2502H
200796SUBMSubtract 2nd operand from memory from A
2008D2JNC200CH200\text{CH}Jump to AHEAD (200CH) if no borrow
20090C0\text{C}Lower address byte (0CH)
200A200\text{A}20Higher address byte (20H)
200B200\text{B}0C0\text{C}INRCIncrement register C (Borrow = 1)
200C200\text{C}23INXHAHEAD: Increment H-L pair to 2503H
200D200\text{D}77MOVM, AStore 8-bit difference to memory 2503H
200E200\text{E}23INXHIncrement H-L pair to 2504H
200F200\text{F}71MOVM, CStore borrow from register C to 2504H
201076HLTHalt processor
assembly
1; Program 10: 8-Bit Subtraction Considering Borrow
2START: LXI H, 2501H ; Point HL to minuend
3 MVI C, 00H ; Clear borrow register C = 00H
4 MOV A, M ; A = [2501H]
5 INX H ; Point to subtrahend
6 SUB M ; A = A - [2502H]
7 JNC AHEAD ; If Borrow flag (CY) = 0, jump to AHEAD
8 INR C ; If Borrow flag (CY) = 1, increment C
9AHEAD: INX H ; Point to difference location 2503H
10 MOV M, A ; [2503H] = Difference
11 INX H ; Point to borrow location 2504H
12 MOV M, C ; [2504H] = Borrow (00H or 01H)
13 HLT ; Halt

Sample Test Data:

  • Input: (2501H)=60H(2501\text{H}) = 60\text{H}, (2502H)=C6H(2502\text{H}) = \text{C6H}
  • Calculation: 60H−C6H=60H+3AH=9AH60\text{H} - \text{C6H} = 60\text{H} + 3\text{AH} = 9\text{AH} with Borrow (CY=1CY = 1)
  • Output: (2503H)=9AH(2503\text{H}) = 9\text{AH}, (2504H)=01H(2504\text{H}) = 01\text{H}

Program 11: 16-Bit Addition (Section 5.9)

Problem Statement: Add two 16-bit numbers stored in little-endian order at 2501H−2502H2501\text{H}-2502\text{H} and 2503H−2504H2503\text{H}-2504\text{H}. Store the 16-bit sum at 2505H−2506H2505\text{H}-2506\text{H}.

AddressOpcodeMnemonicOperandComments
20002A2\text{A}LHLD2501H2501\text{H}Load H-L pair with 1st 16-bit operand from 2501H
200101Lower-order address byte (01H)
200225Higher-order address byte (25H)
2003EBXCHGExchange H-L with D-E (DE <- HL)
20042A2\text{A}LHLD2503H2503\text{H}Load H-L pair with 2nd 16-bit operand from 2503H
200503Lower-order address byte (03H)
200625Higher-order address byte (25H)
200719DADDAdd D-E to H-L (HL <- HL + DE)
200822SHLD2505H2505\text{H}Store 16-bit result from H-L pair to 2505H
200905Lower-order address byte (05H)
200A200\text{A}25Higher-order address byte (25H)
200B200\text{B}76HLTHalt processor
assembly
1; Program 11: 16-Bit Addition using DAD
2START: LHLD 2501H ; Load HL with 1st 16-bit operand (L=[2501H], H=[2502H])
3 XCHG ; Move 1st operand into DE pair
4 LHLD 2503H ; Load HL with 2nd 16-bit operand (L=[2503H], H=[2504H])
5 DAD D ; HL = HL + DE (16-bit addition)
6 SHLD 2505H ; Store 16-bit sum (L->[2505H], H->[2506H])
7 HLT ; Halt

Sample Test Data:

  • Operand 1: (2501H)=96H(2501\text{H}) = 96\text{H}, (2502H)=5AH⟹5A96H(2502\text{H}) = 5\text{AH} ⟹ 5\text{A}96\text{H}
  • Operand 2: (2503H)=4EH(2503\text{H}) = 4\text{EH}, (2504H)=8FH⟹8F4EH(2504\text{H}) = 8\text{FH} ⟹ 8\text{F}4\text{EH}
  • Calculation: 5A96H+8F4EH=E9E4H5\text{A}96\text{H} + 8\text{F}4\text{EH} = \text{E}9\text{E}4\text{H}
  • Output: (2505H)=E4H(2505\text{H}) = \text{E4H} (lower byte), (2506H)=E9H(2506\text{H}) = \text{E9H} (higher byte)

Program 12: One's Complement of an 8-Bit Number (Section 5.13)

Problem Statement: Find the 1's complement of an 8-bit number stored at 2501H2501\text{H} and store the result at 2502H2502\text{H}.

AddressOpcodeMnemonicOperandComments
20003ALDA2501H2501\text{H}Load accumulator with data from 2501H
200101Lower-order address byte (01H)
200225Higher-order address byte (25H)
20032F2\text{F}CMAInvert all bits of accumulator (A <- NOT A)
200432STA2502H2502\text{H}Store 1's complement result to 2502H
200502Lower-order address byte (02H)
200625Higher-order address byte (25H)
200776HLTHalt processor
assembly
1; Program 12: 1's Complement of an 8-bit Number
2START: LDA 2501H ; Load byte into Accumulator
3 CMA ; Complement Accumulator bits (bitwise NOT)
4 STA 2502H ; Store 1's complement to 2502H
5 HLT ; Halt

Sample Test Data:

  • Input: (2501H)=E4H(2501\text{H}) = \text{E4H} (1110 010021110\,0100_2)
  • Calculation: 1110 01002‾=0001 10112=1BH\overline{1110\,0100_2} = 0001\,1011_2 = 1\text{BH}
  • Output: (2502H)=1BH(2502\text{H}) = 1\text{BH}

Program 13: Two's Complement of an 8-Bit Number (Section 5.14)

Problem Statement: Find the 2's complement of an 8-bit number stored at 2501H2501\text{H} and store the result at 2502H2502\text{H}.

AddressOpcodeMnemonicOperandComments
20003ALDA2501H2501\text{H}Load accumulator with data from 2501H
200101Lower-order address byte (01H)
200225Higher-order address byte (25H)
20032F2\text{F}CMAInvert all bits of accumulator
20043CINRAAdd 1 to accumulator (A <- A + 1)
200532STA2502H2502\text{H}Store 2's complement result to 2502H
200602Lower-order address byte (02H)
200725Higher-order address byte (25H)
200876HLTHalt processor
assembly
1; Program 13: 2's Complement of an 8-bit Number
2START: LDA 2501H ; Load byte into Accumulator
3 CMA ; Form 1's complement (invert bits)
4 INR A ; Add 1 to form 2's complement
5 STA 2502H ; Store 2's complement to 2502H
6 HLT ; Halt

Sample Test Data:

  • Input: (2501H)=96H(2501\text{H}) = 96\text{H} (1001 011021001\,0110_2)
  • Calculation: 1's complement = 0110 10012=69H0110\,1001_2 = 69\text{H}; 2's complement = 69H+1=6AH69\text{H} + 1 = 6\text{AH} (0110 101020110\,1010_2)
  • Output: (2502H)=6AH(2502\text{H}) = 6\text{AH}

Program 14: Mask Off Lowest Nibble of an 8-Bit Number (Section 5.20)

Problem Statement: Mask off the lowest nibble (bits D3−D0D_3-D_0) of an 8-bit number stored at 2501H2501\text{H} and store the result at 2502H2502\text{H}.

AddressOpcodeMnemonicOperandComments
20003ALDA2501H2501\text{H}Load accumulator with data from 2501H
200101Lower-order address byte (01H)
200225Higher-order address byte (25H)
2003E6ANIF0HBitwise AND immediate F0H with accumulator
2004F0Immediate mask byte F0H
200532STA2502H2502\text{H}Store masked result to memory 2502H
200602Lower-order address byte (02H)
200725Higher-order address byte (25H)
200876HLTHalt processor
assembly
1; Program 14: Mask Off Lowest Nibble (D3-D0)
2START: LDA 2501H ; Load byte into Accumulator
3 ANI F0H ; AND with 1111 0000b to clear lowest 4 bits
4 STA 2502H ; Store masked result to 2502H
5 HLT ; Halt

Sample Test Data:

  • Input: (2501H)=A8H(2501\text{H}) = \text{A8H} (1010 100021010\,1000_2)
  • Calculation: 1010 10002 AND 1111 00002=1010 00002=A0H1010\,1000_2 \text{ AND } 1111\,0000_2 = 1010\,0000_2 = \text{A0H}
  • Output: (2502H)=A0H(2502\text{H}) = \text{A0H}

Program 15: Block Transfer of N Bytes (Section 5.21)

Problem Statement: Transfer a block of NN data bytes from source starting at 2501H2501\text{H} to destination starting at 2551H2551\text{H}. The count NN is stored at 2500H2500\text{H}.

AddressOpcodeMnemonicOperandComments
200021LXIH, 2500HLoad H-L pair with address 2500H
200100Lower-order byte (00H)
200225Higher-order byte (25H)
20034EMOVC, MLoad count N from 2500H into register C
200423INXHIncrement H-L to 2501H (source start)
200511LXID, 2551HLoad D-E with destination address 2551H
200651Lower-order byte (51H)
200725Higher-order byte (25H)
20087EMOVA, MLOOP: Move source byte at [HL] into A
200912STAXDStore byte into destination [DE]
200A200\text{A}23INXHIncrement source pointer H-L
200B200\text{B}13INXDIncrement destination pointer D-E
200C200\text{C}0D0\text{D}DCRCDecrement byte counter C
200D200\text{D}C2JNZ2008H2008\text{H}Jump to LOOP (2008H) if C != 0
200E200\text{E}08Lower address byte (08H)
200F200\text{F}20Higher address byte (20H)
201076HLTHalt processor
assembly
1; Program 15: Block Transfer of N Bytes
2START: LXI H, 2500H ; Point HL to block count address
3 MOV C, M ; Load count N into counter register C
4 INX H ; Advance HL to start of source array (2501H)
5 LXI D, 2551H ; Point DE to start of destination array
6LOOP: MOV A, M ; Fetch source byte into Accumulator
7 STAX D ; Store byte into destination memory [DE]
8 INX H ; Advance source pointer
9 INX D ; Advance destination pointer
10 DCR C ; Decrement counter
11 JNZ LOOP ; Repeat loop until C reaches 0
12 HLT ; Halt

Sample Test Data:

  • Count: (2500H)=05H(2500\text{H}) = 05\text{H} (N=5N = 5)
  • Source: (2501H)=06H,(2502H)=16H,(2503H)=02H,(2504H)=66H,(2505H)=39H(2501\text{H})=06\text{H}, (2502\text{H})=16\text{H}, (2503\text{H})=02\text{H}, (2504\text{H})=66\text{H}, (2505\text{H})=39\text{H}
  • Destination Output: (2551H)=06H,(2552H)=16H,(2553H)=02H,(2554H)=66H,(2555H)=39H(2551\text{H})=06\text{H}, (2552\text{H})=16\text{H}, (2553\text{H})=02\text{H}, (2554\text{H})=66\text{H}, (2555\text{H})=39\text{H}

Program 16: Block Transfer of N Bytes in Reverse Order (Section 5.22)

Problem Statement: Transfer a block of NN data bytes from source starting at 2501H2501\text{H} to destination starting at 2551H2551\text{H} in reverse order. Count NN is at 2500H2500\text{H}.

AddressOpcodeMnemonicOperandComments
200021LXIH, 2500HLoad H-L pair with address 2500H
200100Lower-order byte (00H)
200225Higher-order byte (25H)
20034EMOVC, MLoad count N into counter C
200423INXHIncrement H-L to 2501H (source start)
200511LXID, 2555HPoint D-E to end of destination 2555H
200655Lower-order byte (55H)
200725Higher-order byte (25H)
20087EMOVA, MLOOP: Move source byte into A
200912STAXDStore byte into destination [DE]
200A200\text{A}23INXHIncrement source pointer H-L
200B200\text{B}1B1\text{B}DCXDDecrement destination pointer D-E
200C200\text{C}0D0\text{D}DCRCDecrement counter C
200D200\text{D}C2JNZ2008H2008\text{H}Jump to LOOP (2008H) if C != 0
200E200\text{E}08Lower address byte (08H)
200F200\text{F}20Higher address byte (20H)
201076HLTHalt processor
assembly
1; Program 16: Block Transfer in Reverse Order
2START: LXI H, 2500H ; Point HL to count address
3 MOV C, M ; Load count N into register C
4 INX H ; Advance HL to start of source array (2501H)
5 LXI D, 2555H ; Point DE to the END of destination array
6LOOP: MOV A, M ; Fetch source byte
7 STAX D ; Store byte into destination memory [DE]
8 INX H ; Advance source pointer forward
9 DCX D ; Move destination pointer backward
10 DCR C ; Decrement counter
11 JNZ LOOP ; Repeat loop until C reaches 0
12 HLT ; Halt

Sample Test Data:

  • Count: (2500H)=05H(2500\text{H}) = 05\text{H}
  • Source: (2501H)=06H,(2502H)=16H,(2503H)=02H,(2504H)=66H,(2505H)=39H(2501\text{H})=06\text{H}, (2502\text{H})=16\text{H}, (2503\text{H})=02\text{H}, (2504\text{H})=66\text{H}, (2505\text{H})=39\text{H}
  • Destination Output (Reversed): (2551H)=39H,(2552H)=66H,(2553H)=02H,(2554H)=16H,(2555H)=06H(2551\text{H})=39\text{H}, (2552\text{H})=66\text{H}, (2553\text{H})=02\text{H}, (2554\text{H})=16\text{H}, (2555\text{H})=06\text{H}

Advanced Curriculum Programs

Finding the Largest Number in an Array

assembly
1; Problem: Find the maximum 8-bit unsigned value in an array of N elements
2; Starting address of array: 2050H (First byte is array length N)
3
4START: LXI H, 2050H ; Point HL to start of array data
5 MOV C, M ; Load count N into register C
6 DCR C ; Decrement count (N-1 comparisons)
7 INX H ; Point to first data element
8 MOV A, M ; Initialize maximum candidate in A
9LOOP: INX H ; Point to next element
10 CMP M ; Compare A with [HL]
11 JNC SKIP ; If A >= [HL], skip replacement
12 MOV A, M ; If [HL] > A, replace maximum with [HL]
13SKIP: DCR C ; Decrement counter
14 JNZ LOOP ; Repeat until all elements evaluated
15 STA 3000H ; Store largest element at 3000H
16 HLT ; Halt processor

Bubble Sort Array in Ascending Order

assembly
1; Sort an array of N numbers in ascending order
2START: MVI B, 04H ; Outer loop counter = (N - 1)
3OUTER: LXI H, 2050H ; Initialize array pointer
4 MOV C, B ; Inner loop counter = remaining passes
5INNER: MOV A, M ; Load current element into A
6 INX H ; Advance pointer to next element
7 CMP M ; Compare element [i] with [i+1]
8 JC NO_SWAP ; If [i] < [i+1], already sorted
9 MOV D, M ; If out of order, perform swap using D:
10 MOV M, A ; [i+1] = A
11 DCX H ; Back up pointer to [i]
12 MOV M, D ; [i] = D
13 INX H ; Restore pointer to [i+1]
14NO_SWAP:DCR C ; Decrement inner pass counter
15 JNZ INNER ; Repeat inner loop
16 DCR B ; Decrement outer pass counter
17 JNZ OUTER ; Repeat outer loop
18 HLT ; Halt
Try it
Array Traversal with Register Indirect Addressing: In 8085 assembly, when traversing a contiguous array in memory using the HL register pair, which instruction advances the pointer to the next consecutive memory location?

Sources

  1. 1.8085 Assembly Language Reference · Intel · technical (opens in a new tab)

Was this chapter useful?

Editors read every answer.

Star this chapter

Each star goes once to every reader who improved this chapter.

Finished reading?

Mark it to keep your place in the course.