Question: Create an HLA function that loops through a single string argument and verifies that last character found in the string is a capital Z .
Create an HLA function that loops through a single string argument and verifies that last character found in the string is a capital Z This function should have the following signature:
procedure endsWithZ stringData : dword ; @nodisplay; @noframe;
This function should return into EAX an int value which is either true or false, or To receive full credit, your endsWithZ function must not allocate any storage.
You must use the utility functions gets and puts provided here Download hereby downloading this file. Unzip it to find the hla file inside. These are the some of the same routines you used in Unit Once you acquire the file, you can include it in your code by saying: #includecsstring.hla" ;
Your function should replicate the following C code:
bool endsWithZ char stringData
int i ;
char letter ;
while stringData i NULL
loop the last character
letter stringData i ;
i i ;
return letter Z;
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 push the parameters to the function.
String Parameter Template Solution For CS Final
CS Students must use this template as the basis for their solution.
Please look at the two TODO: notes below
program StringProgram;
#include "stdlib.hhf;
The file csstring.hla is downloadable from the hyperlink shown above.
Place it in the same folder as this hla file you are working on
#includecsstring.hla" ;
static
stringData : dword;
answer : int;
TODO: CS Students add code below to implement this function
Several hints are supplied
procedure endsWithZ stringData : dword ; @nodisplay; @noframe;
static
dReturnAddress : dword;
begin endsWithZ;
TODO: CS Students will need to preserve registers
pop dReturnAddress ;
TODO: CS Students need to get stringData off the stack
push back the return address
push dReturnAddress ;
preserve registers
begin function implementation
leave the answer in EAX
restore the registers used
ret;
end endsWithZ;
begin StringProgram;
stdout.put "Please enter a string to process", nl ;
this code allocates a string of size
mov @size int AL ;
mov BL ;
inc BL ;
mul BL ;
mov EBX ;
mov AX BX ;
malloc EBX ;
mov EAX, stringData ;
let's try reading a value into the string
mov stringData, EAX ;
push EAX ;
mov 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 EAX ;
TODO: CS Students need to pass a string parameter to the function
call endsWithZ;
mov EAX, answer ;
show the results
stdout.put "after endsWithZ result;
stdout.put answer ;
stdout.newln;
end StringProgram;
File: csstring.hla
Provides the string manipulation functions puts and gets for students to use
this procedure prompts for a string, writing atmost maxLength bytes into a previously declared array
this maxLength should not include the terminating null in its count
the string parameter is being passed by its base address
procedure gets baseStringAddress: dword; maxLength : uns; @nodisplay; @noframe;
uses the register DX DI ECX, EBX and EAX
static
dReturnAddress : dword;
wDIRegister : word :; preserve DI
wDXRegister : word :; preserve DX
dEAXRegister : dword :; preserve EAX
dEBXRegister : dword :; preserve EBX
dECXRegister : dword :; preserve ECX
I am trying to hide the datatype string for use by CS
sData : string;
begin gets;
entry sequence
preserve registers
mov EBX, dEBXRegister ;
mov EAX, dEAXRegister ;
mov DX wDXRegister ;
mov DI wDIRegister ;
pop dReturnAddress ; This is the return address
pop DI ; This is the max length able to read
pop EBX ; This is the base address of the string
push back the return address
push dReturnAddress ;
preserve registers
push wDIRegister ;
push wDXRegister ;
push dECXRegister ;
push dEBXRegister ;
push dEAXRegister ;
begin subtask
prompt for a string
stdin.flushInput;
stdin.agets; allocate and read string into EAX
mov EAX, sData ; save address so it can be free'd later
copy data in sData over into starting at EBX
mov DX ; EBX will be the address of stringi
mov ECX ;
getsRepeatLoop:
read no more than DI chars
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
