X
X
xenofobius2017-06-08 03:38:44
assembler
xenofobius, 2017-06-08 03:38:44

Why doesn't scasw work?

It is necessary, using chain processing instructions, to find the number of given elements in the integer array. The problem is that if I just do repne scasw, it does not find matches and reaches the end (while everything works with cmp and loop). Actually here is a piece of code responsible for this:

start:
  mov ax, data
  mov ds, ax
  xor dx, dx
  mov cx, 8
  lea di, es:[massiv]
  xor bx, bx
  mov ax, 11d
  cld

m1:
  scasw
  cmp ax, 11d
  jne bli
  inc bx
bli:
  loop m1

  mov ax, bx
  call OutputInt
  mov dx,offset strend
  mov ah,9
  int 21h

  mov ax, 4c00h
  int 21h

and data segment
data Segment
  massiv dw 11d, 11d, 66d, 665d, 66d, 344d, 266d, 5221d
  strdsc db 6,0
  strbuf db 6 dup (?)
  strend  db 13,10,'$'
data ends

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2017-06-08
@ksenofobius

As Anton pointed out above , your code does not match the logic of the command.
SCASW compares the cell at ES:DI with AX, flags the results of the comparison, and increments DI by 2. Automatic DI increment allows (and this is actually the main mode of use) to prefix SCAS* with condition check prefixes (REPE, REPNE).
Accordingly, your code should contain the line
REPNE SCASW
instead
of SCASW
CMP AX,...
and loop
And now your code really seems to be LODSW-oriented and not SCASW-oriented

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question