flat assembler
Message board for the users of flat assembler.
Index
> DOS > Simple, yet flashy first FPU program! |
Author |
|
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!
|
|||||||||||
25 Nov 2007, 20:10 |
|
rhyno_dagreat 25 Nov 2007, 20:13
Note: Try and follow the spiral from the center. It will really mess with your head.
|
|||
25 Nov 2007, 20:13 |
|
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.
|
|||
25 Nov 2007, 21:35 |
|
rhyno_dagreat 25 Nov 2007, 21:41
PI is an FPU constant and nobody told me!?
That's awesome! XD Thanks for the hints everyone |
|||
25 Nov 2007, 21:41 |
|
vid 25 Nov 2007, 22:11
Quote: PI is an FPU constant and nobody told me!? |
|||
25 Nov 2007, 22:11 |
|
rhyno_dagreat 26 Nov 2007, 05:05
I fixed the two areas mentioned and I added bounds checking for the PSet function.
|
|||
26 Nov 2007, 05:05 |
|
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
_________________ New User.. Hayden McKay. |
|||||||||||
26 Nov 2007, 07:20 |
|
edfed 04 Dec 2007, 01:08
here is my first try to code for fpu only few modifications in fact.
the basis is mandel example, from fasm for dos package.
|
|||||||||||
04 Dec 2007, 01:08 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.