ReePrime
Implement strlen for Null-Terminated Strings in x86-64 Assembly (YASM)

Hosted by Dailymotion. For legal issues report at the Copyright Center, report us on DMC, or use the Instant Removal tool.

Implement strlen for Null-Terminated Strings in x86-64 Assembly (YASM)

N
Neural Lantern

9 Views • Feb 08, 2026

Description

Learn how to write your own strlen function in x86-64 assembly (YASM) that finds the length of a null-terminated string using a simple while loop.

We preserve the proper registers, follow the ABI, compute the length safely, and then use that length to print the full string efficiently with a single sys_write call.

Great for anyone studying low-level programming, operating systems, or wanting to understand C strings at the assembly level.

00:00:00 Introduction to implementing string length in assembly
00:00:25 What are null-terminated strings and why they exist
00:01:59 Pre-computing length vs using null terminators
00:02:53 How the null byte (0) actually works in memory
00:04:14 Naive approach: printing one character at a time
00:05:20 Goal: efficient printing using computed length
00:06:00 Program structure overview ? two main functions
00:06:32 Data section: defining null-terminated strings
00:08:19 Additional strings for output (prefix, CRLF)
00:09:15 Text section start and global looper function
00:10:44 Preserving callee-saved registers (ABI prologue)
00:11:28 Calling print_null_terminated_string
00:12:43 Simple crlf printing helper function
00:13:10 print_null_terminated_string function signature
00:14:31 Prologue for print_null_terminated_string
00:15:44 Saving arguments and calling strlen
00:17:12 Using sys_write with computed length
00:18:19 string_length (strlen) function begins
00:19:20 Prologue and fake return value testing
00:20:44 Planning the while loop in C-like pseudocode
00:21:33 While loop initialization (pointer and counter)
00:24:23 Loop top: check for null terminator
00:26:23 Loop body: increment pointer and counter
00:27:37 Done label and return length in RAX
00:28:29 First successful run ? full string printed
00:29:30 Adding direct strlen call and length printing
00:31:02 Final run showing both string and its length (54)
00:31:53 Summary ? benefits of computed length printing
00:32:59 Improving loop structure (better jump pattern)
00:34:07 Final improved loop verification
00:35:03 Closing thoughts and thanks
00:35:27 Outro, call to subscribe, website mention

=-=-=-=-=-=-=-=-=

Thanks for watching!

Find us on other social media here:
- https://www.NeuralLantern.com/social
- Twitter / X: https://x.com/NeuralLantern
- Rumble: https://rumble.com/c/c-3696939
- BitChute: https://www.bitchute.com/channel/pg1Pvv5dN4Gt
- Daily Motion: https://www.dailymotion.com/neurallantern
- Minds: https://www.minds.com/neurallantern/
- Odysee: https://odysee.com/@NeuralLantern:5

Please show your support!

- Buy me a coffee: https://ko-fi.com/neurallantern

- Subscribe + Sharing on Social Media
- Leave a comment or suggestion
- Subscribe to Blog: https://www.NeuralLantern.com
- Watching the main "pinned" video of this channel for offers and extras