The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: jckl on May 01, 2007, 02:26:29 AM

Title: Signed Byte
Post by: jckl on May 01, 2007, 02:26:29 AM
I am reading a byte from a file and need to convert it to the signed ascii value. I tried to use all the baseascii functions i could find and also the dwtoa that are in the m32lib folder but none of them convert it to signed.

A6h = -90 signed and 166 unsigned

i need the signed value. Can anyone tell me what i need to do or show me how to do it.
Title: Re: Signed Byte
Post by: GregL on May 01, 2007, 02:40:51 AM
jckl,

Lookup the sbyte$ macro in the MASM32 High Level Reference help file (hlhelp.hlp) under C Runtime Conversions

Title: Re: Signed Byte
Post by: jckl on May 01, 2007, 03:15:57 AM
Nevermind i figured it out but thanks for the help greg.. it kind of led me in the right direction.

i used

.data
tsNum SBYTE 2 dup(0)

then i copy the 2 bytes from memory to tsNum and then used dwtoa and it works perfect.
Title: Re: Signed Byte
Post by: GregL on May 01, 2007, 05:00:18 AM
jckl,

You could do it like this too.


mov dl, 0A6h
movsx eax, dl    ; sign extend
INVOKE dwtoa, eax, ADDR szBuffer


Title: Re: Signed Byte
Post by: jckl on May 01, 2007, 05:14:33 AM
ok cool thanks.. i need to learn more opcodes..
Title: Re: Signed Byte
Post by: asmfan on May 01, 2007, 07:15:06 AM
the problem is when you use pseudo HLL in masm (.if .while...) with declared variables you maust not forget to write the S prefix to all data types that can be negative because compiler is not so clever to insert correct conditions (e.g. cond. jump) that for signed or for unsigned numbers specially (e.g. jb vs. jl, ja vs. jg...).
That's why HLL in masm is weird thing  :wink
/handmade forever/
Title: Re: Signed Byte
Post by: hutch-- on May 01, 2007, 07:59:39 AM
The alternative is to actually know how MASM pseudo high level code works.


.if SDWORD PTR eax == -16
  etc ....
Title: Re: Signed Byte
Post by: jckl on May 01, 2007, 09:44:19 PM
I havnt been using the high level format much but also wasnt awear that ja or jg is unsigned vs signed. Come to think about it i do remember seeing this in one of the help files I believe. I got lots of these little things to learn. I know what some things do but i dont know the technical or reasoning it does this for instance i didnt know the difference between mov al, [esi] and mov eax, [esi] until paul told me. I was confused on this because i can use mov al, [esi] and then add to eax and change whats in al. Now i understand the difference and have not needed help with little functions that i use this in which i would have before. Just that alone helped me understand a lot of stuff.