Discussion:
test al,al setting of ZF
(too old to reply)
bilsch01
2020-12-29 10:26:42 UTC
Permalink
True or False:
test al,al sets ZF only if al = 0

TIA. Bill S.
Rod Pemberton
2020-12-30 10:18:28 UTC
Permalink
On Tue, 29 Dec 2020 02:26:42 -0800
Post by bilsch01
test al,al sets ZF only if al = 0
Look up TEST instruction here:

http://qcd.phys.cmu.edu/QCDcluster/intel/vtune/reference/About_IA-32_Instructions.htm

That's a browse-able HTML version of an IA-32 manual.
--
Sigh ...
Kerr-Mudd,John
2020-12-30 12:46:50 UTC
Permalink
On Wed, 30 Dec 2020 10:18:28 GMT, Rod Pemberton
Post by Rod Pemberton
On Tue, 29 Dec 2020 02:26:42 -0800
Post by bilsch01
test al,al sets ZF only if al = 0
http://qcd.phys.cmu.edu/QCDcluster/intel/vtune/reference/About_IA-32_In
structions.htm
That's a browse-able HTML version of an IA-32 manual.
or elsewhere
https://reverseengineering.stackexchange.com/questions/25188/what-does-
test-al-al-mean

Yes. But why do that if you want to test if al=0? far clearer to code
"cmp al,0"

but is cy set identically? back at the OP!
--
Bah, and indeed, Humbug.
Terje Mathisen
2020-12-30 18:12:37 UTC
Permalink
Post by Kerr-Mudd,John
On Wed, 30 Dec 2020 10:18:28 GMT, Rod Pemberton
Post by Rod Pemberton
On Tue, 29 Dec 2020 02:26:42 -0800
Post by bilsch01
test al,al sets ZF only if al = 0
http://qcd.phys.cmu.edu/QCDcluster/intel/vtune/reference/About_IA-32_In
structions.htm
That's a browse-able HTML version of an IA-32 manual.
or elsewhere
https://reverseengineering.stackexchange.com/questions/25188/what-does-
test-al-al-mean
Yes. But why do that if you want to test if al=0? far clearer to code
"cmp al,0"
but is cy set identically? back at the OP!
CMP AX,0 is longer than TEST AX,AX but I'm not sure if the same is true
for CMP AL,0? I.e. is there a one-byte form of CMP AL with a one-byte
immediate?

Terje
--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
Kerr-Mudd,John
2020-12-30 19:58:19 UTC
Permalink
On Wed, 30 Dec 2020 18:12:37 GMT, Terje Mathisen
Post by Terje Mathisen
Post by Kerr-Mudd,John
On Wed, 30 Dec 2020 10:18:28 GMT, Rod Pemberton
Post by Rod Pemberton
On Tue, 29 Dec 2020 02:26:42 -0800
Post by bilsch01
test al,al sets ZF only if al = 0
http://qcd.phys.cmu.edu/QCDcluster/intel/vtune/reference/About_IA-32
_In
Post by Terje Mathisen
Post by Kerr-Mudd,John
Post by Rod Pemberton
structions.htm
That's a browse-able HTML version of an IA-32 manual.
or elsewhere
https://reverseengineering.stackexchange.com/questions/25188/what-
does-
Post by Terje Mathisen
Post by Kerr-Mudd,John
test-al-al-mean
Yes. But why do that if you want to test if al=0? far clearer to code
"cmp al,0"
but is cy set identically? back at the OP!
CMP AX,0 is longer than TEST AX,AX but I'm not sure if the same is true
for CMP AL,0? I.e. is there a one-byte form of CMP AL with a one-byte
immediate?
Terje
Hugi tips & tricks snippet:


1. Test the value in AL

To test whether AL is 0 or 1, one single-byte instruction is enough:

aaa
jz @zero


