Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help with the following Program in HLA: PLEASE RUN YOUR CODE AND SHOR PROOF ( SCREENSHOTS ) OF THAT IT ACTUALLY WORKS. PROGRAM 1
Need help with the following Program in HLA: PLEASE RUN YOUR CODE AND SHOR PROOFSCREENSHOTS OF THAT IT ACTUALLY WORKS. 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 NOTE THAT THERE IS AN IMPLEMENTATION OF STRINGS INPUT AND OUTPUT: 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" ;
THIS IS THE FILE FOR csstring.hla:
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
cmp DI;
je getsEndLoop;
cmp EAX ECX DH ;
je getsEndLoop;
mov EAX ECX DL ; move character desired
mov DLtype char EBX ;
inc ECX ;
inc EBX ;
dec DI ;
jmp getsRepeatLoop;
getsEndLoop:
set ending null
mov DHtype char EBX ;
release sData
strfree sData ;
exit sequence
restore registers
pop EAX ;
pop EBX ;
pop ECX ;
pop DX ;
pop DI ;
transfer control
ret;
end gets;
this procedure prints the contents of a nullterminated string
the string parameter is being passed by its base address
procedure puts baseStringAddress: dword ; @nodisplay; @noframe;
uses the register EBX
static
dReturnAddress : dword;
wDXRegister : word :; preserve DX
dEBXRegister : dword :; preserve EBX
begin puts;
entry sequence
preserve registers
mov EBX, dEBXRegister ;
mov DX wDXRegister ;
pop dReturnAddress ; This is the return address
pop EBX ; This is the base address of the string
push back the return address
push dReturnAddress ;
preserve registers
push dEBXRegister ;
push wDXRegister ;
begin subtask
print nullterminated string
mov DX ; EBX will be the address of stringi
putsRepeatLoop:
cmp EBX DH ;
je putsEndLoop;
stdout.putc EBX ;
inc EBX ;
jmp putsRepeatLoop;
putsEndLoop:
exit sequence
restore registers
pop DX ;
pop EBX ;
transfer control
ret;
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