I am trying to get this program to use LOOPZ instead of LOOPNZ to find the first positive value in an array but I am not sure how to go about it. Any hints or ideas behind doing it would be much appreciated. This is the code below:

array SWORD -3,-6,-1,-10,10,30,40,4
sentinel SWORD 0

main PROC
mov esi,OFFSET array
mov ecx,LENGTHOF array
test WORD PTR [esi],8000h ; test sign bit
pushfd ; push flags on stack
add esi,TYPE array
popfd ; pop flags from stack
loopnz next ; continue loop
jnz quit ; none found
sub esi,TYPE array ; ESI points to value

Give me convience or give me death...

This is 16-bit code, but it should give you the
general idea, the LOOPZ will decrement CX even if the ZeroFlag
is clear (no Zero Result), both LOOPZ and JCXZ are used
to exit the loop, and LOOPZ is used to exit when a positive value is
found, one with its most significant bit set to 0.
When the logical AND performed by the TEST produces
a result of zero
WORD 1000000000000000 && -32768
WORD 0111111111111111 +32767
0000000000000000 ZF set ; found a positive
LOOPZ's condition will be true and it will exit the loop.

LOOPZ ; decrement CX jump if ZF=1, will decrement
; CX even when ZF=0
JCXZ ; Jump when CX=0

16-bit 8086 Assembler follows:::::::::

mov bx, arr
mov cx, 5
mov ax, [bx]
test word [bx], 8000h
LOOPZ label_exit ; LOOPZ will decrement CX jump if ZF=1
jcxz label_exit
add bx, 2
jmp label
jnz no_positive_found
int 20h
mov dl, 0x41
mov ah, 0x2
int 0x21
int 20h
arr dw 8000h, 8000h, 8000h, 7fffh, 8000h

Ethereal mess....

This article has been dead for over six months. Start a new discussion instead.