I’m trying to change the addresses of the variables once the procedure is done processing the instructions. I have no clue what I’m doing wrong and how to fix it. For example when I input
Gimme X: 12
Gimme Y: 1
Gimme Z: 50
I get this
After biggest, X = 12 Y = 1 Z = 50
when it should be After biggest, X = 50, Y = 50, Z = 50
This is my code so far, any help is greatly appreciated.
program BiggestValue;
#include("stdlib.hhf");
static
x: int16;
y: int16;
z: int16;
procedure biggest(var x: int16; var y: int16; var z: int16); @nodisplay; @noframe;
static
maxValue: int16;
begin biggest;
// Load addresses of x, y, and z into registers
lea(ebx, x); // ebx = address of x
lea(ecx, y); // ecx = address of y
lea(edx, z); // edx = address of z
// Load values pointed by x, y, and z
mov((type int16 [ebx]), ax); // ax = value at address x
mov((type int16 [ecx]), bx); // bx = value at address y
mov((type int16 [edx]), cx); // cx = value at address z
// Find the maximum value
mov(ax, maxValue); // maxValue = value at x
cmp(bx, maxValue);
jle skip_y;
mov(bx, maxValue); // maxValue = value at y
skip_y:
cmp(cx, maxValue);
jle skip_z;
mov(cx, maxValue); // maxValue = value at z
skip_z:
// Set x, y, and z to maxValue
mov(maxValue, (type int16 [ebx])); // value at address x = maxValue
mov(maxValue, (type int16 [ecx])); // value at address y = maxValue
mov(maxValue, (type int16 [edx])); // value at address z = maxValue
end biggest;
begin BiggestValue;
// Get input from the user
stdout.put("Gimme X: ");
stdin.get(x);
stdout.put("Gimme Y: ");
stdin.get(y);
stdout.put("Gimme Z: ");
stdin.get(z);
// Call the biggest procedure
biggest(x, y, z);
// Print the results
stdout.put("After biggest, X = ", x, " Y = ", y, " Z = ", z, nl);
end BiggestValue;