News:

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

Main Menu

plotting in masm 32 bit

Started by markallyn, March 06, 2018, 07:19:16 AM

Previous topic - Next topic

jj2007

Hi Mark,
you are almost there:include \masm32\MasmBasic\Res\MbGui.asm
.data
plotpoints   REAL4  1.1,2.2,3.0,4.0,5.5 ; OPT_Assembler uasm32
.code
  Dim MySinus() As REAL4        ; prepare an array for being plotted (real4 or real8)
  For_ ecx=0 To 4
        fld  plotpoints[4*ecx]
        SetFloat MySinus(ecx)=ST(0)
  Next
Event Paint
  ArrayPlot RgbCol(192, 222, 255)               ; init & set background
  ArrayPlot MySinus(), 0, lines=2               ; draw the array with 2px lines
  ArrayPlot exit, "Playing with Sinus() plots"  ; finish with a title
EndOfCode


This puts plotpoints in the .data section and uses ecx as a counter, so that plotpoints[4*ecx] can be used. Works fine  :biggrin:
I modified two values to avoid a straight line ;-)

P.S.: Here is a variant using StringToArray:

include \masm32\MasmBasic\Res\MbGui.asm

  Dim MyR4() As REAL4
  StringToArray FileRead$("MyData.tab"), MyR4()

Event Paint
  ArrayPlot RgbCol(192, 222, 255)                      ; init & set background
  ArrayPlot MyR4(), RgbCol(255, 0, 0), lines=2         ; draw the array with 2px lines
  ArrayPlot exit, "Data read from a tab file"          ; finish with a title
EndOfCode


Sample file attached, must be in the same folder as the exe.

markallyn

Good evening, JJ,

Once again, I would never have come up with this solution.  But, I see now how it works.

Question: In your original post you referred to a sinus() function.  I assume this is a built-in in masmbasic.  If so, where can I find a list of others, for example, exp, tan, sqrt,, etc.

Regards,
Mark

markallyn

Good evening once more,

You may disregard my question re masmbasic functions.  I found them by looking through masmbasic.inc.  It isn't really convenient, but it works.

Thanks again,
Mark

jj2007

Quote from: markallyn on March 10, 2018, 08:32:48 AMI found them by looking through masmbasic.inc

In the RichMasm menu File, there is "Guide to MasmBasic", listing about 400 functions. Press Ctrl F to search, for example, Exp
But MasmBasic is relatively weak on math; you will still need to know the FPU and roll your own.

HSE

Quote from: markallyn on March 10, 2018, 08:24:24 AM
where can I find a list of others, for example, exp, tan, sqrt,, etc.

qWord's SmplMath  :t
Equations in Assembly: SmplMath

dedndave

the deBoorBezierSpline function wants to see an array of POINT structures
the values for each point are related to pixel locations in the window where the graph is to be drawn

the array is constructed of "knot points" and "control points"
the knot points are essentially your data points, converted into pixel locations
so, you create the array, then fill in the knot points, and pass the address to deBoorBezierSpline
you also tell the function the number of knot points in the array (must be at least 3)
the function will fill in the control points for you
when it's done, the array is suitable for use with the PolyBezier function (used in WM_PAINT code)

the total number of POINT structures in the array is Knots + 2 * (Knots - 1)

knot point
control point
control point
knot point
control point
control point
knot point
.
.
.
knot point
control point
control point
knot point


as i mentioned earlier, YOU initialize the knot points - the function fills in the control points for you

dedndave

... in the demo program, i used an array with 36 knot points
so, there are 2*(36-1) = 70 control points
a total of 106 POINT structures in the array

i make up fake data by using a random number generator
the X step is always 10 pixels and the Y points are generated randomly
equal X spacing is not a requirement, it was just easy to generate that way

i used 2 arrays, one to hold the currently displayed array, one to generate new data
i flip back and forth between the 2 arrays

markallyn

Dave and JJ,

I had to briefly abandon the plot problem due to traveling.  I'm back home now and will resume its solution--thanks to all of your help.

I will post a .zip file that contains a set of plot points that are the solution of a simple ordinary diff eqn.  This will give you a typical data set from the sort of math problems I enjoy solving.  In the past I have used C and called GnuScientificLibrary routines or Octave or similar.  I want to do the same thing in assembly.

Thanks.  Please keep tuned to this thread.

Regards,
Mark

jj2007

Quote from: markallyn on March 13, 2018, 07:26:04 AMI will post a .zip file that contains a set of plot points that are the solution of a simple ordinary diff eqn.  This will give you a typical data set

Very good. If you want to try yourself, see reply #30:  Dim MySinus() As REAL4        ; prepare an array for being plotted (real4 or real8)
  For_ ecx=0 To 4
        fld plotpoints[4*ecx]    ; <<<< replace with whatever produces your values.
        SetFloat MySinus(ecx)=ST(0)   ; this pops the value from ST(0) to the array
  Next

aw27

This may sound like a sacrilege but there pretty good online 2-D plotters. At least as good as others I have seen around here.
http://itools.subhashbose.com/grapher/index.php

markallyn

Hello JJ and others, most recently aw27:

Apologies for being a little late to the party with a test data set:  rk4.zip contains values of time from 0 to 1 for the solution to dy/dt=1-2*y(2).  Y0 is 1.0.  A very simple function solved using 4th order runge-kutta technique.

First column of doubles is clearly t and second is y(t).

Thanks for all your inputs.

I'll check out the 2-D plotter mentioned by aw27.

Regards,
Mark

markallyn

...OOPs.

Equation should read: 

Quote
dy/dt=1-2*y(t)

Lousy at typos!

Mark

dedndave

i am currently working on a simplified form of the PolyBezier demo program
it is for a single static graph - you enter data points and assemble
i am adding a little complexity in that, when you re-size the window, it re-scales the graph
should finish it later today or tomorrow
i will use your data set  :t

jj2007

Quote from: markallyn on March 14, 2018, 06:05:03 AMtest data set:  rk4.zip contains values of time from 0 to 1 for the solution to dy/dt=1-2*y(2).  Y0 is 1.0

include \masm32\MasmBasic\Res\MbGui.asm
  Dim rk() As REAL4             ; define a REAL4 array
  StringToArray 99, rk()        ; fill it; 99 is the resource ID for rk4.txt
Event Paint
  ArrayPlot RgbCol(192, 255, 255)                      ; init & set background
  ArrayPlot rk(XY), RgbCol(222, 0, 0), lines=2         ; draw the array with 2px red lines
  ArrayPlot exit, "Data read from a resource"          ; finish with a title
EndOfCode


Does it look correct? Project attached - to build it, rk4.txt must be in the same folder.

markallyn

JJ, Dave, and aw27,

aw27:  Yes, there are a number of excellent 2-d plotters available.  Gnuplot is one, and it's excellent and opensource, but there are many others too.  What I am trying to accomplish is to write in assembly (masm, uasm, Jwasm, goasm, poasm,nasm,  etc.) a numerical integrator that can call a plotter written also in assembly.  Why?  I could write a c/c++ program, write results to a file, and then call a plotter.  It would be much easier, but not nearly as much fun or as instructive.

Dave:  Great news.  Go for it!

JJ:  Yup.  That's it!  Subsequent to the posting I ran the integrator again and generated plot points out to 2.0.  It clearly shows that the function asymptotes at 0.5.  Now, here's my challenge:  How to put labeled axes and tick marks on the plot.  Can it be done?

Regards,
Mark