Write a piece of code to find the number of zeros in each byte of an array of size 1024 byte stored at addresses starting at 21000H. Store the result of each byte in another array starting at 56000H.
Greetings!!
Code:
.CODE
MOV AX,2000H ;load segment address of the given address
2000(20000+1000)
MOV DS,AX ;load into data segment
MOV AX,5000H ;load segment address of the given address
5000(50000+6000)
MOV ES,AX ;load into extra segment
MOV SI,1000H ;load offset of the source into SI
MOV DI,6000H ;load offset of the destination into DI
MOV CX,400H ;load count 1024(400H) into register CX
BACK:
MOV BX,0008 ;load 8 into register BX to shift the byte 8 times
left, shifting is done to count the number of 0s
MOV AL,[SI] ;load one byte of data from the address 21000
INC SI ;increment source pointer
COUNT:
SHL AL,1 ;shift the byte data left by one position through carry
flag
JC ONE ;if the shifted MSB to the carry flag is 1, jump to label
ONE
INC BH ;otherwise, it is 0 and count it into the register BH
ONE:
DEC BL ;decrement shift count by 1
JNZ COUNT ;if shift count is not zero, goto label COUNT
MOV [DI],BH ;if the shift count is zero,means the byte is shifted 8
times and counted the number of 0s in it and is available on BH and
is stored into address 56000 onwards
INC DI ;increment destination address where zero count is
stored
LOOP BACK ;repeat till 1024 iterations
HLT
Hope this helps
Thank You
Get Answers For Free
Most questions answered within 1 hours.