i am not sure what the above 2 do...here is an example code, and i am not sure what it means, cna someone give me an explanaion?

push pszHeading
pop lvc.pszText

also here is anyother piece of code:

invoke CreateFileMapping,hFile,0,PAGE_READWRITE,0,0,0
mov hFileMapping,eax
test eax, eax
jnz @f

the question is what does test eax,eaxt does here anyways?
i mean what is it;s point ehre since it will always return true?
Posted on 2004-09-03 11:05:24 by ReVeR
The coder wants to move data from memory to memory. However since there is no one opcode that can do that directly, the coder made use of the stack to move data.
Posted on 2004-09-03 11:10:14 by roticv
and how abotu the test ? what is the point of that?
it is sopoused to be error traping, if the return is not the one we want, then the jump doens't go through and error mesage comes up.....
why do we test eax,eax?
also can the movement of the data from mem to me be done with something like this(more liekely, why can it not be done this way):

mov lvc.pszText,pszHeading
Posted on 2004-09-03 11:22:03 by ReVeR
Test eax,eax sets Z when (EAX&EAX) is 0, that is, when EAX is 0. When EAX isn't 0, Z is cleared.

The PUSH/POP sequence should be avoided when you have a free register and the value to set is not an immediate value of WORD or DWORD size that is between -128 and 127, since the corresponding MOV sequence will be faster, and at least as small as the PUSH/POP.
Posted on 2004-09-03 11:22:13 by Sephiroth3
what is z?
indecator of the value being a zero or what?
Posted on 2004-09-03 11:25:28 by ReVeR
mov lvc.pszText,pszHeading

This is an invalid instruction on x86 CPUs. They don't have memory to memory moves (with the exception of the string instructions). So you need to first "load" the operand with 1 instruction, then "store" it with another instruction.

In your example, the stack is used as a temporary work area. Another option is to use a register, like this:

mov eax,pszHeading
mov lvc.pszText,eax

Posted on 2004-09-03 12:00:09 by S/390
but isn;t stack jsut another part of the memory? yherefore what is the diffrence betwwen moving the data between 1 variable to seocnd and to stack then from stack?
i though stack was just allocated part of the mem...where have i gone wrong?
Posted on 2004-09-03 13:17:19 by ReVeR
Instruction encoding.

An arbitrary memory-to-memory move requires explicit encoding of two addresses. A stack operation (PUSH, POP) only requires encoding of one address. Note that the string instruction MOVS severely restricts addressing modes so that it does not need to have any instruction bits dedicated to addressing.

The IA-32 architecture supports only one explicit address. To get a better view of this design choice, study how each instruction and each addressing mode are encoded into bit patterns.
Posted on 2004-09-03 16:33:02 by tenkey
what is z?
indecator of the value being a zero or what?

There's a special purpose register called EFLAGS, some instructions (like TEST) will set or clear some bits of it indicating some aspects of the result (for example, the zero bit means the result was zero). The conditional jump instructions (Jxx) set a branch in the code, based on the status of this flags: for example, JZ will jump to the given location if the zero bit of the EFLAGS register is set, or do nothing if the bit is clear.

The coder has set an error trap there. When the result of the call to CreateFileMapping was zero, the error routine is executed. If not, the program goes on as normal.

Hope that helps :)
Posted on 2004-09-03 19:24:37 by QvasiModo

There is no opcode on x86 hardware that will do the memory to memory copy so you either use the stack with PUSH / POP or you use a register if you have one available.

The code using TEST is to determine if the register holds the value ZERO or not and this is shown by the JNZ instruction after it. You can use CMP REG, 0 as well but its slower on most later hardware.

What happens is if the register is zero, test sets the ZERO flag and the JNZ instruction will not jump to the label. You can use the alternate choice with the instruction JZ which means jump if the register is ZERO.

It would be a good idea if you downloaded the Intel manuals from their website as they have the complete reference for all of the instructions there.


hutch at movsd dot com
Posted on 2004-09-03 20:41:54 by hutch--
You should avoid the push/pop way of doing memory to memory and use a register instead, since it's faster. It doesn't really matter for this type of code, but the push/pop way of donig memory to memory transfers "is a bad mindset".
Posted on 2004-09-04 01:06:07 by f0dder
Test is an and instruction without results being placed in accumulator. It will give same flag results as "and"
Posted on 2004-09-04 01:57:20 by mrgone
thx, for ur answers, i finally got it.
appriciate ur time
Posted on 2004-09-04 02:08:37 by ReVeR
Decided not to make a new thread, but to post int his one...what does xor do?
exxample of code:
what is the function of xor?
Posted on 2004-09-04 02:29:14 by ReVeR
Xor sets bits if they differ from the source operand, and clears them if they're equal. In other words, it toggles every bit when the corresponding source bit is one.
Posted on 2004-09-04 05:37:38 by Sephiroth3
i am not sure i understood ur correctly....
u said, that xor basicly sets the valeus of both of my operands to the same if they are diffrent, and if they ar teh same it sets them to 0?
is that what u meant?
sry, but i am rather newbish....
if i am right, then to what operand is the other one set if they are diffrent, the first one or the second one?
Posted on 2004-09-04 12:00:19 by ReVeR
No, it sets the bits in the first operand when they're different, and clears them when they're equal. It does not change the second operand.
Posted on 2004-09-04 12:09:41 by Sephiroth3
ok, so if the operands are diffrent then the first operand is set to the value of secodn?
sry but i don't get the sets the bits of the first operand....sets them to the value of the second one, right?
and when u say clrea them, what will they be equal, 0?
Posted on 2004-09-04 20:41:24 by ReVeR
Almost, well, when I said that it sets them, I mean that it asserts them.
Oh nevermind, just use this table:
Src: 0 1 0 1

Dst: 0 0 1 1
Res: 0 1 1 0
Posted on 2004-09-05 02:01:21 by Sephiroth3
Hey ReVeR,

Google for "The Art of Assembly" if you wish to learn about Opcodes (xor,text,or,and,mul,imul.... lots of them) but the basics are covered. For more complex Opcodes read the CPU manufactor's Documentation that can be retrieved via their site.

Link to some Opcodes from the Art of Assembly:
Posted on 2004-09-05 06:25:41 by Black iCE