I don't understand why my code outputs The values don't increase even though I input increasing values for example Enter a value: 2 Enter a value: 4 Enter a value: 10 The values don't increase
I also don't understand what this means "after returning back to the caller, your function should not change the value of any register other than DX".
program IncreasingCheck;
#include( "stdlib.hhf" );
static
value1: int8;
value2: int8;
value3: int8;
procedure increasing( valuel : int8; value2 : int8; value3 : int8 ); @nodisplay; @noframe;
begin increasing;
// Checking if value2 is greater than value1
mov( valuel, AL );
mov( value2, BL );
mov( value3, CL );
cmp( AL, BL );
jge NotIncreasing;
// Checking if value3 is greater than value2
cmp( BL, CL );
jge NotIncreasing;
// If both conditions are true, it's increasing
mov( 1, DX );
jmp Done;
NotIncreasing:
mov( 0, DX );
Done:
ret();
end increasing;
begin IncreasingCheck;
stdout.put( "Enter a value: " );
stdin.get( value1 );
stdout.put( "Enter a value: " );
stdin.get( value2 );
stdout.put( "Enter a value: " );
stdin.get( value3 );
// Call the increasing procedure
call increasing;
// Output result
cmp(DX, 1);
je Increase;
jmp NoInc;
Increase:
stdout.put( "The values increase!" );
jmp EndProgram;
NoInc:
stdout.put( "The values don't increase" );
EndProgram:
end IncreasingCheck;
I didn't read Randy Hydes book and play with his HLA but according to this
it looks like You didn't pass arguments to increasing proc
. Some random values are popped.
Also procedure should have prologue and epilogue to correctly pop values from the stack.
push (ebp); // procedure prologue
mov (esp,ebp);
...
mov(ebp,esp); // procedure epilogue
pop(ebp);
ret();
This is corrected procedure:
procedure increasing( value1 : int8; value2 : int8; value3 : int8 ); @nodisplay; @noframe;
begin increasing;
push (ebp);
mov (esp,ebp);
// Checking if value2 is greater than value1
mov( value1, AL );
mov( value2, BL );
mov( value3, CL );
cmp( AL, BL );
jge NotIncreasing;
// Checking if value3 is greater than value2
cmp( BL, CL );
jge NotIncreasing;
// If both conditions are true, it's increasing
mov( 1, DX );
jmp Done;
NotIncreasing:
mov( 0, DX );
Done:
mov(ebp,esp);
pop(ebp);
ret();
end increasing;
And how to trigger it:
increasing(value1,value2,value3);