flat assembler
Message board for the users of flat assembler.

Index > DOS > Simple, yet flashy first FPU program!

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 25 Nov 2007, 20:10
I wrote a program which draws a spiral that wraps around on the screen. If you look closely you'll see a pattern.
Enjoy!


Description:
Download
Filename: FPUTest.zip
Filesize: 1.19 KB
Downloaded: 607 Time(s)

Post 25 Nov 2007, 20:10
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 25 Nov 2007, 20:13
Note: Try and follow the spiral from the center. It will really mess with your head. Wink
Post 25 Nov 2007, 20:13
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 25 Nov 2007, 20:47
Very Good Very Happy

Only some note:
Code:
pi dd 3.141592
         fimul [pi]             ;st0 = angle * pi    


You must use FMUL [pi] because pi is a float number
FIMUL is used with integer variable.
Post 25 Nov 2007, 20:47
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4046
Location: vpcmpistri
bitRAKE 25 Nov 2007, 21:35
Also, PI is an FPU constant: fldpi. Maybe the FPU stack is full? No other reason not to use the instruction, imho.
Post 25 Nov 2007, 21:35
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 25 Nov 2007, 21:41
PI is an FPU constant and nobody told me!? Shocked
That's awesome! XD

Thanks for the hints everyone
Post 25 Nov 2007, 21:41
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 25 Nov 2007, 22:11
Quote:
PI is an FPU constant and nobody told me!?
That's awesome! XD

Laughing
Post 25 Nov 2007, 22:11
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Nov 2007, 05:05
I fixed the two areas mentioned and I added bounds checking for the PSet function.
Post 26 Nov 2007, 05:05
View user's profile Send private message Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden 26 Nov 2007, 07:20
how to test cpu frequency...
Code:
ORG 100H                ; makes it a *.com file
USE16                  ; realmode model
FINIT                       ; initialize fpu

; note this program requires a pentium class or equivilant processor with a maths co-processor
; created by: hayden mckay

call near ClrScreen
mov  di, WaitString
call near PutString
call near RdtscTime
call near ClrScreen
mov  di, AprxString
call near PutString
mov  si,  Frequency
mov  di,  mHzString
call near Dec2Ascii
mov  cx, 5
mov  al,'0'
cld
repe scasb
dec  di
call near PutString

xor ax, ax
int 16h
int 19h

INT 20H                ; leave *.com file

ALIGN 4
WaitString db "please wait...$"
;BootString db "reboot...$"
AprxString db "~ $"
mHzString  db 5 dup(?)
      db 'mHz$',13,10,10

RefPeriod:
    .Delay dd 5     ; five seconds

ClockTick:
    .Ticks dq 18.2f
    .Ratio dq 1000000f

TimeStamp:
    .Lower dd ?
    .Upper dd ?

Frequency:
    .mHz   dd ?

ALIGN 4
RdtscTime:

    ; yippie... i fricken love the fpu processor...

    fld  qword [ds:ClockTick.Ratio]  ; 1000000
    fld  qword [ds:ClockTick.Ticks]  ; 18.2
    fild dword [ds:RefPeriod.Delay]  ; 5
    fld1                         ; 1
    fdiv  st0, st2
    fmul  st0, st3
    fincstp
    fmul  st0, st1
    fdecstp
    fmul  st0, st1
    fstp  qword [ds:ClockTick.Ratio] ; = (((1 / 18.2) * 1000000) * (5 * 18.2))
    fist  dword [ds:RefPeriod.Delay] ; = rounded down (5 * 18.2) = 91
    fstp  qword [ds:ClockTick.Ticks] ; = double float (5 * 18.2) = 91.????????
    ffree st0
    inc   dword [ds:RefPeriod.Delay] ; adds 1 clock ticks for the delay period

    ; point es:di to bios clock tick data area

    push es                 ; save old segment
    mov  ax, 0040h
    mov  di, 006Ch
    mov  es, ax       ; load new segment

    ; wait until the next bios clock tick happens, timming loops are aligned to avoid cache miss
    ; exceptions, also note that 0040:006C is cached by es:di, all this helps with the accuracy!

    mov  ebx, dword [es:di]
