I'm new to Assembly and I have a task to determine a number of 01 repetitions in a binary code of a 16b hex number. For example:
Number AB34 is: 1010 1011 0011 0100
As 01's are bolded above, they need to be counted and stored in RESULT in the code below. The trick is to only use logical instructions such as AND, NOT, OR, XOR, moving (SHL, SHR), rotating (ROR/RCR, ROL/RCL) and logical comparing.
Here is what I have:
name program
data segment
BR dw 0AB34H ;
RESULT db 0
data ends
code segment
assume CS:code, DS:data
start:
mov ax, data
mov ds, ax
mov ax, BR
mov cx, 16
mov bx, 0
lwhile:
; something with logical instructions
loop lwhile
mov RESULT, bl
mov ah, 4ch
int 21h
code ends
end start
I'm assuming that inside the loop some work needs to be done, counted through some register like bx and then moved to RESULT.
I'm open to any suggestions, thanks in advance.
You should making ample use of the
and
,cmp
andshr
instructions. Look them up and try them out.Overall, your code would have a structure like this:
BR
value to a working register (e.g.,bx
)BR
and you're checking pairs of bits]I'm leaving some details to you. Part of your code inside step 2 might look like this:
cmp
will check if the current pair of bits that have been shifted down to the lower order two bits are01
. To check the next pair of bits, use theshr
instruction. Your loop would continue shifting by one bit until you've exhausted all the bits in the working register.