String Instructions - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

String Instructions

Description:

String Instructions. MOVS ; move string. CMPS ; ... MOVS ... MOVS with repeat. Mov si, offset str1 ; si addr of str1. Mov di, offset str2 ; di addr of str2 ... – PowerPoint PPT presentation

Number of Views:112
Avg rating:3.0/5.0
Slides: 13
Provided by: shantil
Category:

less

Transcript and Presenter's Notes

Title: String Instructions


1
String Instructions
  • MOVS move string
  • CMPS compare string
  • SCAS scan string
  • STOS store string
  • LODS load string

2
MOVS
  • Move string data Copy a memory byte, word or
    double word from one memory location to another.
  • Implied operands MOVS DI, SI

3
Example of MOVS
  • ES and DS both must contain address of data
    segments, done by three instructions
  • Mov ax, _at_data
  • Mov ds, ax
  • Mov es, ax
  • Mov si, offset source addr of source in si
  • Mov di, offset dest addr of dest in di
  • Movsb copy byte from source to destn
  • Moves one byte from source pointed by si to
    source pointed by di

4
Repeat instructions
  • REP repeat while cx / 0
  • REPZ, REPE repeat while the zero flag is set
    and cx gt0
  • REPNZ, REPNE repeat while the zero flag is
    clear and cx gt0

5
MOVS with repeat
  • Mov si, offset str1 si ? addr of str1
  • Mov di, offset str2 di ? addr of str2
  • Mov cx, 10 cx ? of bytes to be copied
  • Rep movsb copies 10 bytes from str1 to str2

6
Direction Flag
  • CLD clear direction flag
  • STD sets direction flag
  • If direction flag is cleared, registers SI and
    DI are both incremented, and n bytes are copied
    from left to right (low-high addr)
  • If direction flag is set, registers SI and DI
    are both decremented, and n bytes are copied from
    right to left (low-high addr)

7
MOVS_ (different forms)
  • MOVSB move string byte
  • MOVSW move string word
  • MOVSD move string double word
  • Instruction auto change in si / di (inc or
    dec)
  • movsb 1
  • movsw 2
  • movsd 4

8
CMPSb Compare string byte
  • Mov si, offset source
  • Mov di, offset dest
  • Mov cx, 12
  • Repe cmpsb repeat while sourcedest
  • In instruction cmp ax, 5 (source 5 is subtracted
    from destination ax.
  • In instruction cmps dest, source (dest is
    subtracted from the source)

9
SCASb Scan string byte
  • Mov si, offset source
  • Mov al, 20h
  • Mov cx, 12
  • Repne scasb repeat while sourcedest

10
SCASb Scan string byte
  • Scan string backwards
  • Mov si, offset source
  • Mov al, 20h
  • Mov cx, 12
  • Std set the direction flag
  • Repe scasb repeat while sourcedest

11
STOSb store string byte
  • Mov di, offset str1
  • Mov cx, 75
  • Mov al, 0FFh
  • Cld
  • Rep stosb first 100 bytes of str1 initalized
    to FFh

12
LODSb load string byte
  • loads al with one byte from a buffer
  • Mov si, offset buffer
  • Mov di, offset str1
  • Mov cx, 10
  • L1 lodsb
  • And al, 7Fh
  • Stosb
  • Loop L1
Write a Comment
User Comments (0)
About PowerShow.com