String Instructions - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

String Instructions

Description:

ES must be initialized prior to using these instructions. ... This program transfer 20 bytes of data using MOVS. in the data segment ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 8
Provided by: DHW
Category:

less

Transcript and Presenter's Notes

Title: String Instructions


1
String Instructions
  • SI always points to the source operand which is
    located in the data segment.
  • DI always point to the destination operand which
    is located in the extra segment.
  • ES must be initialized prior to using these
    instructions.
  • data is stored in consecutive memory locations,

2
  • The Direction flag (DF) is used to increment or
    decrement the data pointers
  • The instruction CLD resets DF (DF 0) for
    autoincrement.
  • The instruction STD sets DF (DF 1) for
    autodecrement.
  • The REP prefix allows a string instruction to
    perform the operation repeatedly.
  • Register CX holds the number of times that the
    instruction should be repeated - It is
    automatically decrement after each REP.

3
(No Transcript)
4
  • This program transfer 20 bytes of data using MOVS
  • in the data segment
  • data1 DB abcdefghijklmnopqrst
  • ORG 30H
  • data2 DB 20 DUP(?)
  • in the code segment
  • ASSUME CSCDSEG, DSDTSEG, ESDTSEG, SSSTSEG
  • MOV AX, DTSEG
  • MOV DS, AX initialize the data segment
  • MOV ES, AX initialize the extra segment
  • CLD clear direction flag for autoincrement
  • MOV SI, OFFSET data1 load the source pointer
  • MOV DI, OFFSET data2 load destination pointer
  • MOV CX, 20 load the counter
  • REP MOVSB repeat until CX becomes zero

5
  • This program stores the byte AAH in 100 memory
    locations using STOS
  • put pattern AAAAH in 50 word locations
  • MOV AX, DTSEG initialize
  • MOV DS, AX DS register
  • MOV ES, AX and ES register
  • CLD clear direction flag for autoincrement
  • MOV CX, 50 load the counter (50 words)
  • MOV DI, OFFSET mem_area load the pointer for
    destination
  • MOV AX , AAAAH load the pattern
  • REP STOSW repeat until CX 0

6
  • This program checks the spelling of the word
    EUROPE and inform the user
  • data_dict DB Europe
  • data_typed DB Euorope
  • MESSAGE1 DB The spelling is correct
  • MESSAGE2 DB Wrong spelling
  • from the code segment
  • CLD clear DF for increment
  • MOV SI, OFFSET dat_dict offset for data1
  • MOV DIlt OFFSET dat_typed offset for data2
  • MOV CX, 6 load the counter
  • PEPE CMPSB repeat as long as equal or until
    CX0
  • JE OVER IF ZF0 Then display message1
  • JMP DISPLAY otherwise display message2

7
  • This program scans the name Mr. Gones and
    replaces the G with J
  • in the data segment
  • DATA1 DB Mr. Gones
  • in the code segment
  • MOV AX, DTSEG
  • MOV DS, AX
  • MOV ES, AX
  • CLD DF 0 for increment
  • MOV DI, OFFSET DATA1 ESDI array offset
  • MOV CX, 9 length of the data array
  • MOV AL, G prepare for scanning for the
    letter G
  • REPNE SCASB repeat if not equal or until CX0
  • JNE OVER jump if Z 0
  • DEC DI decrement to point at G
  • MOV BYTE PTR DI, J replace G with J
Write a Comment
User Comments (0)
About PowerShow.com