StringInstructions - The String Instructions The String...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
The String Instructions Beta Draft - Do not distribute © 2001, By Randall Hyde Page 935 The String Instructions Chapter Six 6.1 Chapter Overview A string is a collection of objects stored in contiguous memory locations. Strings are usually arrays of bytes, w ords, or (on 80386 and later processors) double w ords. The 80x86 microprocessor f amily supports se v eral instructions specifi cally designed to cope with strings. This chapter e xplores some of the uses of these string instructions. The 80x86 CPUs can process three types of strings: byte strings , w ord strings , and double w ord strings . The y can mo v e strings , compare strings , search for a specifi c v alue within a string , initialize a string to a fi x ed v alue , and do other primiti v e operations on strings. The 80x86’ s string instructions are also useful for manipulating arrays, tables, and records. Y ou can easily assign or compare such data structures using the string instructions. Using string instructions may speed up your array manipulation code considerably . 6.2 The 80x86 String Instructions All members of the 80x86 f amily support fi v e dif ferent string instructions: MO VS x , CMPS x , SCAS x , LODS x , and ST OS x 1 . ( x = B, W , or D for byte, w ord, or double w ord, respecti v ely . This te xt will generally drop the x suf fi x when talking about these string instructions in a general sense.) The y are the string primi - ti v es since you can b uild most other string operations from these fi v e instructions. Ho w you use these fi v e instructions is the topic of the ne xt se v eral sections. For MOVS: movsb(); movsw(); movsd(); For CMPS: cmpsb(); // Note: repz is a synonym for repe cmpsw(); cmpsd(); cmpsb(); // Note: repnz is a synonym for repne. cmpsw(); cmpsd(); For SCAS: scasb(); // Note: repz is a synonym for repe scasw(); scasd(); scasb(); // Note: repnz is a synonym for repne. scasw(); scasd(); For STOS: stosb(); stosw(); stosd(); 1. The 80x86 processor support two additional string instructions, INS and OUTS which input strings of data from an input port or output strings of data to an output port. We will not consider these instructions since they are privileged instructions and you cannot execute them in a standard 32-bit OS application.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Chapter Six Volume Six Page 936 © 2001, By Randall Hyde Beta Draft - Do not distribute For LODS: lodsb(); lodsw(); lodsd(); 6.2.1 How the String Instructions Operate The string instructions operate on blocks (contiguous linear arrays) of memory . F or e xample, the MO VS instruction mo v es a sequence of bytes from one memory location to another . The CMPS instruction com - pares tw o blocks of memory . The SCAS instruction scans a block of memory for a particular v alue. These string instructions often require three operands, a destination block address, a source block address, and (optionally) an element count. F or e xample, when using the MO VS instruction to cop y a string, you need a source address, a destination address, and a count (the number of string elements to mo v e).
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern