Task: Displaying the Length of a String
Navigate to tasks/string-print-len/support/.
The program print_string_len.asm displays the length of a string using the PRINTF32 macro. The calculation of the length of the mystring string occurs within the program (it is already implemented).
Implement the program to display the length of the string using the printf function.
At the end, you will have the length of the string displayed twice: initially with the PRINTF32 macro and then with the external function call printf.
NOTE: Consider that the
printfcall is of the formprintf("String length is %u\n", len);. You need to construct the stack for this call.The steps to follow are:
- Mark the symbol
printfas external.- Define the format string
"String length is %u", 10, 0.- Make the function call to
printf, i.e.:
- Put the two arguments on the stack: the format string and the length.
- Call
printfusingcall.- Restore the stack.
The length of the string is found in the
ecxregister.
To test the implementation, enter the tests/ directory and run:
make check
In case of a correct solution, you will get an output such as:
./run_all_tests.sh
test_length_zero ........................ passed ... 20
test_length_small ........................ passed ... 40
test_length_large ........................ passed ... 40
Total: 100/100
If you’re having trouble solving this exercise, go through this reading material.