Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

test al,al setting of ZF

19 views
Skip to first unread message

bilsch01

unread,
Dec 29, 2020, 4:10:40 PM12/29/20
to
True or False:
test al,al sets ZF only if al = 0

TIA. Bill S.

Rod Pemberton

unread,
Dec 30, 2020, 5:31:46 AM12/30/20
to
On Tue, 29 Dec 2020 02:26:42 -0800
bilsch01 <fy...@nospicedham.always.com> wrote:

> True or False:
> 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

unread,
Dec 30, 2020, 7:47:37 AM12/30/20
to
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.

Bernhard Schornak

unread,
Dec 30, 2020, 8:48:00 AM12/30/20
to
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

Terje Mathisen

unread,
Dec 30, 2020, 1:18:36 PM12/30/20
to
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"

bilsch01

unread,
Dec 30, 2020, 1:48:41 PM12/30/20
to
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?

Kerr-Mudd,John

unread,
Dec 30, 2020, 3:04:09 PM12/30/20
to
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".

bilsch01

unread,
Dec 30, 2020, 4:04:44 PM12/30/20
to
Thanks for your post. Bill S.

Frank Kotler

unread,
Dec 30, 2020, 6:46:17 PM12/30/20
to
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

unread,
Dec 31, 2020, 4:18:04 AM12/31/20
to
On Wed, 30 Dec 2020 10:46:46 -0800
bilsch01 <fy...@nospicedham.always.com> wrote:

> The ref you provide is no more help to me.

So, you didn't like the RTFM with a link to the actual manual? ...

> 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.

--

Kerr-Mudd,John

unread,
Dec 31, 2020, 6:33:16 AM12/31/20
to
On Wed, 30 Dec 2020 19:58:19 GMT, "Kerr-Mudd,John"
<nots...@nospicedham.127.0.0.1> wrote:

> On Wed, 30 Dec 2020 18:12:37 GMT, Terje Mathisen
> <terje.m...@nospicedham.tmsw.no> wrote:

[]

>> 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".
>

Oops; also jumps if AL is 0x0A
0 new messages