Question: endsInSeven Write an HLA Assembly language program that implements a function which correctly identifies if both values end in seven and return returns a boolean

endsInSeven
Write an HLA Assembly language program that implements a function which correctly identifies if both values end in seven and return returns a boolean value in AL (1 when both end in seven; 0 otherwise).(HINT: You can perform this operation by repetitively subtracting ten from the value. If you wind up hitting seven before you hit zero, then the value originally ended in seven)
This function should have the following signature:
procedure endsInSeven( x: int16; y: int16); @nodisplay; @noframe;
In order to receive full credit, you must pass your parameters on the run-time stack and be preventing register corruption by preserving and then restoring the value of any register your function touches. This rule applies to every register except for AL which is being used to pass an answer back to the calling code.
Feed Me X:5
Feed Me Y:13
Not ending in seven. AL =0
Feed Me X: 57
Feed Me Y: 27
Both ending in seven. AL =1
Feed Me X:5
Feed Me Y: 27
Not ending in seven. AL =0
I want it in HLA and be able to run it in HLA_176.bat and I provide instructions and sample program:
program RecursiveThree;
#include( "stdlib.hhf");
static
iDataValue1 : int16 :=0;
iDataValue2 : int16 :=0;
////////////////////////////
// Function isDivideableByThreeRec
////////////////////////////
procedure isDivideableByThreeRec( n : int16); @nodisplay; @noframe;
static
returnAddress : dword;
temp: int16;
begin isDivideableByThreeRec;
// this procedure returns its answer in EAX, so we don't need to save that
// register. No other register is used, so no other registers need to be saved
////////////////// get params from stack ///////////////////
pop( returnAddress );
pop( temp ); //padding - stack must be 32-bit aligned
pop( n );
push( returnAddress );
cmp( n,0); //if n=0, return true =1
je ReturnTrue;
cmp( n,0); //if n0, return false =0
jle ReturnFalse;
jmp Neither; //else isDivideableByThreeRec( n-3)
ReturnTrue:
mov(1, EAX ); //return true
jmp ExitSequence;
ReturnFalse:
mov(0, EAX ); //return false
jmp ExitSequence;
Neither:
sub(3, n ); //n-3
// calling isDivideableByThreeRec( n-3);
push( n );
push( temp ); // padding
call isDivideableByThreeRec;
jmp ExitSequence;
ExitSequence:
ret();
end isDivideableByThreeRec;
////////// main program //////////////
begin RecursiveThree;
stdout.put( "Gimme an n: ");
stdin.get( iDataValue1);
push( iDataValue1);
push( iDataValue2); //padding
call isDivideableByThreeRec;
// this function leaves the answer in EAX
cmp(EAX,1);
je ISDIVISIBLE;
jmp NOTDIVISIBLE;
ISDIVISIBLE:
stdout.put("true",nl);
jmp EndProgram;
NOTDIVISIBLE:
stdout.put("false",nl);
jmp EndProgram;
stdout.newln();
EndProgram:
Assembly Language Instructions
Instruction Syntax Description MOV mov ( source, dest ); dest = source; ADD add ( source, dest ); dest += source; SUB sub( source, dest ); dest -= source; SHL shl( count, dest ); shuffles left a total of count bits in dest operand; sets carry when count=1 SHR shr( count, dest ); shuffles right a total of count bits in dest operand; sets carry when count=1 SAR sar( count, dest ); shuffles right a total of count bits in dest operand; sets carry when count=1; leaves H.O. bit unchanged ROL rol ( count, dest ); rotates left a total of count bits in dest operand; sets carry when count=1 ROR ror( count, dest ); rotates right a total of count bits in dest operand; sets carry when count=1 NOT not( dest ); inverts the bits of the dest operand AND and( source, dest ); bitwise logical AND; result placed in dest operand OR or( source, dest ); bitwise inclusive OR; result placed in dest operand XOR xor( source, dest ); bitwise exclusive OR; result placed in dest operand LAHF lahf(); pushes the lower 8 bits of EFLAGS register into AH INC inc( operand ); operand = operand +1; DEC dec ( operand ); operand = operand -1; CMP cmp( lhs, rhs ); sets EFLAGS as if lhs-rhs was performed; does not change the value of either operand TEST test( operand1, operand2); sets EFLAGS as if AND( operand1, operand2) was performed; does not change the value of either operand NEG neg ( dest ); JMP jmp label; jmp(32bit_register); jmp( dword ); unconditional transfer of control. Note the inconsistent use of parentheses. SETcc setcc(8bit_operand); reads an EFLAG bit into a byte operand. Mnemonics listed below.
Available Datatypes
int8
int16
int32
uns 8
uns16
uns 32
boolean
Available I/O
Routines
stdout.put
stdout.puti8
stdout.puti16
stdout.puti32
stdout.putb
stdout.putw
stdout.putd
stdout.putuns8
stdout.putuns16
stdout.putuns32
stdout.newln
JMP
jmp label; jmp (32bit_register); jmp( dword);
unconditional transfer of control. Note the inconsistent use of parentheses.
SETcC setcc(8bit_operand);
reads an EFLAG bit into a byte operand. Mnemonics listed below.
JCc jcc label;
transfers control to label when condition is met. Mnemonics listed below.
endsInSeven Write an HLA Assembly language

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 Programming Questions!