Reputation: 11
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.
I have written my code but get "####" as the output of the surface area heres my code:
program surfaceArea;
#include( "stdlib.hhf" );
static
radius : real32;
procedure computeSurfaceArea(r : real32); @nodisplay; @noframe;
static
returnAddress : dword;
area : real32;
begin computeSurfaceArea;
pop(returnAddress);
pop(r);
push(returnAddress);
finit();
fld( r );
fld( st0 );
fmul();
fldpi();
fld(4.0);
fmul();
fmul();
fstp( area );
stdout.putr32(area, 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 = ");
call computeSurfaceArea;
end surfaceArea;
Upvotes: 0
Views: 495
Reputation: 21
Look here: stdout.putr32(area, 4, 10);
Unfortunately you have not provided enough field width for the output text (space for the leading numbers nor the decimal) for the value to be printed correctly.
stdout.putr32( r:real32; width:uns32; decpts:uns32 ); The first parameter to these procedures is the floating point value you wish to print. The size of this parameter must match the procedures name. The second parameter specifies the field width for the output text. Like the width when working with an integer value, this width is the number of character positions the number will require when the procedure displays it. Remember to include a position for both the sign of the number and the decimal point. The third parameter specifies the number of print positions to place after the decimal point. As an example, stdout.putr32( pi, 10, 4 ); displays the value _ _ _ _ 3.1416 where the underscores are used to represent leading spaces.
I hope this helps!
Upvotes: 1