Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an HLA Assembly language program that implements a function which correctl

ID: 3914568 • Letter: W

Question

Write an HLA Assembly language program that implements a function which correctly identifies which of three parameters is neither the largest nor the smallest and returns a boolean value in AL (1 when all three values are equal; 0 otherwise). This function should have the following signature:

Shown below is a sample program dialogue.

Feed Me X: 215
Feed Me Y: 480
Feed Me Z: 91
215 in the middle!
AL = 0

Feed Me X: 0
Feed Me Y: 0
Feed Me Z: 0
X and Y and Z are all equal!
AL = 1

Feed Me X: 221
Feed Me Y: 100
Feed Me Z: 40
100 is in the middle!
AL = 0

Explanation / Answer

Firstly take the input

begin middleFinder;
stdout.put( "Feed Me X: " );
stdin.get( xdata );
stdout.put( "Feed Me Y: " );
stdin.get( ydata );
stdout.put( "Feed Me Z: " );
stdin.get( zdata );

mov( xdata, BX );
push( BX );

mov( ydata, BX );
push( BX );

mov( zdata, BX );
push( BX );

call findMiddle;// this is the function to find the middle value
stdout.puti16( DX );
stdout.put( " is in the middle!" );
stdout.newln();

end middleFinder;

Defining the function to find the middle value. You will need to compare the values x with y then compare the greater of the two with z to check which is smaller. This will give you the middle value.

mov(x, DX);
cmp(y, DX);
je XareYequal;
cmp(y, DX);
jl YisGreater;
cmp(y, DX);
jg XisGreater;

XareYequal:
mov(y, BX);
cmp(z, BX);
je AllEqual;

//if the AllEqual jump doesn't occur, it means that at least one value is different from the others, so AL = 0
stdout.put("AL = 0");

XisGreater:
mov(z,BX);
cmp(x,BX);
jl MovXtoDX;
jg MovZtoDX;


YisGreater:
mov(y, BX);
cmp(z, BX);
jl MovYtoDX;
jg MovZtoDX;

After finding the middle value move it into the register DX. So when the instruction pointer returns back to the middleFinder procedure after completing the findMiddle procedure the value in DX will be printed to give the middle value.

AllEqual is defined as the address to jump to when all the variables are equal. So "X and Y and Z are all equal" should be printed here. Along with "AL = 1".

AllEqual:
stdout.put("All three values are equal");
stdout.put("AL = 1");
jmp ExitSequence;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote