Author Topic: How to output 128 bits to the screen?  (Read 18688 times)

Mikl__

  • Member
  • *****
  • Posts: 1345
How to output 128 bits to the screen?
« on: July 19, 2017, 10:51:33 PM »
Hi, All!
If I need to output 64-bits float to the screen, I do so
Code: [Select]
; CONSOLE #
include win64a.inc
include msvcrt.inc
includelib msvcrt.lib
.data
pi  dq 3.14159265358979323846264338327
textformat db "hello, %.16llf!",0
.code
WinMain proc
sub rsp,28h
lea rcx,textformat
mov rdx,pi
call printf
xor rax,rax
add rsp,28h
ret
WinMain endp
end
What should I do to output 128-bits float to the screen? Thanks...

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #1 on: July 19, 2017, 10:56:47 PM »

Mikl__

  • Member
  • *****
  • Posts: 1345
Re: How to output 128 bits to the screen?
« Reply #2 on: July 19, 2017, 11:09:30 PM »
Ciao, jj2007! Come stai?
I do not need an exact calculation of the Pi number, but I need an example of using format string for prints and  xmm-registers...

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #3 on: July 19, 2017, 11:27:24 PM »
Display with "normal" code ends with Real10 precision:
Code: [Select]
include \masm32\MasmBasic\MasmBasic.inc
  Init
  fldpi
  Inkey Str$("PI=%Jf", ST(0)v) ; PI=3.141592653589793238
EndOfCode

Everything beyond needs special libraries, like Dave's Ling Long Kai Fang Bignum library. Rumours say Drizz also has one.

If you want to see C/C++/G++ coders fighting with 128-bit windmills, check
how to print __uint128_t number using gcc?
or
How to print __int128 in g++?

Of course, you can always use hex representation:
Code: [Select]
My128Bits xmmword 1111111111abcdef2222222222abcdefh
  movups xmm0, My128Bits
  deb 4, "Test", x:xmm0

Output: Test    x:xmm0          11111111 11ABCDEF 22222222 22ABCDEF

nidud

  • Member
  • *****
  • Posts: 2388
    • https://github.com/nidud/asmc
Re: How to output 128 bits to the screen?
« Reply #4 on: July 20, 2017, 12:47:15 AM »
Code: [Select]
    movq pi,xmm0

aw27

  • Guest
Re: How to output 128 bits to the screen?
« Reply #5 on: July 20, 2017, 02:45:12 AM »
Another alternative:

Code: [Select]
; x64
;uasm64 -win64 -Zp8 -c p128.asm

.xmm
option casemap:none
option frame:auto

includelib \masm32\lib64\msvcrt.lib
printf proto :ptr, :vararg

_DOUBLESTOXMM MACRO par1, par2
Local xmmValue
  .const
  align 16
  xmmValue REAL8 par1, par2
  .code
  exitm <xmmValue>
ENDM

.data
format db "Results: %.16llf, %.16llf",13,10,0

.code

main proc
       ;sub rsp, 8 by uasm
sub rsp, 20h
movaps xmm0, XMMWORD ptr _DOUBLESTOXMM(3.14159265358979323846264338327, -6.28318530717958647692528676654)

movq r8, xmm0 ; Note: ML64 does not accept movq, it is a know bug. But it accepts movd and converts it to movq. Weird
  shufpd xmm0, xmm0, 1
movq rdx, xmm0
mov rcx, offset format
call printf

add rsp, 20h
ret
main endp

end


Results: -6.2831853071795862, 3.1415926535897931

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #6 on: July 20, 2017, 05:12:49 AM »
What should I do to output 128-bits float to the screen?

aw27

  • Guest
Re: How to output 128 bits to the screen?
« Reply #7 on: July 20, 2017, 05:29:12 AM »
What should I do to output 128-bits float to the screen?

Are you telling that you printed a float?  :badgrin:


jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #8 on: July 20, 2017, 08:07:47 AM »
Yes, I printed a float: PI=3.141592653589793238

But that is "only" an 80 bit float. OP wants 128 bits, and that is not possible with "normal" code. You need a bignum library.

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: How to output 128 bits to the screen?
« Reply #9 on: July 20, 2017, 08:36:00 AM »
Yes, I printed a float: PI=3.141592653589793238

But that is "only" an 80 bit float. OP wants 128 bits, and that is not possible with "normal" code. You need a bignum library.
             Yes it seems Mikl__ wants a 128 bits converter. But if there is one BIGNUM library then it
has the converter. Where to see it Jochen (but i dont want it) ? And what is a bignum library, what it does ?
Does it real128 * real128 = real128 ? What is the format ? (real128 means any real with 128 bits in the same way real80 is the same as REAL10- 10 bytes)
 :t

aw27

  • Guest
Re: How to output 128 bits to the screen?
« Reply #10 on: July 20, 2017, 03:05:40 PM »
Yes, I printed a float: PI=3.141592653589793238

But that is "only" an 80 bit float. OP wants 128 bits, and that is not possible with "normal" code. You need a bignum library.

Of course, it is not possible without a bignum library.
And he asked for "an example of using format string for prints and  xmm-register".
So what comes closer to what he wants, in the realm of possibilities, is what I did.
I also did it in Assembly Language, which this forum is all about.

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #11 on: July 20, 2017, 04:39:32 PM »
I also did it in Assembly Language, which this forum is all about.

Code: [Select]
call printf
 :t

aw27

  • Guest
Re: How to output 128 bits to the screen?
« Reply #12 on: July 20, 2017, 04:53:54 PM »
Code: [Select]
call printf :t
You do the same, or equivalent, hidden in the middle of obscure code supported by undocumented libs you developed (MasmBasic, JBasic.*).
That way, I can only expect newbies to learn ASM when pigs can fly.  :badgrin:

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #13 on: July 20, 2017, 05:10:13 PM »
We are doing almost the same. The difference is that I am not pretending to solve the problem, I just demonstrate that it is NOT possible, and I do it using a library that is written 100% in assembly, developed here in this forum by many members, without even a trace of C code. And I really don't understand why this turns into a pissing contest, José. If you want to be constructive, start a bignum library thread in the Laboratory. That could be interesting indeed.

aw27

  • Guest
Re: How to output 128 bits to the screen?
« Reply #14 on: July 20, 2017, 05:26:34 PM »
If you want to be constructive, start a bignum library thread in the Laboratory. That could be interesting indeed.
In my opinion there are already enough BigNum libraries out there. Probably the best one for Windows, is the MPIR, which is written partially in YASM. I used it to do a freeware I published called Googol+