I'm not claiming it's faster than "test".
--
Bah, and indeed, Humbug.
Kerr-Mudd,John
2020-12-31 11:30:12 UTC
Permalink
On Wed, 30 Dec 2020 19:58:19 GMT, "Kerr-Mudd,John"
Post by Kerr-Mudd,John
On Wed, 30 Dec 2020 18:12:37 GMT, Terje Mathisen
[]
Post by Kerr-Mudd,John
Post by Terje Mathisen
for CMP AL,0? I.e. is there a one-byte form of CMP AL with a one-byte
immediate?
Terje
1. Test the value in AL
aaa
I'm not claiming it's faster than "test".
Oops; also jumps if AL is 0x0A
--
Bah, and indeed, Humbug.
bilsch01
2020-12-30 18:46:46 UTC
Permalink
Post by Rod Pemberton
On Tue, 29 Dec 2020 02:26:42 -0800
Post by bilsch01
test al,al sets ZF only if al = 0
http://qcd.phys.cmu.edu/QCDcluster/intel/vtune/reference/About_IA-32_Instructions.htm
That's a browse-able HTML version of an IA-32 manual.
I've been using this one.

http://www.felixcloutier.com/x86/

I couldn't believe what I read.
The ref you provide is no more help to me.

I found the following, which I recognize - answered my question.

00000102 BEC87D mov si,0x7dc8 ;msg: Error.
00000105 AC lodsb
00000106 84C0 test al,al
00000108 74FC jz 0x106
0000010A B40E mov ah,0xe
0000010C B307 mov bl,0x7
0000010E CD10 int 0x10
00000110 EBF3 jmp short 0x105

Consider this: Why not just answer the question that was asked?
bilsch01
2020-12-30 20:59:14 UTC
Permalink
Post by bilsch01
Post by Rod Pemberton
On Tue, 29 Dec 2020 02:26:42 -0800
Post by bilsch01
test al,al sets ZF only if al = 0
http://qcd.phys.cmu.edu/QCDcluster/intel/vtune/reference/About_IA-32_Instructions.htm
That's a browse-able HTML version of an IA-32 manual.
I've been using this one.
http://www.felixcloutier.com/x86/
I couldn't believe what I read.
The ref you provide is no more help to me.
I found the following, which I recognize - answered my question.
00000102  BEC87D            mov si,0x7dc8  ;msg: Error.
00000105  AC                lodsb
00000106  84C0              test al,al
00000108  74FC              jz 0x106
0000010A  B40E              mov ah,0xe
0000010C  B307              mov bl,0x7
0000010E  CD10              int 0x10
00000110  EBF3              jmp short 0x105
Consider this: Why not just answer the question that was asked?
Thanks for your post. Bill S.
Frank Kotler
2020-12-30 23:39:51 UTC
Permalink
On 12/30/2020 03:59 PM, bilsch01 wrote:

...
Thanks for your post.   Bill S.
That's more like it!

Thanks for your question and welcome to clax86.

Best,
Frank
[moderator]
Rod Pemberton
2020-12-31 09:10:52 UTC
Permalink
On Wed, 30 Dec 2020 10:46:46 -0800
Post by bilsch01
The ref you provide is no more help to me.
So, you didn't like the RTFM with a link to the actual manual? ...
Post by bilsch01
Consider this: Why not just answer the question that was asked?
Consider this: What would you learn from any of us simply giving you
the answer? ...

If you didn't understand the explanation in the manual, you could have
easily written some x86 code to test all 256 values for AL.

--
Bernhard Schornak
2020-12-30 13:45:22 UTC
Permalink
Post by bilsch01
test al,al sets ZF only if al = 0
TIA.   Bill S.
testb %al, %al

internally performs

andb %al, %al

without writing the result to the destination. Hence,

andb %al, %al

sets ZF if %al is zero. in all other cases, ZF is cleared. PF and
SF are set according to %al's content. CF and OF are set to zero,
no matter, what %al currently holds.

"AMD64 Architecture Programmer’s Manual Volume 3: General-Purpose
and System Instructions" [PDF 24594, page 342]


Greetings from Augburg

Bernhard Schornak
Loading...