question:
In data segment i have two arrays A,B (DW) with size 1
<
N<
20 with some numbers (code runs only if arrays length less 20), code need to run in both arrays and check if number in same index of arrays equal, push them in to stack. Note: Need to do that without CMP.
Example A:
A DW 1234,35235,1234,5678
B DW 4532,32735,5678,1234
N=4
The stack will be empty
Example B:
A DW 4532,35235,1234,5678
B DW 4532,32735,1234,1234
N=4
Numbers 4532 and 1234 goes to stack
My code:
DATA SEGMENT
A DW 4535
B DW 4535
SIZEA = OFFSET B /2
SIZEB = ($-B)/2
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV SP,100h
MOV CX,SIZEB ;how times loop run
MOV DX,SIZEA ;to compare sizes of arrays
TEST CX,19 ;if size of array B above 19 numbers jump to end
JNP END
TEST DX,19 ;if size of array A above 19 numbers jump to end
JNP END
XOR DX,CX ;if arrays size not equal jump to end
JNZ END
MOV SI,0 ;index of array
CHECK:
MOV AX,A(SI)
MOV BX, B(SI)
SUB AX,BX ;if same numbers zf=1, jump to find
JZ FIND
ADD SI,2 ;goes to next index (2 because DW)
LOOP CHECK ;checking next index
JMP END ;when cx = 1 jump to end
FIND:
PUSH BX ;pushing to stack equal number
ADD SI,2
LOOP CHECK
END:
CODE ENDS
END START
This works except for length 19,16,14,13,10,9,6,5,2,1