2

I am trying nested while loop in assembly using masm. I am getting the "error A2070: invalid instruction operands" at line 15 i.e at the endw directive of internal while loop while running the following code.

INCLUDE Irvine32.inc
.data
i byte 1
j byte 2
.code
main PROC  
xor eax,eax
 .while i<5
mov j, 2
.while j<i
    mov al, j
    call writeDec
    call crlf
    inc j
.endw
inc i
 .endw
exit
main ENDP
END main

I cant find the reason for this. Can anyone help me?

rkhb
  • 14,159
  • 7
  • 32
  • 60
p096035
  • 39
  • 4
  • Related: [another Q&A about using `mov [esi], [edi]` explicitly](https://stackoverflow.com/questions/20632907/i-get-anerror-a2070-invalid-instruction-operands-how-can-i-resolved-this), instead of through MASM's "high level" macros. – Peter Cordes Dec 13 '17 at 06:11

1 Answers1

1

The error is here:

.while j<i

You cannot compare two memory contents directly. It is possible to compare a memory content with a register, e.g.:

mov dl, i
.while j<dl

BTW: Don't trust an "alien" function (Irvine's WriteDec and Crlf). When a register unintentionally changes its contents, this can due to such a function.

rkhb
  • 14,159
  • 7
  • 32
  • 60