News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Using FPU functions to resolve Trigonometry Problems

Started by norpeter, November 11, 2018, 10:26:25 AM

Previous topic - Next topic

norpeter

I'm new to this forum as well as to MASM32 assembly.  I'm 74 years old and I've just started teaching myself assembly language again which I haven't used since the 80s.  I'm doing this for fun and to keep my mind active.  Recently I started a project to develop an application to resolve basic trig problems using fsin, fcos, and fpatan floating point instructions.  Everything
worked well until I decided to do the inverse of these instructions.  I came across the FpuArcsin,  FpuArccos, and FpuArctan functions which I intended to use, however, I haven't been
very successful with them.  If one could provide some examples of how these functions are called or invoked, that would at least get me kick started on completing my application.  I should also mention that I've been combining the assembly language part of my application with links to a Windows interface language which is also compiles.  It has the Asin(x), Acos(x), and Atan(x) inversion instructions, but I prefer to use FPU assembly functions.  I just need one good example.   Many thanks.


jj2007

Hi norpeter,

Our friend Mikl gave you a link to a fascinating project, don't miss it! But for starting your journey, you should visit the page of the FPU expert, Raymond Filiatreault (Mikl knows him, too ;))

For testing fpu code, you can either use a debugger (Olly is fantastic), or a debug macro like deb:

include \masm32\MasmBasic\MasmBasic.inc         ; download

.data           ; initialised data section
MyReal8         REAL8 12345678.90
MyReal10        REAL10 1.1111111111111111111111111111111111

  Init
  deb 4, "On init", ST(0), ST(1)        ; show the first two FPU registers
  fldpi                                 ; load PI
  fld MyReal10
  deb 4, "after two loads", ST(0), ST(1), ST(2)         ; first three registers after two loads
  fmul
  deb 4, "PI*1.111", ST(0), ST(1)
  fsincos
  deb 4, "fsincos(PI*1.111)", ST(0), ST(1)
  Inkey CrLf$, "ok?"            ; wait for a keypress
EndOfCode


Output:
On init
ST(0)           0.0
ST(1)           0.0

after two loads
ST(0)           1.111111111111111111
ST(1)           3.141592653589793238
ST(2)           0.0

PI*1.111
ST(0)           3.490658503988659154
ST(1)           0.0

fsincos(PI*1.111)
ST(0)           -0.9396926207859083841
ST(1)           -0.3420201433256687331


And don't hesitate to ask lots of questions here - welcome to the forum :icon14:

Jochen

Mikl__


raymond

Hi norpeter,

Welcome to this forum young man 8)

You seem to be very interested in using the computer for playing with mathematics. In the link which JJ gave you for my site, you may also find a few more "playing" options in addition to learning how to use the FPU.

Make sure you also look at the source code of the FPU library functions. Once you understand those functions that you need, you can then extract the instructions needed for your specific applications without some of the overhead. Hope you enjoy it.
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

norpeter

Thanks for the warm welcome!  By the way, Fortran was my first programming language too back in the 70s.  My first computer was an 8-bit model I built from Heath Kit.  We've sure come a long way since then.  Anyway, I've gone through the Fpulib source code on most of its functions and I've also used the included Fpulibtester.exe.  It gave me the results I wanted on FpuArcsin, FpuArccos, and FpuArctan.   I hope to do the same soon.   Thank you for the insight.

norpeter

I've come a long way using FPU instructions and I've nearly completed my masm32 learning project .  It involved using a Windows interface language to create menus to selectively access masm32 procedures to solve various Trig problems.   The whole project turned out quite well except for the positioning of the console window and font selection.  I managed to implement various colours into the console windows but not fonts or console resizing or positioning.   If anyone could point me in the right direction for this, it would be greatly appreciated.   I am looking for simple system command instructions or several lines of masm32 code to do the trick.  I browsed around on the internet for ways but I haven't been able find any instruction
sets that involves less than a dozen lines of code.  If anyone know a simple way to do any of these tasks, I would really love to hear about it.  Thank folks.

dedndave

programming the console window under windows can be buggish (always has been)
so, i generally use the console in "teletype" mode only, not trying to reposition the cursor or do anything fancy
it works well for simple tasks

if you want much more than that, in the way of appearance, it's a safe bet that you want a GUI application
furthermore, when you start writing a GUI app, start out using UNICODE windows (a hard lesson learned - lol)

as for the math part, i am a little surprised that Ray did not mention Project Euler  :P

https://projecteuler.net/

jj2007

Quote from: dedndave on January 08, 2019, 05:22:24 AMif you want much more than that, in the way of appearance, it's a safe bet that you want a GUI application

Indeed! This full-fledged Windows GUI application loads formatted text from a resource file. You can edit the text, saving would be three lines more.

GuiParas equ "No rocket science needed to program a GUI application", x50, y50, w1000, h600
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste
include \masm32\MasmBasic\Res\MbGui.asm

GuiControl MyEdit, "richedit"
SetWin$ hMyEdit=FileRead$(100)                 ; use resource ID #100 (can be a disk file or a URL, too)

Event Menu
  Switch_ MenuID
  Case_ 0: MsgBox 0, "You clicked 'Open'", "Menu test:", MB_OK
  Case_ 1 .. 6
        MsgBox 0, Str$("You clicked on menu #%i", MenuID), "Test:", MB_OK
  Endsw_
GuiEnd

dedndave

hi Jochen  :t
Hope you have a great New Year!

.....
yah, but i think he wants to learn ASM, not basic - lol
(i am sure you've heard that before)

dedndave

...actually, it's not so much the issue of ASM vs Basic

what he would really miss out on is the discovery process for the Windows operating system API functions

to create a GUI application, learn about...
window classes (RegisterWindowEx)
WndProc procedures and windows messaging (including the message loop)
creating a window (CreateWindowEx)

it's also helpful to touch on windows controls (including common controls), resource files, and the build process/tool chain

aw27

Quote
I haven't been able find any instruction
sets that involves less than a dozen lines of code .... for the positioning of the console window and font selection
Looks difficult indeed.