LOOPZ vs LOOPNZ

Reply

Join Date: Oct 2009
Posts: 2
Reputation: assembly101 is an unknown quantity at this point 
Solved Threads: 0
assembly101 assembly101 is offline Offline
Newbie Poster

LOOPZ vs LOOPNZ

 
0
  #1
Oct 20th, 2009
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:
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 133
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 13
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
0
  #2
Oct 21st, 2009
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:::::::::
  1. start:
  2. mov bx, arr
  3. mov cx, 5
  4. label:
  5. mov ax, [bx]
  6. test word [bx], 8000h
  7. LOOPZ label_exit ; LOOPZ will decrement CX jump if ZF=1
  8. jcxz label_exit
  9. add bx, 2
  10. jmp label
  11. label_exit:
  12. jnz no_positive_found
  13. int 20h
  14. no_positive_found:
  15. mov dl, 0x41
  16. mov ah, 0x2
  17. int 0x21
  18. int 20h
  19. arr dw 8000h, 8000h, 8000h, 7fffh, 8000h

Ethereal mess....
LLLLLL
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC