Answered step by step
Verified Expert Solution
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
Feed Me: asdf
The String You Entered: asdf Has Length
Keep in mind the following: String IO 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 : uns;
puts baseStringAddress : dword ;
Each routine needs to be passed a nicely allocated and nullterminated string by sending its base address that is index 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: csstring.hla. By stating in your program,
#includecsstring.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 csstring.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;
#includecsstring.hla" ;
static
stringData : dword;
count : int :;
procedure countNonLowerCase stringData : dword ; @nodisplay; @noframe;
static
dReturnAddress : dword;
temp : int;
letter : int;
begin countNonLowerCase;
pop dReturnAddress ; this is the return address
poptemp;
popEAX;
popEBX;
popECX;
push back the return address
push dReturnAddress ;
preserve registers
pushEAX;
pushEBX;
pushECX;
LoopStart:
movletterEAX; Move the character at the current address to the letter variable
cmpletter; 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
movEAX letter; Move the character to EAX
cmpletterz; Compare the character to z
ja NotLowerCase; If it's above z it's not lowercase
cmplettera; Compare the character to a
jb NotLowerCase; If it's below a it's not lowercase
add count; Increment the count of lowercase characters
NotLowerCase:
addEAX; Move to the next character
jmp LoopStart; Jump back to the beginning of the loop
EndLoop:
leave the count in EAX
movcount EAX;
restore the registers used
popletter;
poptemp;
popEAX;
ret;
end countNonLowerCase;
begin StringProgram;
stdout.put "Please enter a string to process", nl ;
Allocate memory for the string
malloc;
movEAX stringData;
Read a string from the user
movstringData EAX;
mov CX;
pushCX;
call gets;
Print the entered string
stdout.put Here is the string you entered: ;
movstringData EAX;
pushEAX;
call puts;
stdout.newln;
Call the countNonLowerCase function
movstringData EAX;
pushEAX;
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started