# PureBasic Forum

 It is currently Wed Jan 20, 2021 5:09 am

 All times are UTC + 1 hour

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Unsigned 32-bit integersPosted: Wed Nov 27, 2013 5:40 pm
 Enthusiast

Joined: Mon May 12, 2008 1:25 pm
Posts: 374
Location: The Netherlands
Hi there community!

I've been playing around with inline assembly more and more lately, and I've
been wondering; How can I perform several calculations in fASM and keep the
working variables unsigned? I don't care if the end result which will be returned
to PureBasic will be a signed integer, but how do I keep it all unsigned in ASM?

e.g. I'm reading a byte from a buffer, I always want it to be unsigned. Then, for
example, I would add this byte value to an int (let's say it's a hashing function),
how do I keep the int (EAX) unsigned throughout the calculations with common
arithmetic / bitwise operations? It's quite problematic when it comes to addition
and subtraction.

It could be something so obvious and I'm missing a world of simple facts here, but
I'd love some light being shed on my question.

Thanks all, have a nice day!

_________________

Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!

Top

 Post subject: Re: Unsigned 32-bit integersPosted: Wed Nov 27, 2013 6:10 pm
 PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
It depends on what functionality you need.
For a shift to the right for example, there's SHR (unsigned) and there's SAR (signed).
For multiplication, there's MUL (unsigned) and there's IMUL (signed).
For division, there's DIV (unsigned) and there's IDIV (signed).
When loading a smaller type (byte or word) into a 32 bit register, there's MOVZX (zero extended / unsigned) and there's MOVSX (sign extended / signed).
So to work with unsigned variables, you use different opcodes compared to the ones you use for signed variables.

Code:
!mov eax, [p.v_long]
!movsx ecx, byte [p.v_byte]
ProcedureReturn
EndProcedure

!mov eax, [p.v_long]
!movzx ecx, byte [p.v_byte]
ProcedureReturn
EndProcedure

_________________
macOS 10.15 Catalina, Windows 10

Top

 Post subject: Re: Unsigned 32-bit integersPosted: Wed Nov 27, 2013 7:27 pm
 Enthusiast

Joined: Mon May 12, 2008 1:25 pm
Posts: 374
Location: The Netherlands
Great, thanks for the info Wilbert! Now I know what to look for, I'll read
up on these instructions a bit more.

Cheers / een fijne avond nog!

_________________

Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - IDE    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite