Question: Create an HLA function that forces a value into a passed parameters under certain circumstances. The parameters are being passed by - reference and are

Create an HLA function that forces a value into a passed parameters under certain circumstances. The parameters are being passed by-reference and are intended to change the value of callers variables.
This function should have the following signature:
procedure makeOddByAddingOne( var i : int16);@nodisplay; @noframe;
After calling this function, the value of the drivers variables should be set to an odd value equal to one more that it started with if it was originally an even value. Your function should replicate the following C code:
void makeOddByCreate an HLA function that forces a value into a passed parameters under certain circumstances. The parameters are being passed by-reference and are intended to change the value of callers variables.
This function should have the following signature:
procedure makeOddByAddingOne( var i : int16);@nodisplay; @noframe;
After calling this function, the value of the drivers variables should be set to an odd value equal to one more that it started with if it was originally an even value. Your function should replicate the following C code:
void makeOddByAddingOne( int * i )
{
int value =*i;
// after enough subtractions, value will be either 2 or 1
while (value >2)
{
value = value -2;
}
// now value is either 2 or 1
// was i originally even?? if so, then add one
if (value ==2)
{
value =*i;
value = value +1;
*i = value;
}
}
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 prepare and push the parameters to the function.
// I hope it will help simplify your development task.
// Please look at the two TODO: notes below
programReferenceProgram;
#include( "stdlib.hhf");
static
iValue1 : int16 :=0;
// TODO: Add code below to implement this function
// Several hints are supplied
procedure makeOddByAddingOne( var i : int16);@nodisplay; @noframe;
static
dReturnAddress : dword;
begin makeOddByAddingOne;
// entry sequence
// preserve registers used
pop( dReturnAddress );// this is the return address
// process the passed reference parameters
// push back the return address
push( dReturnAddress );
// preserve registers
// begin sub-task
// restore the registers used
ret();
end makeOddByAddingOne;
beginReferenceProgram;
stdout.put( "gimme a value: ");
stdin.get( iValue1);
// TODO: push parameters to the function.
// Please remember that these parameters must be passed by-reference.
call makeOddByAddingOne;
stdout.put( "after makeOddByAddingOne!" );
stdout.newln();
stdout.put( "iValue1=");
stdout.put( iValue1);
stdout.newln();
endReferenceProgram;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!