flat assembler
Message board for the users of flat assembler.

Index > Main > gmp help plz

Author
Thread Post new topic Reply to topic
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 14 Oct 2011, 21:30
Hi,

Just tried to start using gmp, thanks to goldenspider for this.

Can't get the simplest things working though Sad

Quote:
Function: void mpz_set (mpz_t rop, mpz_t op)


my code
Code:
     cinvoke mpz_init, i
     cinvoke mpz_set, i, [num]
section '.data' data readable writeable
     i          mpz_t
     num     mpz_t 34     ;tried this as dd as well, no difference

    


This doesn't return to the correct place. The mpz_init works fine and returns but the mpz_set disappears into the ether. The reason I was doing this in 2 steps is the same thing was happening with cinvoke mpz_init_set, i, [num]

Any idea what I'm doing wrong?

thx
Post 14 Oct 2011, 21:30
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1389
Location: Piraeus, Greece
Picnic 14 Oct 2011, 22:19
Hi,

I never used GMP, but i saw the integer functions 4.1: 5 and play a bit.
This works fine on my pc, outputs: 18446744073709551615
Code:
section '.text' code readable executable
start:
     cinvoke mpz_init, t1
     cinvoke mpz_init, t2
     cinvoke mpz_set_str, t2, big, 16
     cinvoke mpz_set, t1, t2
     cinvoke mpz_get_str, buff, 10, t1
     cinvoke printf, buff
     cinvoke mpz_clear, t1
     cinvoke mpz_clear, t2
     ;
     ;

section '.data' data readable writeable

     t1 mpz_t
     t2 mpz_t
     big db "FFFFFFFFFFFFFFFF",0
     buff rb 1024
    


To load a signed long int i used mpz_set_si
Code:
     cinvoke mpz_set_si, t1, [dval]
    
Post 14 Oct 2011, 22:19
View user's profile Send private message Visit poster's website Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 14 Oct 2011, 23:15
Thanks for the quick reply Wink


Picnic wrote:

cinvoke mpz_set_str, t2, big, 16
section '.data' data readable writeable
big db "FFFFFFFFFFFFFFFF",0



Sorry, feeling very blond here. I have to set the number as a string first?

magicĀ²
Post 14 Oct 2011, 23:15
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1389
Location: Piraeus, Greece
Picnic 15 Oct 2011, 00:22
You're welcome magicSqr.

Depends, i see there are plenty of funtions.
I tested an addition, a dword in a big number, success!
I have to practise the lib to be more helpful.

Code:
     cinvoke mpz_set_ui, t1, [dval]             ; load an unsigned long int
     cinvoke mpz_init_set_str, t2, big, 16      ; initialize & set big number

     cinvoke mpz_add, t3, t2, t1
    


Code:
     t1 mpz_t
     t2 mpz_t
     t3 mpz_t
     dval dd 4294967295
     big db "FFFFFFFFFFFFFFFF",0
    
Post 15 Oct 2011, 00:22
View user's profile Send private message Visit poster's website Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 15 Oct 2011, 10:15
Thanks for the kick-start Wink

Think I'm getting there now Very Happy

Code:
format PE console
entry start

include '%fasminc%\win32a.inc'

struct MP_INT
     _mp_alloc  dd ?
     _mp_size   dd ?
     _mp_d      dd ?
ends

mpz_t fix MP_INT
;---------------------------------------------
section '.text' code readable executable
  start:

        cinvoke mpz_init_set_ui, t1, [x]
        cinvoke mpz_init_set_ui, t2, [y]
        cinvoke mpz_init, t3
        cinvoke mpz_cdiv_q, t3, t2, t1          ;(mpz_t quotient, mpz_t number, mpz_t divisor)
                                                ;if t1 or t2 weren't needed after the division
                                                ;they could be used for the quotient
        cinvoke gmp_printf, szFmt, t2, t1, t3
        cinvoke system, szPause
        ret

;---------------------------------------------
section '.data' data readable writeable

     t1         mpz_t
     t2         mpz_t
     t3         mpz_t
     x          dd 47
     y          dd 7473
     szFmt      db '%Zd / %Zd = %Zd',0ah,0
     szPause    db 'pause',0
;---------------------------------------------
section '.idata' import data readable writeable
  library libgmp,'libgmp-3.dll',\
     msvcrt,'msvcrt.dll'

  import libgmp,\
     mpz_init,'__gmpz_init',\
     mpz_init_set_ui,'__gmpz_init_set_ui',\
     mpz_cdiv_q, '__gmpz_cdiv_q',\
     gmp_printf,'__gmp_printf'

  import msvcrt,\
     printf,'printf',\
     system,'system'
    


magicĀ²
Post 15 Oct 2011, 10:15
View user's profile Send private message 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.