0

I am working on an assembly, technically HLA(High Level Assembly) assignment. Here is my assignment:


Write an HLA Assembly language program that computes the surface area based on a radius. A sample program dialogue is shown below. However you decide to do it, your main program should include calling a procedure or function (atleast one...) to solve this problem.

Lemme calculate the surface area of a sphere! Gimme r: 1 Surface Area = 12.57

Lemme calculate the surface area of a sphere! Gimme r: 3.5 Surface Area = 153.94


Here is my code:

program surfaceArea;
#include( "stdlib.hhf" );
static
radius : real32;

procedure computeSurfaceArea(r : real32); @nodisplay; @noframe;
static
    returnAddress : dword;
    z : real32;

begin computeSurfaceArea;

pop(returnAddress);
pop(r);
push(returnAddress);

finit();
fld( r );
fld( st0 );
fmul();

fldpi();
fld(4.0);            .
fmul();

fmul();

fstp( z );
stdout.putr32(z, 4, 10);
ret();
end computeSurfaceArea;

begin surfaceArea;

stdout.put("Lemme calculate the surface area of a sphere!", nl);
stdout.put("Gimme r: ");
stdin.get(radius);
stdout.put("Surface area is: ", nl);
call computeSurfaceArea;

end surfaceArea;

So my problem is with my fld(4.0) line of code. What I am trying to do is multiply 4 by pi, and then multiply the result of that with r square which was calculated up above. The error I get is:

Syntax Error, unexpected ".".

Thank you for the help.

ecain
  • 1,282
  • 5
  • 23
  • 54
  • Did you try `fld( 4 );`? – RockPaperLz- Mask it or Casket Nov 15 '15 at 06:29
  • 1
    There is a dot at the end of the line `fld(4.0); .`. This causes the error. Remove it. – rkhb Nov 15 '15 at 08:04
  • Hints: Change all `fmul();` to `fmulp();` and change `stdout.putr32(z, 4, 10);` to `stdout.put(z:10:2);` and insert a `push (radius);` before `call computeSurfaceArea;`. – rkhb Nov 15 '15 at 09:04
  • Wow thanks so much, I never noticed the period there. – ecain Nov 15 '15 at 19:03
  • You sure you don't want to make that an answer so I can up vote you? – ecain Nov 15 '15 at 19:04
  • @Elijah: You're welcome. The typo itself is not worth to make a full answer. The "hints" would need wide explanations. And hazardous is your parameter handling with push/pop, where I found a bug/feature in HLA (using `EBP` as frame pointer without initializing it properly). I think I wait for your next issue... :-) – rkhb Nov 15 '15 at 19:28
  • Well after I fixed the period, and remembered to push radius it actually works correctly. Was there an issue that should have happened? – ecain Nov 15 '15 at 19:53
  • Are you sure you need to multiply by 4? – greybeard Nov 17 '15 at 20:40

0 Answers0