Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with the following program and this is the code that I have so far. Write an HLA Assembly language program that implements

I need help with the following program and this is the code that I have so far.
Write an HLA Assembly language program that implements the following function:
procedure strlen( baseStringAddress: dword ); @nodisplay; @noframe;
This function should return in AL the number of characters in the string parameter, passed by its base address. Here is a sample program dialogue:
Feed Me: asdfasdf
The String You Entered: asdfasdf Has Length =8
Feed Me: asdf
The String You Entered: asdf Has Length =4
Keep in mind the following: String I/O Routines
In effect to assist you in working with strings, I authored the function gets and the procedure puts. As you can see from the example above, "gets" is used to read a string, while "puts" is used to write a string. These routines support the following syntax:
gets( baseStringAddress : dword; maxLength : uns16);
puts( baseStringAddress : dword );
Each routine needs to be passed a nicely allocated and null-terminated string by sending its base address (that is, index 0 of the array). In addition, gets takes a second parameter which tells it how many characters it can legally ramm into the array before it overwrites its allocated size.
Both of these routines are provided in the file: cs17string.hla. By stating in your program,
#include("cs17string.hla" );
you'll acquire the implementation of these routines. You'll want to use this file, it's packed as a .zip file that you will need to unzip. Place the file wherever your source with the #include statement lives. I don't think you need to see the implemention file cs17string.hla. but here is a copy of my code that I have been working on. please help me I am really stuck.
program StringProgram;
#include( "stdlib.hhf");
#include("cs17string.hla" );
static
stringData : dword;
count : int32 :=0;
procedure countNonLowerCase( stringData : dword ); @nodisplay; @noframe;
static
dReturnAddress : dword;
temp : int32;
letter : int32;
begin countNonLowerCase;
pop( dReturnAddress ); // this is the return address
pop(temp);
pop(EAX);
pop(EBX);
pop(ECX);
// push back the return address
push( dReturnAddress );
// preserve registers
push(EAX);
push(EBX);
push(ECX);
LoopStart:
mov(letter,[EAX]); // Move the character at the current address to the letter variable
cmp(letter,0); // Compare the character to zero (end of string)
je EndLoop; // If it's zero, jump to the EndLoop section
// Check if the character is lowercase
mov(EAX, letter); // Move the character to EAX
cmp(letter,'z'); // Compare the character to 'z'
ja NotLowerCase; // If it's above 'z', it's not lowercase
cmp(letter,'a'); // Compare the character to 'a'
jb NotLowerCase; // If it's below 'a', it's not lowercase
add(1, count); // Increment the count of lowercase characters
NotLowerCase:
add(1,EAX); // Move to the next character
jmp LoopStart; // Jump back to the beginning of the loop
EndLoop:
// leave the count in EAX
mov(count, EAX);
// restore the registers used
pop(letter);
pop(temp);
pop(EAX);
ret();
end countNonLowerCase;
begin StringProgram;
stdout.put( "Please enter a string to process", nl );
// Allocate memory for the string
malloc(80);
mov(EAX, stringData);
// Read a string from the user
mov(stringData, EAX);
mov(80, CX);
push(CX);
call gets;
// Print the entered string
stdout.put("----> Here is the string you entered: ");
mov(stringData, EAX);
push(EAX);
call puts;
stdout.newln();
// Call the countNonLowerCase function
mov(stringData, EAX);
push(EAX);
call countNonLowerCase;
// Show the results
stdout.put( "Number of lowercase characters: ");
stdout.put( EAX );
stdout.newln();
end StringProgram;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions