| | |
LOOPZ vs LOOPNZ
![]() |
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
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:
.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:
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:::::::::
Ethereal mess....
LLLLLL
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:::::::::
Assembly Syntax (Toggle Plain Text)
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
----------------------------------------------------------
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/
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/
![]() |
Similar Threads
- Countdown timer (Assembly)
- Space Invaders (Assembly)
- Second Stage Loader (Assembly)
- I Need Assembly help w/reversing strings (Assembly)
Other Threads in the Assembly Forum
- Previous Thread: Machine relative offsets
- Next Thread: convert C to Mips
| Thread Tools | Search this Thread |





