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

test instruction

1 view
Skip to first unread message

Erlend J. Leiknes

unread,
Aug 24, 2001, 12:50:18 PM8/24/01
to
I wonder how the test and lea instruction work...
Ive seen a lot of:
test eax, eax
jne <address>

What does test do?

What would be best for me would be a complete x86 assembly instruction
textfile... which I havent found.

--

-- Erlend J. Leiknes (noo...@online.no)

NEVER eat more than you can lift.

Tim Robinson

unread,
Aug 24, 2001, 1:01:02 PM8/24/01
to
"Erlend J. Leiknes" <noo...@online.no> wrote in message
news:ICvh7.498$1T5....@news1.oke.nextra.no...

| I wonder how the test and lea instruction work...
| Ive seen a lot of:
| test eax, eax
| jne <address>
|
| What does test do?
|
| What would be best for me would be a complete x86 assembly instruction
| textfile... which I havent found.

It performs a "mental AND" on its two operands, and updates the flags as if
the operation took place. That is, it's the same as the AND operation, except
that it discards the result, and keeps the flags which might have been set.

This:

test reg, reg
jz <address>

...is a common way of testing whether reg is zero -- remember that (reg AND
reg = reg). je is a synonym for jz, and jne is a synonym for jnz. So can you
guess what the code you posted does?

As for x86 references, the ones I rely on are the one that comes with NASM,
and the 386intel.txt which seems to be floating around the internet.


cLIeNUX user

unread,
Aug 24, 2001, 3:37:38 PM8/24/01
to
humb...@smart.net

>I wonder how the test and lea instruction work...
>Ive seen a lot of:
>test eax, eax
>jne <address>
>
>What does test do?
>
>What would be best for me would be a complete x86 assembly instruction
>textfile... which I havent found.
>

http://ftp.unina.it/pub/docs/386htm/toc.htm

lea took me a while too. The Intel docs are pretty terse about it. lea is
an artifact of the 386 addressing modes. It does an address computation,
and then loads it's argument with the result of the computation. Because
it's just doing what the CPU does for any memory reference anyway, it's
only 2 clocks. Thus it can be as much as...

shift a register by 1, 2 or 4
add that to another register
add a literal to that
put the result in a chosen register

in 2 clocks. All 3 registers can be the same register, so you can do wierd
things like multiply by 9 in 2 clocks.

I was shown recently in comp.lang.forth by Gary Chanson how lea can be
really handy for implementing a stack pointer for a virtual machine stack
additional to the return stack, which Forth requires.

Rick Hohensee

Jerry Coffin

unread,
Aug 24, 2001, 7:46:10 PM8/24/01
to
In article <ICvh7.498$1T5....@news1.oke.nextra.no>, noo...@online.no
says...

> I wonder how the test and lea instruction work...
> Ive seen a lot of:
> test eax, eax
> jne <address>
>
> What does test do?

Test is a lot like cmp, except that it does and AND instead of a SUB.
The basic idea in both cases, however, is that you take two operands,
carry out an operation on them, but discard the result. The only
effect of a test or a cmp is to set flags based on the result.

Normally, test is used to see whether a particular set of bits in an
operand are set. For a rather silly example, you could test whether
a number is odd using test:

mov eax, number
test eax, 1
jnz its_odd

--
Later,
Jerry.

The Universe is a figment of its own imagination.

Erlend J. Leiknes

unread,
Aug 24, 2001, 8:39:09 PM8/24/01
to
but Ive seen MANY test eax,eax
you cannot check if its odd because I dont know what you AND the eax with...
its just...strange...

Jerry Coffin <jco...@taeus.com> wrote in message
news:MPG.15f094afa...@news.direcpc.com...

cLIeNUX user

unread,
Aug 24, 2001, 10:08:21 PM8/24/01
to
humb...@smart.net

>but Ive seen MANY test eax,eax
>you cannot check if its odd because I dont know what you AND the eax with...
>its just...strange...
>

That checks if it's zero or not. It's probably followed by a jz or jnz,
yes? And perhaps also, uh, parity, sign, but not carry or overflow.


HEY! Everybody take a 386 instruction and do a tutorial description! Beth
can start with NOP since she likes it terse :o)

Rick Hohensee

xby

unread,
Aug 26, 2001, 11:52:35 AM8/26/01
to
r@cLIeNUX. (cLIeNUX user) wrote in message news:<todb82d...@corp.supernews.com>...
The LEA instruction has been implemented ever since the 8086/8088.
It loads the offset to its operand but not the segment. It is
practical when the operand is pointed to by a register/displacement
combination, e.g.

LEA AX,[BX+SI].VARIABLE

places in AX the sum of the contents of BX plus the contents of SI
plus the offset to VARIABLE.

0 new messages