Page 1 of 1

Create an HLA function that checks whether none of its passed parameters are zero. This function should have the followi

Posted: Mon Jun 06, 2022 4:43 pm
by answerhappygod
Create an HLA function that checks whether none of its passed
parameters are zero. This function should have the following
signature:
procedure noneZero( value1 : int16; value2 : int16; value3 :
int16 ); @nodisplay; @noframe;
This function should return a one in EAX if all of the passed
arguments are not zero; otherwise, return zero in EAX. Your
function should replicate the following C code:
bool noneZero( int value1, int value2, int value3 )
{
bool result = true;
if (value1 == 0)
{
result = false;
}
if (value2 == 0)
{
result = false;
}
if (value3 == 0)
{
result = false;
}
return( result );
}
IN ORDER TO RECEIVE FULL CREDIT, YOU MUST USE THE TEMPLATE
SOLUTION SHOWN 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 to preserve any registers your function touches.
// Please look at the TODO: notes below
program isNoneZeroProgram;
#include( "stdlib.hhf" );
static
iValue1: int16 := 0;
iValue2: int16 := 0;
iValue3: int16 := 0;
iAnswer : int32 := 0;
// TODO: CS 17 Students add code below to implement this
function
// Several hints are supplied
procedure noneZero( value1 : int16; value2 : int16; value3 :
int16 );@nodisplay; @noframe;
static
dReturnAddress : dword;
begin noneZero ;
// entry sequence
// preserve registers used
pop( dReturnAddress );
// push back the return address
push( dReturnAddress );
// preserve registers
// begin function task
// restore the registers used
// leave the answer in EAX
ret();
end noneZero;
begin isNoneZeroProgram;
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.
call noneZero;
mov( EAX, iAnswer );
stdout.put( "after noneZero iAnswer=", iAnswer );
stdout.newln();
end isNoneZeroProgram;