flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > FASMG: question about lengthof operator

Author
Thread Post new topic Reply to topic
fabbel



Joined: 30 Oct 2012
Posts: 84
fabbel 27 Mar 2024, 14:42
Hi Tomasz,

quick / small question reg. FASMG lengthof operator :
if I do e.g.
Code:
LEN = lengthof 0x0FF
    

-> i get LEN = 2, despite value obviously being 1-byte only
.. and similar behavior - i.e. byte lentgh +1 - for any value with sign bit set: 0x80, 0x9000, ...


Is this this intended / on purpose ? ... so need to reimplement some 'byte length' operator then ?
Post 27 Mar 2024, 14:42
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 27 Mar 2024, 15:26
The LENGHTOF is only defined for string values, and when you use it with another kind of value, it is implicitly converted to string first, so "lengthof 0xFF" is the same as "lengthof string 0xFF".
If you test this:
Code:
db string 0xFF    
you can see that the value is converted into a 2-byte string. That's because fasmg always treats the numbers as sign-extended, little endian with arbitrary length (so it's the highest bit of the last byte that needs to be equal to the sign):
Code:
db string -1        ; 1 byte
db string 0xFF      ; 2 bytes
db string -8000h    ; 2 bytes
db string 8000h     ; 3 bytes    
Also if you convert a string back into a number, it is interpreted as a sign-extended value.
Post 27 Mar 2024, 15:26
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.