News:

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

how to represent long numbers??

Started by Metatrion, February 26, 2010, 12:24:27 PM

Previous topic - Next topic

Metatrion

Hi everyone im trying to program a compiler of a language for the university and i need represent 4 types: int long double and float. int and float in 32 bits its ok but long and double of 64 im no sure how to do it. I think that double of 64 must be done with the fpu and his registers on stack but the long in 64 i dont know :(.

I try to use te macro a2sq to convert an ascii string to integer of 64 bits but i dont know how this macro return the data. It says that return the address of data but when i want to see in the screen with sqword$ it says that it is not a sqword.

My actual code for that is this:

lea eax, long                   ;take address of the var long declared in .data
mov edi,a2sq(eax)           ;convert to long
;mov edi,qword ptr [edi]  ;fails it says invalid instruction operand
print sqword$(edi),13,10  ;finally it fails. shows the "half" number in bits (the first 32 bits but stacked)

i have tried to search in this forum but i havent found anything about this :(.

thanks in advance and sorry for my english im spanish and i dont know a lot about masm32.









Slugsnack

i am assuming you are programming for x86 32 bit platform. in this case, the longs are qwords. which can be declared in .data/.data? just as you would with other types. however because your registers are limited at 32 bits, you can only move it in half by half.

this page gives some info on qword arithmetic :
http://webster.cs.ucr.edu/AoA/Windows/HTML/AdvancedArithmetic.html

it is in hla but is easily adaptable for masm32. it surprises me that your university would ask you to code for masm32 and not nasm or something else though

you can print a qword as follows:
include \masm32\include\masm32rt.inc

.data

examp   qword   -4564564654654

.code
start:

print sqword$(examp), 13, 10
inkey
exit

end start


for your fpu, masm32 includes a very nice fpu library by raymond. are you allowed to use that ? again.. i do find it very strange that they are allowing you to use masm32 including its macros. not only is portability severely compromised, but also your fundamental understanding of this particular architecture. imo, it sort of defeats the purpose of asking you to code your own compiler if you are allowed to use built in macros in your code generation..

btw "mov edi,qword ptr [edi]" fails because you are attempting to move a 64 bit value into a 32 bit register

Astro

Hi,

64-bit numbers can be represented as two 32-bit DWORDS. You can use REAL8 and REAL10 for large floating point numbers, but they usually only directly manipulated by the FPU (though you can read/write them with the CPU if you wish, as normal).

REAL8 is 64-bit.
REAL10 is 80-bit.

Refer to the MASM help file: opcodes.chm (masm32/help directory). It contains the most often used op-codes, and everything you need to get started with the instruction set. It is also strongly recommended to get the document Intel Architecture Software Developer's Manual, Volume 2: Instruction Set Reference Manual as well as Volume 1 and 3 (also available via the link) in order to better understand the architecture.

You might also find it beneficial to study Iczelion's Tutorials to get a better understanding of both MASM programming, assembler in general, and programming for Windows.

Welcome to the forum, and good luck!  :U

Best regards,
Robin.

Metatrion

thanks a lot i will read this web and the reason to take masm32 is only mine lol. My project is to translate a high level program language to an exe in x86 under windows or linux. I dont have limitations and i have been searching about this and i found masm32 with lots of macros and functions and i think that its easy.

thanks astro i have that documentation full here and i have readed lot of it i will see too that tutorials.

thanks for the fast posts!!

i have found a form to operate an show my numbers when i compile ^^



include \masm32\include\masm32rt.inc

.data

entero_largo   qword   -4564564654654

.code
start:


print sqword$(entero_largo),13,10

lea eax,entero_largo

mov ebx,[eax]
mov ecx,[eax+4]

;represents 100
mov ebx,0
mov ecx,100

mov [eax],ecx
mov [eax+4],ebx

print sqword$(entero_largo),13,10

inkey
exit

end start




the trick is to have an quad always in memory and when i want to show i change it like in that example. I dont know why i cant reference a quad in memory with a single 32 bits register. If the address IS ALWAYS 32 bits why not? i dont know but with this i can try to translate the operations to long :). Cut a long in 2 registers in that form would be easy. I think that if i pass my long to binary thanks to Long class in java, i cut the binary string in 2 and translate the 2 parts to int and i can use that algorithm.

I have did something similar with a PIC16F84 with only 8 bits of word :(. Try to imagine do floating operations without IEE-754 implementation XDD it was a madness and to operations with integers of 16 bits i did the operations in 2 pass. First the operation with 2 registers and second with the others with the carry produces in first operation. this is very very similar to it.

thanks a lot Slugsnack yo have give me the solution :)