CHAPTER 11Strings and Things: Those Amazing String Instructions

Most people, having learned a little assembly language, grumble about the seemingly huge number of instructions it takes to do anything useful. By and large, this is a legitimate gripe—and the major reason people write programs in higher-level languages such as Pascal and BASIC. The x64 instruction set, on the other hand, is full of surprises, and the surprise most likely to make apprentice assembly programmers gasp is the instruction group we call string instructions.

They alone, of all the instructions in the x64 instruction set, have the power to deal with long sequences of bytes, words, double words, or quad words at one time. Keep in mind that in assembly language, any contiguous sequence of bytes or larger units in memory may be considered a string—not simply sequences of human-readable characters. More amazingly, the string instructions deal with these large sequences of bytes or larger units in an extraordinarily compact way: by executing an instruction loop entirely inside the CPU! A string instruction is, in effect, a complete instruction loop baked into a single machine instruction.

The string instructions are subtle and complicated, and I won't be able to treat them exhaustively in this book. Much of what they do qualifies as an advanced topic. Still, you can get a good start on understanding the string instructions by using them to build some simple tools to add to your video toolkit.

Besides, for ...

Get x64 Assembly Language Step-by-Step, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.