PROGRAM 6: Same Write an HLA Assembly language program that implements a function which correctly identifies when all four parameters are the same and returns a boolean value in AL (1 when all four values are equal; 0 otherwise). This function should have the following signature:
procedure theSame( w:int16; x:int16; y:int16; z:int16 ); @nodisplay; @noframe;
Shown below is a sample program dialogue.
Feed Me W: 215 Feed Me X: 215 Feed Me Y: 480 Feed Me Z: 91 Not the same. AL = 0
Feed Me W: 0 Feed Me X: 0 Feed Me Y: 0 Feed Me Z: 0 Same. AL = 1
Feed Me W: 0 Feed Me X: 221 Feed Me Y: 100 Feed Me Z: 40 Not the same. AL = 0
**My output are almost correct but when I entered
w : 2
x : 2
y : 2
z : 1
"the same" instead of "NOT the same"
Please help with any thoughts that I might be missing.** I am not sure if register push and pop are the issue.
program Same;
#include ("stdlib.hhf");
static
iDataValue1 : int16 := 0;
iDataValue2 : int16 := 0;
iDataValue3 : int16 := 0;
iDataValue4 : int16 := 0;
procedure theSame( w : int16; x : int16; y : int16; z : int16); @nodisplay; @noframe;
static
returnAddress : dword;
temp: int16;
begin theSame;
pop (returnAddress);
pop (temp);
pop (z);
pop (y);
pop (x);
pop (w);
push (returnAddress);
push (BX);
//Perform Subtask
mov (z, BX);
cmp (y, BX); // Compare z & y
jne ReturnZero;
mov (y, BX);
cmp (x, BX); // Compare y & x
je ReturnOne;
jmp ReturnZero;
mov (x, BX);
cmp (w, BX); // Compare x & w
je ReturnOne;
jmp ReturnZero;
ReturnOne:
mov (1, AL);
jmp ExitSequence;
ReturnZero:
mov (0, AL);
jmp ExitSequence;
ExitSequence:
pop (BX);
ret();
end theSame;
begin Same;
stdout.put ("Feed Me W: ");
stdin.get (iDataValue1);
stdout.put ("Feed Me X: ");
stdin.get (iDataValue2);
stdout.put ("Feed Me Y: ");
stdin.get (iDataValue3);
stdout.put ("Feed Me Z: ");
stdin.get (iDataValue4);
push (iDataValue1);
push (iDataValue2);
push (iDataValue3);
push (iDataValue4);
call theSame;
cmp (AL, 1);
je NumbersAreSame;
jmp NumbersAreDifferent;
NumbersAreSame:
stdout.put ("Same. AL = 1");
jmp EndProgram;
NumbersAreDifferent:
stdout.put ("Not the same. AL = 0");
stdout.newln();
jmp EndProgram;
EndProgram:
end Same;