Understanding String Operations in Assembly Language

Slide Note
Embed
Share

Explore the operations such as move, load, store, scan, and compare strings in assembly language. Learn how to manipulate single elements or entire strings using instructions like movs, stos, scas, cmps, lods, and more. Dive into prefixes like rep, repz, repe, repnz, and repne, along with detailed explanations on movs, cmps, lods, stos, and scas instructions for byte, word, or double word manipulation. Enhance your understanding of string processing and comparisons in assembly programming.


Uploaded on Dec 08, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. STRING INSTRUCTIONS

  2. movs (move string) lods (load string element into the accumulator) stos (store accumulator into string element) scas (Scan string and check for match against the value in the accumulator) cmps (compare two strings) You can use the movs, stos, scas, cmps, instructions to manipulate a single element (byte, word, or double word) in a string, or to process an entire string. Generally, you would only use the lods instruction to manipulate a single item at a time. These instructions can operate on strings of bytes, words, or double words. To specify the object size, simply append a b, w, or d to the end of the instruction s mnemonic, i.e., lodsb, movsw, cmpsd, etc. Of course, the double word forms are only available on 80386 and later procs. 2 2024 ALP LECTURE

  3. PREFIXES rep (repeat a string operation) repz (repeat while zero) repe (repeat while equal) repnz (repeat while not zero) repne (repeat while not equal One instruction LOOP as long as CX not equal to zero 3 2024 ALP LECTURE

  4. MOVS{B|W|D} movs{b,w,d}: es:[di] := ds:[si] if direction_flag = 0 then si := si + size; di := di + size; else si := si - size; di := di - size; endif; Note: size is one for bytes, two for words, and four for dwords MOVSB, MOVSW, MOVSD 4 2024 ALP LECTURE

  5. CMPS{B,W,D} The cmps instruction compares the byte, word, or dword at location ds:si to es:di and sets the processor flags accordingly. After the comparison, cmps increments or decrements si and di by one, two, or four depending on the size of the instruction and the status of the direction flag in the flags register. cmps{b,w,d}: cmp ds:[si], es:[di] if direction_flag = 0 then si := si + size; di := di + size; else si := si - size; di := di - size; endif; 5 2024 ALP LECTURE

  6. LODS{B,W,D} lods{b,w,d}: eax/ax/al := ds:[si] if direction_flag = 0 then si := si + size; else si := si - size; endif; 6 2024 ALP LECTURE

  7. STOS{B,W,D} stos{b,w,d}: es:[di] := eax/ax/al if direction_flag = 0 then di := di + size; else di := di - size; endif; 7 2024 ALP LECTURE

  8. SCAS{B,W,D} scas{b,w,d}: cmp eax/ax/al, es:[di] if direction_flag = 0 then di := di + size; else di := di - size; endif; 8 2024 ALP LECTURE

More Related Content