I’m wondering where my error is that my program can’t detect if the user’s inputs are a multiple or not.
This is what I want to be outputted
Example 1:
Feed Me i: 10
Feed Me j: 20
EAX = 1
Example 2:
Feed Me i: 20
Feed Me j: 10
EAX = 1
instead when I enter it I get this
Feed Me i: 20
Feed Me j: 10
EAX = 0
program multiples;
#include("stdlib.hhf");
static
iDataValue1 : int32 := 0;
iDataValue2 : int32 := 0;
procedure multiplesOfAnother(i: int32; j: int32); @nodisplay; @noframe;
begin multiplesOfAnother;
// Preserving registers
push(EBX);
push(ECX);
push(EDX);
mov(0, EAX);
mov(i, EBX); // EBX will hold the value of i
mov(j, ECX); // ECX will hold the value of j
// Determine the smaller and larger values
cmp(EBX, ECX);
jg Swap; // Jump if EBX > ECX
// If we reach here, ECX is larger or they are equal
mov(EBX, EDX); // Start with the smaller value in EDX
jmp Adding;
Swap:
mov(ECX, EDX); // Start with the smaller value in EDX (here, ECX is smaller)
mov(EBX, ECX); // Swap the values
mov(EDX, EBX);
Adding:
add(EDX, EDX);
cmp(EDX, ECX);
je YesMultiples; // If they are equal, they are multiples
jl Adding;
jmp EndProcedure; // Exit if EDX surpasses ECX without matching
YesMultiples:
mov(1, EAX); // Set EAX to 1 to indicate they are multiples
EndProcedure:
// Restore registers
pop(EDX);
pop(ECX);
pop(EBX);
ret(); // Return from procedure
end multiplesOfAnother;
begin multiples;
stdout.put( "Feed Me i: " );
stdin.get( iDataValue1 );
stdout.put( "Feed Me j: " );
stdin.get( iDataValue2 );
push( iDataValue2 );
push( iDataValue1 );
call multiplesOfAnother;
// This function leaves the answer in EAX
cmp(EAX, 1);
je Multiple;
jmp NotMultiple;
Multiple:
stdout.put("EAX = 1");
jmp EndProgram;
NotMultiple:
stdout.put("EAX = 0", nl);
jmp EndProgram;
stdout.newln();
EndProgram:
end multiples;
Any help is greatly appreciated!