Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Writing an X86–64 Assembly Language Program

Part VI: How to Determine String Length

Tony Oreglia
Dev Genius
Published in
2 min readNov 28, 2021

--

Photo by Brett Jordan on Unsplash

This guide is part six of a series

How to Calculate String Length

In order to calculate the length of a string, we’ll first need to know what determines the end of a given string.

Strings in memory are represented as a pointer. The location pointed at is a byte of data representing a character followed by additional characters contiguous in memory. The important point is that this sequence of bytes is terminated by the byte 0x00. This is called the zero-termination character which is one method of terminating a string (C uses this approach, for example). There are methods of encoding strings that we won’t cover here.

For example, the string “HELLO WORLD!” would hold the following values in memory (binary values represented in hexadecimal):

So the length can be determined by looping through each byte of memory in a string until the zero-termination character is reached. Here is an initial implementation of how this may be implemented, but if you look closely there are a couple of bugs, see if you can identify the issues with this code snippet.

--

--

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Tony Oreglia

Fullstack Software Engineer living in Lisbon. I write about coding and productivity. I'm building a secure journaling space at https://jumblejournal.org

Responses (2)

Write a response