Write an HLA Assembly language program that implements a function which correctly identifies which of three parameters is the largest and returns in AX the value of that largest parameter. This function should have the following signature:
procedure largestfinder( x: int16; y: int16; z: int16 ); @nodisplay; @noframe;
Must pass your parameters on the run-time stack and 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 AX which is being used to pass an answer back to the calling code.
Feed Me X: 5
Feed Me Y: 13
Feed Me Z: 10
AX = 13
Feed Me X: 35
Feed Me Y: 5
Feed Me Z: 11
AX = 35
Feed Me X: 5
Feed Me Y: 235
Feed Me Z: 51
AX = 235
program LargestFinder;
#include("stdlib.hhf");
procedure largestfinder(x: int16; y: int16; z: int16); @nodisplay; @noframe;
begin largestfinder;
pop(EDX); // Return Address
pop(z);
pop(y);
pop(x);
// Save the Return Address again
push(EDX); // Return Address
// Assume x is the largest initially
mov(x, AX);
// Compare with y
cmp(y, AX);
jle CheckZ;
mov(y, AX);
CheckZ:
// Compare with z
cmp(z, AX);
jle EndLargestFinder;
mov(z, AX);
EndLargestFinder:
// Return the largest value in AX
ret();
end largestfinder;
begin LargestFinder;
stdout.put("Feed Me X: ");
stdin.geti16();
push(AX);
stdout.put("Feed Me Y: ");
stdin.geti16();
push(AX);
stdout.put("Feed Me Z: ");
stdin.geti16();
push(AX);
call largestfinder;
stdout.put("The largest number is: ", AX);
end LargestFinder;
Noodoh Bae is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1