ALIGN 4
Wait4Tick:
    cmp  dword [es:di], ebx
    je      Wait4Tick

    ; save a copy of the cpu time stamp counter, need a pentium class or better for this, gea...
    ; otherwise program is killed by an invalid opcode exception...

    rdtsc
    mov  dword [ds:TimeStamp.Lower], eax
    mov  dword [ds:TimeStamp.Upper], edx

    ; wait until the time reference delay period has passed, yawn...

    add  ebx, dword [ds:RefPeriod.Delay]
ALIGN 4
Wait4Time:
    cmp  ebx, dword [es:di]
    jne  Wait4Time               ; jump while not equal

    ; read in the cpu's time stamp counter again and subtract the saved copy...

    rdtsc
    sub  eax, dword [ds:TimeStamp.Lower]
    sbb  edx, dword [ds:TimeStamp.Upper]

    ; save the result someware were the fpu can find it...

    mov  dword [ds:TimeStamp.Lower], eax
    mov  dword [ds:TimeStamp.Upper], edx

    pop  es                      ; restore old segment

    ; some more fpu...

    fild  qword [ds:TimeStamp]
    fdiv  qword [ds:ClockTick.Ratio]
    fistp qword [ds:Frequency.mHz]             ; round off, store and pop it off the stack
    ret

    ; some normal crap for dealing with the display etc. code here is o/s independant...
    ; permission granted if anyone wants to use this code for bootstrap or an o/s kernel

ALIGN 4            ; DwToAscii() - translates a binary word to an ascii string
Dec2Ascii:
    mov  ax, word [ds:si]                ; entry:    [ds:si] points to the word binary
    mov  bx, 10                        ;           [es:di] points to a 5 byte buffer
    mov  cx, 5
SaveAscii:
    xor  dx, dx
    div  bx
    add  dl, '0'
    push bx
    push cx
    pop  bx
    mov  byte [es:di+bx-1], dl
    pop  bx
    loop SaveAscii
    ret

ALIGN 4                   ; ClrScreen() - clears the text display & relocates the cursor
ClrScreen:
    push ds                           ; entry:    n/a
    mov  ax, 0040h
    xor  bx, bx
    xor  dx, dx
    mov  ds, ax
    mov  bh, byte [ds:0062h]   ; active page
    mov  ax, 0200h                                ; legacy vga bios - set cursor
    int  10h
    mov  dl, byte [ds:0084h]   ; maximum rows -1
    mov  ax, word [ds:004Ah]   ; maximum columns
    add  dl, 1
    mul  dx
    mov  cx, ax
    mov  ax, 0900h                                ; legacy vga bios - put chars
    int  10h                                           ; interrupt
    pop  ds
    ret

ALIGN 4                  ; PutString() - writes a '$' terminated string to the display
PutString:
    xor  bx, bx                  ; entry:    [es:di] points to the string source
    mov  ax, 0f00h
    int  10h             ; legacy vga bios - read states
    mov  ax, 0300h
    int  10h           ; legacy vga bios - read cursor
    mov  cx, -1
    mov  al, '$'
    push di
    cld
    repne scasb           ; look for '$'
    pop  bp
    mov  cx, di
    mov  bl, 7            ; default grey
    sub  cx, 1
    mov  ax, 1301h          ; advance mode
    sub  cx, bp
    int  10h               ; legacy vga bios - type string
    ret
    


Description: Here is the compiled version...
Download
Filename: mhz.7z
Filesize: 423 Bytes
Downloaded: 586 Time(s)


_________________
New User.. Hayden McKay.
Post 26 Nov 2007, 07:20
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 04 Dec 2007, 01:08
here is my first try to code for fpu only few modifications in fact. Sad
the basis is mandel example, from fasm for dos package.


Description: arrows to move the picture
A Z to zoom
space to stop the color cycle
echap to exit

Download
Filename: MANDEL.zip
Filesize: 3.04 KB
Downloaded: 571 Time(s)

Post 04 Dec 2007, 01:08
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 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.