Reputation: 1640
Im having a problem with a final part of my assignment. We get in a stream of bits, etc etc, in the stream is an integer with the number of 1's in the text portion. I get that integer and its 24 which is correct, now i loop through the text data i get and i try to count all the 1's in there. But my proc is always returning zero.
I was able to make sure it was looping properly and it is.
The text = Hello which is 16 1's, here is my proc for looping through that text to count the number of ones in it.
sub AX,AX
sub SI,SI
mov bx,[bp+6] ;get message offset
@@mainLoop:
mov cx,8
mov dh,80h
cmp byte ptr [bx + si],0
je @@endChecker
@@innerLoop:
test byte ptr [bx + si],dh
jz @@zeroFound
inc AX
@@zeroFound:
shr bh,1
loop @@innerLoop
@@continue:
inc si
jmp @@mainLoop
the rest of the proc is just push/pops. What im wanting this to actually do is use TEST to compare 100000000 to a byte, if its a 1 inc AX else shift right the mask by 1 and loop a whole byte, than inc to next byte and do again.
Upvotes: 2
Views: 334
Reputation: 86433
Just to give you an alternative and shorter implementation of your inner-loop:
mov cx, 8
mov dh, byte ptr [bx+si]
@@innerLoop:
add dh, dh
adc ax, 0
loop @@innerLoop
Here we don't test the bits at all. Instead the add dh, dh shifts the topmost bit into the carry and also does the same as shl dh,1 in one instruction.
The addc ax,0 just adds the carry to AX.
Upvotes: 1