Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PROGRAM 1 4 : strlen Function Write an HLA Assembly language program that implements the following function: procedure strlen ( baseStringAddress: dword ) ; @nodisplay;
PROGRAM : strlen Function
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
This is what I have so far:
File: strlenProgram.hla
program strlenProgram;
#include "stdlib.hhf;
#includecsstring.hla" ;
procedure strlen baseStringAddress: dword ; @nodisplay; @noframe;
static
dStringLength : int;
begin strlen;
Initialize the string length to
mov dStringLength ;
Loop through the string until null character is found
strlenLoop:
movbaseStringAddress AL ; Load the current character
cmp AL; Compare it with null character
je strlenEnd; If null, end the loop
inc dStringLength ; Increment the string length
inc baseStringAddress ; Move to the next character
jmp strlenLoop; Repeat the loop
strlenEnd:
mov dStringLength, AL ; Return the string length in AL
ret;
end strlen;
const
nullchar : byte :;
static
inputBuffer: byte; Buffer to hold user input
stringData : byte; Buffer for string data initially empty
stringDataLen : uns :; Max number of chars the string can hold excluding NULL
stringLength: byte;
begin strlenProgram;
Prompt the user to enter some text
stdout.put "Please enter some text to work with and hit Return!", nl ;
Read input into stringData using gets
Load effective address of stringData into EAX
mov&inputBuffer,eax;
push EAX ;
push stringDataLen ;
call gets;
Call the strlen function to calculate the string length
lea EAX, stringData ; Load effective address of stringData into EAX
push EAX ;
call strlen;
Store the returned length
mov AL stringLength ;
Display the result
stdout.put "The String You Entered: stringData, Has Length stringLength, nl ;
end strlenProgram;
Can you fix this? What can I do to make it work?
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