Question: C - Style String Length The strlen function in C calculates the length of a C string: a sequence of bytes that's terminated by a
CStyle String Length
The strlen function in calculates the length of a string: a sequence of bytes that's terminated by a null byte Write an
assembly function strlenmine in lab S that does this: takes a pointer to a byte array and counts the number of bytes before getting
to a null zero byte.
Remember that we're working with bytes here not bit values and that if you have a memory address pointer in a register, you can
follow the pointer to inspect that memory location by putting the register name in parenthesis. ie this is probably a useful comparison to
make adjusting the register name as you like:
cmpb $rdi
The provided tests. c contains some tests of this and the next function. It #includes the data from teststrings.c as test cases.
The teststrings.c does not need to be included on the command line:
gcc Wall Wpedantic stdcmarchhaswell tests.c labS
&&aout
UTF String Length
C strings are not typically treated like encoded Unicode characters, but they could be Write an assembly function strlenut in
lab S that calculates the number of Unicode characters in a byte array, treating it as UTFencoded text.
This will be similar to the previous question, except you should not count bytes that are UTF continuation bytes: any byte in the form
xxxxxx is a continuation byte. You will need to extract those specific bits from each byte to see if they are the "right" value for a
continuation byte.
If you want to examine specific bits of an integer, you can construct a value to bitwiseAND with to keep exactly the bits you care about. In
this case, :
bxxyyyyyy
& b
And then make a comparison for equality. WRITE ASSEMBLY CODE FOR THIS FUNCTION!!!!!!!!! IT SHOULD PASS THE TESTS.C WHICH IS ALSO PROVIDED
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
