For a pyramid, a cone or a cylinder, their volumes can be computed from the para
ID: 3918533 • Letter: F
Question
For a pyramid, a cone or a cylinder, their volumes can be computed from the parameters b, r and h, as shown below:
Volume = pi * r * r * h
Write an HLA Assembly language program that computes and then prints the volume of a pyramid, cone and cylinder based on a radius r, a length b and a height h by writing a function with the following signature:
A sample program dialogue is shown below.
Lemme calculate the volumes of various things!
Gimme r: 1.0
Gimme b: 1.0
Gimme h: 1.0
Volume of a pyramid = 0.33333
Volume of a cone = 1.04719
Volume of a cylinder = 3.14159
Lemme calculate the volumes of various things!
Gimme r: 1.0
Gimme b: 1.0
Gimme h: 3.0
Volume of a pyramid = 1.00000
Volume of a cone = 3.14159
Volume of a cylinder = 9.42477
Lemme calculate the volumes of various things!
Gimme r: 2.0
Gimme b: 1.0
Gimme h: 3.0
Volume of a pyramid = 1.00000
Volume of a cone = 12.5663
Volume of a cylinder = 37.6991
Volume = pi * r * r * h
Explanation / Answer
HLA program:
program volume;
#include( "stdlib.hhf" );
static
radius : real32;
length : real32;
height : real32;
procedure volumeFinder( r: real32; b : real32; h : real32 ); @nodisplay; @noframe;
static
returnAddress : dword;
v : real32;
begin volumeFinder;
pop(returnAddress);
pop(r);
push(returnAddress);
pop(returnAddress);
pop(b);
push(returnAddress);
pop(returnAddress);
pop(h);
push(returnAddress);
// set of statements for calculating the volume of pyramid
finit();
fld( b );
fld( h );
fmul();
fldpi();
fld(0.3);
fmul();
fmul();
fmul();
fstp( v );
stdout.putr32(v, 4, 10);
ret();
// set of statements for calculating the volume of cone
finit();
fld( r );
fld( st0 );//this statement copies the previous stack
fld( h );
fmul();
fldpi();
fld(0.3);
fmul();
fmul();
fmul();
fstp( v );
stdout.putr32(v, 4, 10);
ret();
// set of statements for calculating the volume of cylinder
finit();
fld( r );
fld( st0 );
fld( h );
fmul();
fldpi();
fmul();
fmul();
fstp( z );
stdout.putr32(z, 4, 10);
ret();
end volumeFinder;
begin volume;
stdout.put("Lemme calculate the volumes of various things!", nl);
stdout.put("Gimme r: "); stdout.put("Gimme b: "); stdout.put("Gimme h: ");
stdin.get(radius);stdin.get(length);stdin.get(height);
stdout.put("Volume of a pyramid: ", nl); stdout.put("Volume of a cone: ", nl); stdout.put("Volume of a cylinder: ", nl);
call volumeFinder;
end volume;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.