Comparison and conditional branching in HLA

19 Views Asked by At

I'm working on this problem: procedure matchingSum( i: int32; j : int32; k : int32 ); @nodisplay; @noframe;

This function should return into EAX the value 1 if any two parameters sum to exactly the value of the third parameter; otherwise, return into EAX the value 0. In order to receive full credit, you should be preventing register corruption by preserving and then restoring the value of any register your function touches. This rule applies to every register except for EAX which is being used to pass an answer back to the calling code.

Feed Me i: 20 Feed Me j: 20 Feed Me k: 20 EAX = 0

my code takes the inputs but doesn't print out the EAX for some reason. After I enter the inputs, nothing is printed and I can't figure out why:

"program MatchingSumFunction;

#include( "stdlib.hhf" );

procedure matchingSum( i: int32; j: int32; k: int32 ); @nodisplay; @noframe;
static
returnAddress : dword;

begin matchingSum;
// Get the return address from the stack
pop(returnAddress);

cmp(i, 0);
je ReturnTrue;

cmp(i, 0);
jle ReturnFalse;

// Call matchingSum(i - k, j, k)
push(k);
push(j);
push(i);
call matchingSum;

jmp ExitSequence;

ReturnTrue:
mov(1, EAX); // Return true

ReturnFalse:
mov(0, EAX); // Return false

ExitSequence:
// Restore the return address and return
push(returnAddress);
ret();
end matchingSum;

begin MatchingSumFunction;
stdout.put("Feed Me i: ");
stdin.geti32();   // Read i from the user

stdout.put("Feed Me j: ");
stdin.geti32();   // Read j from the user

stdout.put("Feed Me k: ");
stdin.geti32();   // Read k from the user

call matchingSum;  // Call the matchingSum function

stdout.put("EAX = ");
stdout.puti32(eax);
stdout.newln();   // Move to a new line
end MatchingSumFunction;

"

0

There are 0 best solutions below