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

Create an HLA function that loops through a single string argument and verifies

ID: 3576250 • Letter: C

Question

Create an HLA function that loops through a single string argument and verifies that the letters are in the pattern of a single lowercase letter followed by a single UPPERCASE letter, repeatedly through the string. This function should have the following signature:

procedure isLowerUpper( stringData : dword ); @nodisplay; @noframe;

This function should return into EAX an int32 value which is either true or false, 1 or 0. To receive full credit, your isLowerUpper( ) procedure must not allocate any storage.

To further explain myself, the following strings all have the isLowerUpper pattern I am looking for:

"aA"
"aBbCc"
"a"
"aBa"
"aBbCa"

To further explain myself, the following string do NOT have the isUpperLower pattern I am looking for:

"0"
"aA1"
"aAAAAA"
"aAaaaaa"
"aAbBcC-+"

You must use the utility functions gets and puts provided here ( http://www.howardstahl.com/cs17/cs17Final.hla ) by downloading this file. These are the some of the same routines you used in Unit 15. Once you acquire the file, you can include it in your code by saying: #include( "cs17Final.hla" );

Your function should replicate the following C code:

bool isLowerUpper( char * stringData )
{

int i = 0;
bool result = true; // hope for the best...
bool upperTurn = false;
while ( stringData[ i ] != NULL )
{
int letter = stringData[ i ];
if (upperTurn)
{
// uppercase letters are ASCII(65) thru ASCII(90)
if (letter<65 || letter>90) result = false;
}
else
{
// lowercase letters are ASCII(97) thru ASCII(122)
if (letter>122 || letter<97) result = false;
}
upperTurn = !upperTurn;
i = i + 1;

}

return( result );

}

IN ORDER TO RECEIVE FULL CREDIT, YOU MUST USE THE TEMPLATE SOLUTION SHOWN BELOW. Of course, you will need to add code to the function to implement the desired algorithm explained above. In addition, you will need to prepare and push the parameters to the function.


// String Parameter Template Solution For CS 17 Final
// CS 17 Students must use this template as the basis for their solution.
// I hope it will help simplify your development task.

// Please look at the two TODO: notes below

program StringProgram;

#include( "stdlib.hhf" );
// The file cs17Final.hla is downloadable from the hyperlink shown above.
// Place it in the same folder as this hla file you are working on

#include( "cs17Final.hla" );

static
stringData : dword;
answer : int32;

// TODO: CS 17 Students add code below to implement this function
// Several hints are supplied

procedure isLowerUpper( stringData : dword ); @nodisplay; @noframe;
static
dReturnAddress : dword;
begin isLowerUpper;
// TODO: CS 17 Students will need to preserve registers
pop( dReturnAddress );
// this is the return address

// push back the return address
push( dReturnAddress );

// preserve registers

// begin sub-task

// leave the count in EAX

// restore the registers used

ret();

end isLowerUpper;

begin StringProgram;

stdout.put( "Please enter a string to process", nl );

// this code allocates a string of size 80

mov( @size( int8 ), AL );
mov( 80, BL );
inc( BL );
mul( BL );
mov( 0, EBX );
mov( AX, BX );
malloc( EBX );
mov( EAX, stringData );

// let's try reading a value into the string
mov( stringData, EAX );
push( EAX );
mov( 80, CX );
push( CX );

call gets;

// print the string

stdout.put( "----> here is the string you entered: " );

mov( stringData, EAX );
push( EAX );
call puts;

stdout.newln();

// initialize EAX before calling the function.

mov( 0, EAX );


// TODO: send a string parameter to the function

call isLowerUpper;
mov( EAX, answer );


// show the results
stdout.put( "after isLowerUpper--- result=" );
stdout.put( answer );
stdout.newln();

end StringProgram;

Explanation / Answer

bool isLowerUpper( char * stringData )
{

int i = 0;
bool result = true; // hope for the best...
bool upperTurn = false;
while ( stringData[ i ] != NULL )
{
int letter = stringData[ i ];
if (upperTurn)
{
// uppercase letters are ASCII(65) thru ASCII(90)
if (letter<65 || letter>90) result = false;
}
else
{
// lowercase letters are ASCII(97) thru ASCII(122)
if (letter>122 || letter<97) result = false;
}
upperTurn = !upperTurn;
i = i + 1;

}

return( result );

}

IN ORDER TO RECEIVE FULL CREDIT, YOU MUST USE THE TEMPLATE SOLUTION SHOWN BELOW. Of course, you will need to add code to the function to implement the desired algorithm explained above. In addition, you will need to prepare and push the parameters to the function.


// String Parameter Template Solution For CS 17 Final
// CS 17 Students must use this template as the basis for their solution.
// I hope it will help simplify your development task.

// Please look at the two TODO: notes below

program StringProgram;

#include( "stdlib.hhf" );
// The file cs17Final.hla is downloadable from the hyperlink shown above.
// Place it in the same folder as this hla file you are working on

#include( "cs17Final.hla" );

static
stringData : dword;
answer : int32;

// TODO: CS 17 Students add code below to implement this function
// Several hints are supplied

procedure isLowerUpper( stringData : dword ); @nodisplay; @noframe;
static
dReturnAddress : dword;
begin isLowerUpper;
// TODO: CS 17 Students will need to preserve registers
pop( dReturnAddress );
// this is the return address

// push back the return address
push( dReturnAddress );

// preserve registers

// begin sub-task

// leave the count in EAX

// restore the registers used

ret();

end isLowerUpper;

begin StringProgram;

stdout.put( "Please enter a string to process", nl );

// this code allocates a string of size 80

mov( @size( int8 ), AL );
mov( 80, BL );
inc( BL );
mul( BL );
mov( 0, EBX );
mov( AX, BX );
malloc( EBX );
mov( EAX, stringData );

// let's try reading a value into the string
mov( stringData, EAX );
push( EAX );
mov( 80, CX );
push( CX );

call gets;

// print the string

stdout.put( "----> here is the string you entered: " );

mov( stringData, EAX );
push( EAX );
call puts;

stdout.newln();

// initialize EAX before calling the function.

mov( 0, EAX );


// TODO: send a string parameter to the function

call isLowerUpper;
mov( EAX, answer );


// show the results
stdout.put( "after isLowerUpper--- result=" );
stdout.put( answer );
stdout.newln();

end StringProgram;

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