OR DL, DL
CALL WRITE_CHAR
JZ stop
By the time the CALL WRITE_CHAR returns, the flags that were defined from the OR DL, DL instruction will have vanished! So it's possible the loop doesn't run the required number of times.
What are the even characters in a string ?
- Is it the characters that reside on an even offset within the string?
main proc
mov ax, DGROUP
mov ds, ax
xor bx, bx ; (*)
jmp char
next:
inc bx ; The sought for EVEN offset just became ODD here ...
test bx, 1
jz char ; ... so using opposite condition to skip
mov ah, 02h ; DOS.WriteChar
int 21h
char:
mov dl, adat[bx]
test dl, dl
jnz next
mov ax, 4C00h ; DOS.Terminate
int 21h
main endp
- Is it the characters at the 2nd, 4th, 6th, ... place in the string, so at odd offsets?
main proc
mov ax, DGROUP
mov ds, ax
xor bx, bx ; (*)
jmp char
next:
inc bx ; The sought for ODD offset just became EVEN here ...
test bx, 1
jnz char ; ... so using opposite condition to skip
mov ah, 02h ; DOS.WriteChar
int 21h
char:
mov dl, adat[bx]
test dl, dl
jnz next
mov ax, 4C00h ; DOS.Terminate
int 21h
main endp
- Or is it the characters whose ASCII code is an even number?
main proc
mov ax, DGROUP
mov ds, ax
xor bx, bx
jmp char
next:
inc bx
test dl, 1 ; Testing ASCII
jnz char ; Skip on ODD code
mov ah, 02h ; DOS.WriteChar
int 21h
char:
mov dl, adat[bx]
test dl, dl
jnz next
mov ax, 4C00h ; DOS.Terminate
int 21h
main endp
(*) Instead of using an extra register to test for even-ness, we can work from the address register by which we address the string.
In these code snippets, repeating the unconditional jump was avoided by placing the test for string termination near the bottom of the loop and executing a one-time-only jump to it.