I pondered this out of curiosity too much so I'll go ahead and ask for any other ideas. The best I've thought up was to copy the stack pointer such as mov eax,esp.
How about this:
stc
setc al
And of course there is always mov al, 1.
How about:
or eax, 1
lahf
I am not sure if there is a condition that will have all the flags zero at one time.
If you have not cleared EBX, try XLATB
If you know the register is zero, you could use the 1-byte instruction inc reg.
I think lahf is safe.
xor eax, eax ; clear eax
sahf ; load AX into flags
lahf ; load flags into AX
fn MessageBox,hWnd,str$(eax),"Title",MB_OK
Thanks for the replies. My goal originally was to find the smallest way to unzero a register in sort of the opposite to how xor eax,eax zero's a register. Obviously it would be some sort of operation that involves registers only and since the stack pointer is rarely ever zero it seemed to make the most sense to use.
Read the xor part of http://www.win32asmcommunity.net/phpwiki/index.php/BitOperations
lahf is 1 byte which is half of 2 bytes.
Quotelahf is 1 byte which is half of 2 bytes.
But it can only work on the EAX (AH) register. You can't use it for un-zeroing other registers.
I always use
or reg,1Raymond
Why would you want to unzero a register?
QuoteWhy would you want to unzero a register?
One example would be to indicate success or failure when returning from a proc. With HLLs, you can generally use only EAX for returning something. In assembly, you can use any register. In some cases, it may be usefull to return a value in one register and the success/failure code in another.
Raymond
Quote from: AeroASM on April 23, 2005, 05:34:38 PM
Why would you want to unzero a register?
Thanks for the replies.
I use it with the
xchg flag, ecx instruction to both unzero a thread synchronization flag and to check if the flag was zero.
While it's not directly related to the question asked, since we're talking about return values, I feel it may be worth mentioning the SALC (D6h) instruction which sets AL to FFh if the CF is set or AL to 0h if it's not.
regards,
-Brent
Quote from: Alloy on April 24, 2005, 11:05:47 AM
I use it with the xchg flag, ecx instruction to both unzero a thread synchronization flag and to check if the flag was zero.
Just thought I'd mention the BTS instruction - which is designed for this purpose.