Question: PROGRAM 1 5 : Biggest Write an HLA Assembly language program that implements a function which correctly adjusts each parameter value to hold the largest

PROGRAM 15: Biggest
Write an HLA Assembly language program that implements a function which correctly adjusts each parameter value to hold the largest value passed to the function. This function should have the following signature:
procedure biggest( var x : int16; var y : int16; var z : int16); @nodisplay; @noframe;
After invoking the function, the caller's version of the variables x, y and z should all set to the same value which is the biggest value supplied to the function. Your function must use reference parameters, changing the callers version of the variables passed to the function. Here is a sample program dialogue:
Gimme X: 12
Gimme Y: 1
Gimme Z: 50
After biggest, X =50, Y =50, Z =50
Gimme X: 100
Gimme Y: 10
Gimme Z: 2
After biggest, X =100, Y =100, Z =100
(Hint: Even though the parameters are listed as int16, HLA expects you will pass them as memory addresses, requiring a full 32-bit value. So you'll have to use extended registers to hold the parameters, not 16-bit registers!)
(Second Hint: Since there are reference parameters, the original main program variable values should be changed after being passed to this function)
This is what I have so far:
program Biggestm;
#include( "stdlib.hhf");
// Procedure to find the largest value and assign it to x, y, and z
procedure biggest( var x:int16; var y:int16; var z:int16); @nodisplay; @noframe;
static
ret_addr: dword; // Variable to store the return address
xx: int16;
yy: int16;
zz: int16;
begin biggest;
// Save the return address and load the addresses of x, y, z from the stack
pop( ret_addr ); // Pop the return address into ret_addr
pop( eax ); // Pop the address of x into eax
mov( eax, ebx ); // Copy eax to ebx for later use
pop( eax ); // Pop the address of y into eax
mov( eax, ecx ); // Copy eax to ecx for later use
pop( eax ); // Pop the address of z into eax
mov( eax, edx ); // Copy eax to edx for later use
// Load values of x, y, z into registers
mov([ebx], xx ); // Value of x into xx
mov([ecx], yy ); // Value of y into yy
mov([edx], zz ); // Value of z into zz
mov(xx,ax);
mov(yy,bx);
mov(zz,cx);
cmp( bx, ax );
jg set_y_as_largest;
cmp( cx, ax );
jg set_z_as_largest;
jmp update_all;
set_y_as_largest:
cmp( cx, bx );
jg set_z_as_largest;
mov( yy, xx );
jmp update_all;
set_z_as_largest:
mov( zz, xx );
update_all:
mov( xx,[ebx]);
mov( xx,[ecx]);
mov( xx,[edx]);
// Push back the return address
push( ret_addr );
ret();
end biggest;
static
x: int16 :=0;
y: int16 :=0;
z: int16 :=0;
begin Biggestm;
// Get user input
stdout.put( "Gimme X: ");
stdin.get( x );
stdout.put( "Gimme Y: ");
stdin.get( y );
stdout.put( "Gimme Z: ");
stdin.get( z );
// Push addresses of x, y, z onto the stack
lea( ebx, z );
push( ebx );
lea( ebx, y );
push( ebx );
lea( ebx, x );
push( ebx );
call biggest;
// Output the results
stdout.put( "After biggest, X =", x,", Y =", y,", Z =", z, nl );
end Biggestm;
Can you fix this for me? Where did I go wrong?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!