BBC BASIC for Windows
« Converting signed 64-bit int to signed 32-bit int »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:25pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Converting signed 64-bit int to signed 32-bit int  (Read 686 times)
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Converting signed 64-bit int to signed 32-bit int
« Thread started on: Jun 12th, 2009, 09:29am »

Okay, this is embarrassing.

I'm trying to implement the MOD operator as an ASM routine using the definition given in the BB4W docs:

A MOD B = A - ( A DIV B ) * B

For my purposes, A is a signed 32-bit integer (so it may be negative), and B is always a positive integer never greater than 16 bits.

Things are fine until one supplies a negative A, because I can't work out how to convert a signed 64-bit integer to a signed 32-bit integer (the absolute value of the signed 64-bit integer is assumed never to exceed 32 bits, or 31 bits, strictly speaking).

So, doing the A DIV B part, I've got:

Code:
; EAX = A,  EBX = B
xor edx, edx
idiv ebx 


How do I convert the possibly negative 64-bit value in EDX:EAX to a signed 32-bit value (again bearing in mind the absolute value in EDX:EAX doesn't exceed 32 bits)?

I did try using floating point instructions, but without success.


David.


User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Converting signed 64-bit int to signed 32-bit
« Reply #1 on: Jun 12th, 2009, 10:20am »

Quote:
How do I convert the possibly negative 64-bit value in EDX:EAX to a signed 32-bit value (again bearing in mind the absolute value in EDX:EAX doesn't exceed 32 bits)?

I don't understand the question. If the 64-bit integer value in EDX:EAX is within the range of a 32-bit (signed) number (i.e. -2147483648 to +2147483647) then no conversion is necessary: the answer is simply the value of EAX.

Am I missing some subtlety here?

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls