Write an HLA Assembly language program that implements a function which correctl
ID: 3858485 • Letter: W
Question
Write an HLA Assembly language program that implements a function which correctly prints out which of the three passed parameters is in the middle (that is, not the biggest and not the smallest value...) and returns a boolean value in AL (1 when all three values are equal; 0 otherwise). This function should have the following signature:
procedure middleFinder( x: int16; y : int16; z : int16 ); @nodisplay; @noframe;
Shown below is a sample program dialogue.
Feed Me X: 215
Feed Me Y: 220
Feed Me Z: 241
220 is 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: 54
Feed Me Y: 120
Feed Me Z: 100
100 is in the middle!
AL = 0
Explanation / Answer
Answer for the given Question:
See the below code is having the three conditions checking with the problem statements.
program FinderProgram;
#include( "stdlib.hhf" );
static
iValue1: int16:=0;
iValue2: int16:=0;
iValue3: int16:=0;
procedure middlefinder( x: int16; y: int16; z: int16 ); @nodisplay; @noframe;
static
iReturnAddress: dword;
iMid: int16;
iTemporary: int16;
iRegisterValue: dword;
begin middlefinder;
mov(EBX, iRegisterValue);
pop(iReturnAddress);
pop(iTemporary);
pop(iTemporary);
mov(iTemporary, BX);
mov(BL, z);
pop(iTemporary);
mov(iTemporary, BX);
mov(BL, a);
push(iReturnAddress);
push(iRegisterValue);
mov(x, DH); //
cmp(y, DH);
je XYequal;
cmp(y, DH);
jl less; //if Y is less than X, compare against Z. whichever is more there gets compared to X and whichever is more there is the middle
cmp(y, DH);
jg great;
XYequal
mov(y, BX);
cmp(z, BX);
je equal;
jmp ExitSequence;
equal:
stdout.put("All three values are equal");
stdout.out("AL=1");
jmp ExitSequence;
less:
mov(0, BX);
mov(y, BX);
cmp(z, BX); //if z is greater than Y, compare to X. if z is less than Y, than
Y is middle
jg greaterthany;
jl Yismiddle;
greaterthany;
mov(0,BX);
mov(z, BX);
cmp(x,BX);
jg Zismiddle;
jl Xismiddle;
Yismiddle:
mov(y, DH);
jmp ExitSequence;
Zismiddle:
mov(z, DH);
jmp ExitSequence;
Xismiddle:
mov(x, DH);
jmp ExitSequence;
ExitSequence:
pop(EBX);
ret();
end middlefinder;
begin numberFinder;
stdout.put( "Feed Me X: " );
stdin.get( iValue1 );
stdout.put( "Feed Me Y: " );
stdin.get( iValue2 );
stdout.put( "Feed Me Z: " );
stdin.get( iValue3 );
mov( 0, BX );
mov( iValue1, BL );
push( BX );
mov( 0, BX );
mov( iValue2, BL );
push( BX );
mov( 0, BX );
mov( iValue3, BL );
push( BX );
mov( 0, BX );
push( BX );
call middleFinder;
stdout.put( "The value in the middle is " );
stdout.puti8( DH );
stdout.newln();
end numberFinder;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.