News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

unsigned long to long

Started by jckl, April 06, 2006, 04:10:13 AM

Previous topic - Next topic

jckl

I been searching how to convert an unsigned long to long but cant seem to get it working... Can anyone get me started or know how to do it?

jckl

nevermind i no longer need this..

hutch--

Jusat to add some confusion, there is no conversion needed when the value is in either a register or a memory operand as the storage of the value is neither signed or unsigned. What makes the difference is how you evaluate the value, you have signed or unsigned jumps, signed or unsigned extension and so on that draw the distinction for you.

About the only time in MASM that you need to make a pseudo high level data type is if you are using the high level syntax where it need to know the difference between a signed or unsigned value. In these contexts you use stuff like,

.if SDWORD PTR myvar == -1
  etc ....
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jckl

well like if i read 4 bytes from a file that in hex comes out as 7D 37 59 FE it will equal -27707523 as a signed long but equals 4267259773 as unsigned long..

first i was using this to convert to ascii and it was only coming up with the unsigned value.

    div Base
    add dl, 30h

Mincho Georgiev


                           mov eax,0FE59377dh
   cdq


Will give you -1 in edx. It means that you have negative value in eax!


Mark Jones

If this is useful, the sign bit can be "toggled":


    mov eax,0FE59377Dh
    and eax,07FFFFFFFh    ; strip off sign bit

    mov eax,07F59377Dh
    or  eax,080000000h    ; tack on sign bit

    and eax,080000000h
    cmp eax,080000000h
    jz SignBitSet         ; test sign bit
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

daydreamer

Quote from: Mark Jones on April 06, 2006, 03:28:35 PM
If this is useful, the sign bit can be "toggled":


    mov eax,0FE59377Dh
    and eax,07FFFFFFFh    ; strip off sign bit

    mov eax,07F59377Dh
    or  eax,080000000h    ; tack on sign bit

    and eax,080000000h
    cmp eax,080000000h
    jz SignBitSet         ; test sign bit

no it doesnt work that way, you need to 2complement(NEG) it to change sign, I already checked because I wanted to find a way to switch sign quickly in parallel code, with AND
instead I have to perform NOT followed by add 1 = NEG
and instead mask FF and 01, with pand and result from a packed comparision

jckl

i used neg to change sign also.

Ratch

 jckl,

Quote....unsigned long to long....

     Since this is the MASM forum, you should use MASM terminology, not that of C,C++.  The correct word is DWORD.

Quotei used neg to change sign also.

     NEG will not change the sign of zero. 

Mark Jones,

Quote    and eax,080000000h
    cmp eax,080000000h
    jz SignBitSet         ; test sign bit

     The following is more direct and does not change EAX.

  TEST EAX,EAX       ;if needed
  JZ xxxx                  ;test for zero if interested, because zero is neither positive or negative
  JS/JNS yyyy           ;test for sign/no sign

To all Interesteds,
     If all you want to do is toggle the sign, use XOR EAX,080000000H.  The result will not be the number multiplied by -1.  If you want to multiply a 1's complement number by -1, use NOT EAX.  This will flip all the bits of the number. If you want to multiply a 2's complement number (INTEL uses 2's complement)  by -1, use NEG EAX.  This will flip all the bits and add 1.  Ratch

     

Mark Jones

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

jckl

If there is no sign i skip the converion and if its a zero i dont run that on it.