Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 : 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 : int; var y : int; var z : int; @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:
Gimme Y:
Gimme Z:
After biggest, X Y Z
Gimme X:
Gimme Y:
Gimme Z:
After biggest, X Y Z
Hint: Even though the parameters are listed as int HLA expects you will pass them as memory addresses, requiring a full bit value. So you'll have to use extended registers to hold the parameters, not 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:int; var y:int; var z:int; @nodisplay; @noframe;
static
retaddr: dword; Variable to store the return address
xx: int;
yy: int;
zz: int;
begin biggest;
Save the return address and load the addresses of x y z from the stack
pop retaddr ; Pop the return address into retaddr
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
movebx xx ; Value of x into xx
movecx yy ; Value of y into yy
movedx zz ; Value of z into zz
movxxax;
movyybx;
movzzcx;
cmp bx ax ;
jg setyaslargest;
cmp cx ax ;
jg setzaslargest;
jmp updateall;
setyaslargest:
cmp cx bx ;
jg setzaslargest;
mov yy xx ;
jmp updateall;
setzaslargest:
mov zz xx ;
updateall:
mov xxebx;
mov xxecx;
mov xxedx;
Push back the return address
push retaddr ;
ret;
end biggest;
static
x: int :;
y: int :;
z: int :;
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started