flat assembler
Message board for the users of flat assembler.

Index > Heap > Leibniz Pi program in Alpha Assembly

Author
Thread Post new topic Reply to topic
mattst88



Joined: 12 May 2006
Posts: 260
Location: South Carolina
mattst88
The Leibniz Pi algorithm is an algorithm I've written in many different languages, and I have learned a quite a bit from it.

Wikipedia article: http://en.wikipedia.org/wiki/Leibniz_formula_for_pi

My leibniz code (C, x86 FPU, SSE3) is here: http://mattst88.com/programming/?page=leibniz

Since I've got an Alpha, I figured I'd study RISC programming and write the leibniz algorithm in alpha assembly. So here it is, if anyone is interested whatsoever.

By the way, here's a page about my Alphaserver DS20L. http://mattst88.com/ds20l/

(GAS Syntax)

Code:
STACK = 1
FRAME = ((STACK*8+8)/16)*16

.data
F_ONE:    .t_floating     1.0
COUNT:       .quad           100000000
ONE:   .quad           1
PRINT: .ascii          "1/%.0f - %19.17f\n"

.text
        .align  4
   .set    noreorder
   .arch   ev6
 .globl  main
        .ent    main

main:   ldgp    $gp,0($27)
  lda     $sp,-FRAME($sp)
     stq     $26,0($sp)
  .mask   0x04000000,-FRAME
   .frame  $sp,FRAME,$26,0
     .prologue 1
 .globl  first
first:     ldt     $f2,F_ONE               # $f2 num = 1.0
     cpyse   $f2,$f2,$f3             # $f3 sum = 1.0
     ldq     $9,ONE                  # $9 = 1
    addt    $f2,$f2,$f4             # $f4 incrementor = 2.0
     ldq     $10,COUNT               # $10 = counter
     addt    $f4,$f3,$f5             # $f5 denom = 3.0
   mov     $10,$2                  # load counter into $2
      
    .align  4
loop:  cpysn   $f2,$f2,$f2             # num = -num
        divt    $f2,$f5,$f10            # temp = num / denom
        addt    $f3,$f10,$f3            # sum += temp
       addt    $f5,$f4,$f5             # denom += 2.0

  subq    $2,$9,$2                # counter -= 1

  bne     $2,loop                 # if counter == 0, loop

 lda     $16,PRINT               # load format string
        cpyse   $f5,$f5,$f17            # $f17 = denom
      cpyse   $f3,$f3,$f18            # $f18 = sum
        jsr     $26,printf              # call printf
       ldgp    $gp,0($26)              # reload global pointer

 mov     $10,$2                  # reset counter
     br      $31,loop                # loop back to top unconditionally

done:     mov     $31,$0                  # return val = 0
    ldq     $26,0($sp)
  lda     $sp,FRAME($sp)
      ret     $31,($26),1             # return
    .end    main    

_________________
My x86 Instruction Reference -- includes SSE, SSE2, SSE3, SSSE3, SSE4 instructions.
Assembly Programmer's Journal
Post 26 Apr 2008, 00:51
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
When will we see fasmalpha? Razz
Post 26 Apr 2008, 01:12
View user's profile Send private message Visit poster's website Reply with quote
mattst88



Joined: 12 May 2006
Posts: 260
Location: South Carolina
mattst88
revolution wrote:
When will we see fasmalpha? Razz


I've thought about that!

I don't know the FASM internals that well, so there'd be a significant learning curve. I assume if I ever do attempt to do it, I could use your FASMARM as a base though, right?

_________________
My x86 Instruction Reference -- includes SSE, SSE2, SSE3, SSSE3, SSE4 instructions.
Assembly Programmer's Journal
Post 26 Apr 2008, 01:15
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
mattst88 wrote:
I assume if I ever do attempt to do it, I could use your FASMARM as a base though, right?
Sure, that would be good. It would be nice not to have to see the ugly GAS syntax.
Post 26 Apr 2008, 01:46
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
matts88: You actually posted your site in the Wikipedia article. Wow. Nice code though.
Post 26 Apr 2008, 02:49
View user's profile Send private message Visit poster's website Reply with quote
mattst88



Joined: 12 May 2006
Posts: 260
Location: South Carolina
mattst88
AlexP wrote:
matts88: You actually posted your site in the Wikipedia article.


Very true. I figure it's quite relevant though.

_________________
My x86 Instruction Reference -- includes SSE, SSE2, SSE3, SSSE3, SSE4 instructions.
Assembly Programmer's Journal
Post 26 Apr 2008, 03:35
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2914
Location: [RSP+8*5]
bitRAKE
Mind if I add one?
Code:
mov ebx,0       ; sum
mov ebp,$170000 ; itterations/2
mov ecx,3       ; denominator

.0: mov edx,1
    mov eax,0
    div ecx
    add ecx,2
    sub ebx,eax

    mov edx,1
    mov eax,0
    div ecx
    add ecx,2
    add ebx,eax

    dec ebp
    jne .0    
...fixed point version. EBX ---> pi/4 * 2^32

There is a lot of rounding error, but lots of good bits too.

_________________
¯\(°_o)/¯ unlicense.org
Post 26 Apr 2008, 03:50
View user's profile Send private message Visit poster's website 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 can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.