News:

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

Signed Byte

Started by jckl, May 01, 2007, 02:26:29 AM

Previous topic - Next topic

jckl

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.

GregL

jckl,

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


jckl

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.

GregL

jckl,

You could do it like this too.


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



jckl

ok cool thanks.. i need to learn more opcodes..

asmfan

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/
Russia is a weird place

hutch--

The alternative is to actually know how MASM pseudo high level code works.


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

jckl

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.