flat assembler
Message board for the users of flat assembler.

Index > Main > which flags "test" updates?

Author
Thread Post new topic Reply to topic
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 20 Mar 2017, 17:43
This page https://flatassembler.net/docs.php?article=manual says:

>test performs the same action as the and instruction, but it does not alter the destination operand, only updates flags. Rules for the operands are the same as for the and instruction.

>and, or and xor instructions perform the standard logical operations. They update the SF, ZF and PF flags. Rules for the operands are the same as for the add instruction.

, but this page http://stackoverflow.com/questions/147173/x86-assembly-testl-eax-against-eax says:

>CF and OF cleared (AND/TEST always does that, and subtracting zero never produces a carry)

>ZF, SF and PF according to the value in EAX. (a = a&a = a-0)

So I guess, that's something to add in the fasm documentation?

I'm asking this because in the second link you can find this:

>It tests whether eax is 0, or above, or below.

But I'm not sure if it can test for "above" or "below", does it set enough flags for that? Also, is that a signed or unsigned comparasion?
Post 20 Mar 2017, 17:43
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 20 Mar 2017, 19:27
From Intel 64 manual:

Quote:

TEST—Logical Compare
. . .
Flags Affected
The OF and CF flags are set to 0. The SF, ZF, and PF flags are set according to the result. The state of the AF flag is undefined.


test above and below depend on CF (particularly, CF is set if below). Thus you cannot use TEST for this as it always clears Carry flag
Post 20 Mar 2017, 19:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 21 Mar 2017, 02:04
vivik: I suggest you download either the Intel Manuals, or the AMD manuals, or both. There are thousands of little details that the fasm manual doesn't cover. Without the source manuals you will be lost.
Post 21 Mar 2017, 02:04
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 21 Mar 2017, 05:40
@zhak
Thanks for clearing things out!

@revolution
>There are thousands of little details that the fasm manual doesn't cover.
Can I get some examples?
Post 21 Mar 2017, 05:40
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 670
system error 21 Mar 2017, 05:55
@vivik

FASM manual is a description about FASM - it describes mostly how it implements x86 instruction sets and how it may or may not differ from the ISA. So, FASM manual just goes a quick walkthrough of the entire instruction sets without bothering about the details. The technical details of such implementations are described in the Intel/AMD manuals instead.

For example, it could be that FASM implements a symbolic MOVTOREG to represent intel's <mov reg,source> instruction. Assembler's manual is used to explain such things.
Post 21 Mar 2017, 05:55
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 21 Mar 2017, 06:25
hm... fasm manual seems to be enough for practical needs, it's verbose just enough for me to understand.

Can you give me other details that may be important during assembly programming but are not mentioned in fasm manual?
Post 21 Mar 2017, 06:25
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 670
system error 21 Mar 2017, 06:38
vivik wrote:
hm... fasm manual seems to be enough for practical needs, it's verbose just enough for me to understand.

Can you give me other details that may be important during assembly programming but are not mentioned in fasm manual?


Example: not all instructions mentioned in FASM manuals come with explanations of the affected flags.

Example: there's no instruction mnemonics (which are important for debuggers, disassemblers)

We are lucky enough that FASM emulates all instructions as close as possible to the Intel/AMD definitions. In MASM for example, MOVQ is implemented differently than the Intel Manual. So assuming MOVQ of FASM and MOVQ of MASM behaves the same is wrong. That's the purpose of assembler's manual - to explain WHAT it implements and HOW they may differ.
Post 21 Mar 2017, 06:38
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 21 Mar 2017, 07:12
Always thought that MOV, AND, TEST actually are the mnemonics, was I wrong?
Post 21 Mar 2017, 07:12
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 670
system error 21 Mar 2017, 07:54
What I meant to say was encoding. I personally prefer the term SYMBOLS when referring to textual representations of instructions because it applies to all programming languages when it comes to syntax.
Post 21 Mar 2017, 07:54
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 21 Mar 2017, 08:12
Ok, I see. Thanks.
Post 21 Mar 2017, 08:12
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.