Document 3
Document 3
Document 3
Program:
Memory Table:
Output:
Program:
Memory Table:
Output:
Program:
Memory Table:
Output:
Program:
NEXT:
MOV A, M ; Load memory content into A
ANI 01H ; Mask LSB to check even/odd
JNZ SKIP ; If odd, skip
INR B ; Increment even number counter
SKIP:
INX H ; Increment address pointer
DCR C ; Decrement count
JNZ NEXT ; Repeat until counter is 0
Memory Table:
Output:
Program:
NEXT:
MOV D, M ; Load memory content into D
ANI 01H ; Mask LSB to check even/odd
JNZ SKIP ; If odd, skip
ADD D ; Add even number to accumulator
SKIP:
INX H ; Increment memory address pointer
DCR C ; Decrement count
JNZ NEXT ; Repeat loop until counter is 0
Memory Table:
Output:
Program:
LXI H, 4000H ; Load first 16-bit number (at 4000H and 4001H)
LXI D, 4002H ; Load second 16-bit number (at 4002H and 4003H)
MOV A, M ; Load LSB of first number
ADD E ; Add LSB of second number
MOV L, A ; Store result in L register
INX H ; Point to MSB of first number
INX D ; Point to MSB of second number
MOV A, M ; Load MSB of first number
ADC D ; Add MSB of second number with carry
MOV H, A ; Store result in H register
SHLD 3005H ; Store 16-bit result at 3005H
HLT ; Halt
Memory Table:
Input Data:
Output:
Multiplication is performed via repeated addition since the 8085 has no direct
multiplication instruction.
Program:
LOOP:
ADD B ; Add multiplicand to accumulator
DCR C ; Decrement multiplier
JNZ LOOP ; Repeat if multiplier > 0
STA 3007H ; Store result at 3007H
HLT ; Halt
Memory Table:
Output:
Division is implemented by repeated subtraction until the dividend becomes smaller than
the divisor.
Program:
DIVIDE:
SUB C ; Subtract divisor from dividend LSB
JC END ; If carry is set, stop subtraction
INR D ; Increment quotient
JMP DIVIDE ; Repeat subtraction
END:
MOV E, A ; Move the remainder into E
STA 3005H ; Store remainder at 3005H
MOV A, D ; Move quotient into A
STA 3006H ; Store quotient at 3006H
HLT ; Halt
Memory Table:
Input Data:
Output:
Program:
LOOP:
MOV B, M ; Load the next number into B
CMP B ; Compare A with B
JC NEXT ; If A < B, skip
MOV A, B ; Update A to hold the larger number
NEXT:
INX H ; Increment memory pointer
DCR C ; Decrement counter
JNZ LOOP ; Repeat until count = 0
Memory Table:
Input Data:
Output:
This program counts how many 1s are in the binary representation of an 8-bit number.
Program:
LOOP:
MOV A, M ; Load the 8-bit number
RLC ; Rotate left through carry, shifting bits into carry
JZ NOCOUNT ; If carry is 0, skip increment
INR B ; Increment bit count if carry is set
NOCOUNT:
DCR C ; Decrement bit counter
JNZ LOOP ; Repeat for all bits
Memory Table:
Input Data:
Output:
Program:
Memory Table:
Input Data:
Output:
LOOP:
RLC ; Rotate left through carry
DCR C ; Decrement loop counter
MOV D, A ; Copy to D for checking
ANI 0F0H ; Mask upper nibble
JZ SKIP ; Skip if lower nibble is 0
Memory Table:
Output:
This program multiplies two 8-bit numbers and stores the result.
Program:
LOOP:
MOV A, C ; Move low byte of result to A
ADD B ; Add second number to result
MOV C, A ; Store result in C register
MOV A, D ; Move high byte to A
ADC 00H ; Add carry to high byte of result
MOV D, A ; Store the new high byte
Memory Table:
Input Data:
Output:
Program:
LOOP:
CMP B ; Compare A with B
JC NEXT ; If A < B, skip
MOV A, B ; If A >= B, move B to A (new smallest)
NEXT:
INX H ; Increment to next number
DCR C ; Decrement counter
JNZ LOOP ; Repeat until counter is zero
Memory Table:
Input Data:
Output:
This program converts a Binary-Coded Decimal (BCD) number to its binary equivalent.
Program:
LOOP:
RLC ; Rotate left through carry
MOV B, A ; Move the result into B register
DCR C ; Decrement the counter
JNZ LOOP ; Repeat until counter is zero
STA 300AH ; Store the binary result at 300AH
HLT ; Halt
Memory Table:
Input Data:
Output:
LOOP:
RLC ; Rotate the bits of A left through carry
MOV B, A ; Move the result into B
DCR C ; Decrement the counter
JNZ LOOP ; Repeat until counter reaches zero
Memory Table:
Input Data:
Program:
LESSTHAN:
MVI C, 01H ; Set flag to indicate A is less than B
JMP DONE
EQUAL:
MVI C, 00H ; Set flag to indicate numbers are equal
JMP DONE
GREATER:
MVI C, 02H ; Set flag to indicate A is greater than B
DONE:
HLT ; Halt
Memory Table:
Input Data:
Output:
Program:
LOOP:
RLC ; Rotate the bits of A left through carry
MOV B, A ; Move the result into B
DCR C ; Decrement the counter
JNZ LOOP ; Repeat until all 8 bits are processed
Memory Table:
Input Data:
Output: