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:

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

.code
main PROC
mov esi,OFFSET array
mov ecx,LENGTHOF array
next:
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
quit:

Recommended Answers

All 2 Replies

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.

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

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

start:
mov bx, arr
mov cx, 5
label:
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
label_exit:
jnz no_positive_found
int 20h
no_positive_found:
mov dl, 0x41
mov ah, 0x2
int 0x21
int 20h
arr dw 8000h, 8000h, 8000h, 7fffh, 8000h

Ethereal mess....
LLLLLL

hi please introuduce a good book for assembely 16-bit

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.