/* Create an HLA function that forces a value into all three passed parameters. This function should have the following

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

/* Create an HLA function that forces a value into all three passed parameters. This function should have the following

Post by answerhappygod »

/*
Create an HLA function that forces a value into all three passed
parameters. This function should have the following signature:
procedure makeSmallest( var i : int16; var j : int16; var k :
int16 );@nodisplay; @noframe;
After calling this function, the value of all the driver’s
variables should be set to the value of the smallest of the three
passed parameters. Your function should replicate the following C
code:
void makeSmallest( int * i, int * j, int * k ) {
int smallest = *i;
if (*j < smallest)
{
smallest = *j;
}
if (*k < smallest)
{
smallest = *k;
}
*i = smallest;
*j = smallest;
*k = smallest;
}
IN ORDER TO RECEIVE FULL CREDIT, YOU MUST USE THE TEMPLATE
SOLUTION SUPPLIED BELOW> Of course, you will need to add code to
the function to implement the desired algorithm explained above. In
addition, you will need to push the parameters to the function. Be
sure your function preserves all the registers it touches.
*/
// Students must use this template as the basis for their
solution. I hope it will help simplify your development task.
// Please look at the two TODO: notes below
program ReferenceProgram ;
#include( "stdlib.hhf" );
static
iValue1 : int16 := 0;
iValue2 : int16 := 0;
iValue3 : int16 := 0;
// TODO: Students add code below to implement this function
// Several hints are supplied
procedure makeSmallest( var i : int16; var j : int16; var k :
int16 );@nodisplay; @noframe;
static
dReturnAddress : dword;
begin makeSmallest ;
// entry sequence
// preserve registers used
pop( dReturnAddress );
// this is the return address
// push back the return address
push( dReturnAddress );
// preserve registers
// TODO: implement function
// restore the registers used
ret();
end makeSmallest ;
begin ReferenceProgram ;
stdout.put( "Gimme iValue1:" );
stdin.get( iValue1 );
stdout.put( "Gimme iValue2:" );
stdin.get( iValue2 );
stdout.put( "Gimme iValue3:" );
stdin.get( iValue3 );
// TODO: push parameters to the function.
// These parameters must be passed by-reference.
call makeSmallest ;
stdout.put( "after makeSmallest!" );
stdout.newln();
stdout.put( "iValue1 = " );
stdout.put( iValue1 );
stdout.put( "iValue2 = " );
stdout.put( iValue2 );
stdout.put( "iValue3 = " );
stdout.put( iValue3 );
stdout.newln();
end ReferenceProgram;
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply