1 / 14

CEN 226 : Computer Organization & Assembly Language : CSC 225 (Lec#10)

CEN 226 : Computer Organization & Assembly Language : CSC 225 (Lec#10). By Dr. Syed Noman. String manipulation in assembly. Computer applications along with arithmetical processing involve work such as text processing, searching of files, sorting of names etc.

aquila
Download Presentation

CEN 226 : Computer Organization & Assembly Language : CSC 225 (Lec#10)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CEN 226: Computer Organization & Assembly Language :CSC 225(Lec#10) By Dr. Syed Noman

  2. String manipulation in assembly • Computer applications along with arithmetical processing involve work such as text processing, searching of files, sorting of names etc. • The core of such tasks is string, which is an arbitrary sequence of characters. • The 8086/88 is endowed with instructions for handling text or strings.

  3. String manipulation instructions • There are 5 primitive string manipulation instructions: • MOVS • STOS • LODS • CMPS • SCAS • REP instruction is used to provide a loop for the repeating the above instructions.

  4. String manipulation instructions • The primitive string instructions are controlled with the CX, SI and DI registers. • CX used with rep to count number of locations remaining for the operation. • SI contains the source operand address of memory, with respect to DS. • DI contains the destination operand address of memory, with respect to ES. • Direction flag DF=0, means operation with increasing memory locations, ‘1’ means decreasing.

  5. MOVS • This instruction takes one byte/word pointed to by SI register and moves it to the location pointed to by the DI register. • It automatically increments/decrements SI and DI register depending on the value of direction flag. • It automatically decrements CX register.

  6. Example program .model small .data Str1 db “college of computer” Str2 db 30 dup(‘$’) .code Start: Movax,@data Mov ds, ax Moves, ax Lea si, str1 Lea di, str2 Mov cx,19 Cld Rep movsb Mov ah,9 Lea dx,str2 Int 21h Mov ax, 4c00h Int 21h End start end

  7. STOS • Filling blocks of memory with the same byte/word. • STOSB/STOSW stores the contents of AL/AX in the memory location addressed by the DI register. Mov DI, offset buf Mov cx,256 Mov al,0 Cld Rep stosb

  8. LODS • The reverse of STOS, but rep is hardly ever used with LODs as it is unlikely that contents of one location are stored in AL/AX and then straight away move the contents of the next location into the same register. • It takes one byte/word from the location whose address is in SI register.

  9. LODS Mov SI, 200 Mov DI, 300 Mov cx, 50 Cld nextLoc: Lodsb Add al, 20h Stosb Loop nextLoc

  10. CMPS and REPZ • Both in combination are used to compare strings but stop when either: • Cx becomes 0; or • Mismatch of character is found

  11. CMPS and REPZ Cld Mov cx, 50 Mov SI, 200 Mov DI, 300 Repzcmpsb Jnzdiff_strings Mov dl, ’Y’ Jmp Matched

  12. SCAS and REPNZ • Scans memory pointed by DX for a byte/word held in AL/AX. • It stops, if: • CX becomes zero (all locations searched) • Required byte/word has been found.

  13. SCAS and REPNZ cld mov di, 200 mov cx, 50 next: mov al, ‘x’ repnzscasb jnz next dec di mov al, ‘y’ ; replace each ‘x’ with ‘y’ stosb inc cx loop next

  14. Assignment 3c • Use string instructions to print number of times (maximum 9) a substring “abc” is found in “abbabcnabdemabcdabcd” • Use scasb and cmpsb

More Related