Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 null byte (1??0'). Write an
assembly function strlen_mine in lab6. 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 64-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. i.e. this is probably a useful comparison to
make (adjusting the register name as you like):
cmpb $0,(%rdi)
The provided tests. c contains some tests of this and the next function. It #includes the data from test_strings.c as test cases.
The test_strings.c does not need to be included on the command line:
gcc -Wall -Wpedantic -std=c17-march=haswell -03 tests.c lab6.S }
&&./a.out
UTF-8 String Length
C strings are not typically treated like encoded Unicode characters, but they could be. Write an assembly function strlen_ut f8 in
lab6. S that calculates the number of Unicode characters in a byte array, treating it as UTF-8-encoded text.
This will be similar to the previous question, except you should not count bytes that are UTF-8 continuation bytes: any byte in the form
10xxxxxx 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 bitwise-AND with to keep exactly the bits you care about. In
this case, 11000000 :
0bxxyyyyyy
& 0b11000000
=0bx000000
And then make a comparison for equality. WRITE ASSEMBLY CODE FOR THIS FUNCTION!!!!!!!!! IT SHOULD PASS THE TESTS.C WHICH IS ALSO PROVIDED
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions