- 2071 Magh · 8 marks
8085 ALP: transfer data with more than 3 ones
Short answer
Count the 1s in each byte by rotating right eight times, incrementing a counter when carry is set. If the count is 4 or greater, copy the byte to table2; otherwise store FFH. For instance, 0FH is copied, 07H becomes FFH.
Write an assembly language program for 8085. Table1 contains 16 no. of 8 bit data, transfer data which have number of 1s greater than 3, from table1 to table2, otherwise store FFH in table2.
Assumptions: table 1 is at 2000H (16 bytes) and table 2 at 2100H. Data and FFH are written at the same index in table 2.
Method: the number of 1s is counted by rotating the byte right 8 times and incrementing a counter each time CY = 1. CPI 04H sets CY if the count is less than 4. For 4 or more ones (more than 3) the original byte is stored; otherwise FFH is stored.
LXI H,2000H ; HL -> table 1 (16 bytes)
MVI D,10H ; 16 numbers
LOOP: MOV A,M
MOV B,A ; keep the data in B
MVI C,00H ; C = number of ones
MVI E,08H ; 8 bits to test
CNT: RRC
JNC NEXT
INR C ; bit = 1
NEXT: DCR E
JNZ CNT
MOV A,C
CPI 04H ; CY = 1 if ones < 4
MOV A,B ; A = data (MOV keeps the flags)
JNC STORE ; ones >= 4, i.e. more than 3 -> keep data
MVI A,0FFH ; otherwise store FFH
STORE: INR H ; table 2 = table 1 + 0100H (2100H)
MOV M,A
DCR H
INX H
DCR D
JNZ LOOP
HLT
Example: byte 0FH has four 1s, so 0FH is copied; byte 07H has three 1s, so FFH is stored.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- 8085 ALP: compare two tables of 16-bit data · Microprocessor, chapter 2
- 8085 ALP: count ones in upper nibble · Microprocessor, chapter 2
- 8085 ALP: transfer with bit set/reset · Microprocessor, chapter 2
- 8085 ALP: odd parity transfer with bit change · Microprocessor, chapter 2
- 8085 ALP: copy data within a range · Microprocessor, chapter 2
- 8086 ALP: max and min of 16-bit list · Microprocessor, chapter 3
- Count number of 1s in ROM data · Embedded System, chapter 9 · asked 2×
- RE: no more than 3 a's · Theory of Computation, chapter 2
- FFH AND C0H; (16)₁₀ − (26)₁₀ by 2's complement · Digital Logic, chapter 5
- C program: sum of two 8-bit BCD numbers · Embedded System, chapter 9