1 / 46

String Instructions

String Instructions. String instructions were designed to operate on large data structures. The SI and DI registers are used as pointers to the data structures being accessed or manipulated. The operation of the dedicated registers stated above are used to simplify code and minimize its size.

remy
Download Presentation

String Instructions

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. String Instructions • String instructions were designed to operate on large data structures. • The SI and DI registers are used as pointers to the data structures being accessed or manipulated. • The operation of the dedicated registers stated above are used to simplify code and minimize its size.

  2. String Instructions • The registers(DI,SI) are automatically incremented or decremented depending on the value of the direction flag: • DF=0, increment SI, DI. • DF=1, decrement SI, DI. • To set or clear the direction flag one should use the following instructions: • CLD to clear the DF. • STD to set the DF.

  3. String Instructions • The REP/REPZ/REPNZ prefixes are used to repeat the operation it precedes. • String instructions we will discuss: • LODS • STOS • MOVS • CMPS • SCAS • INS • OUTS

  4. LODS/LODSB/LODSW/LODSD • Loads the AL, AX or EAX registers with the content of the memory byte, word or double word pointed to by SI relative to DS. After the transfer is made, the SI register is automatically updated as follows: • SI is incremented if DF=0. • SI is decremented if DF=1.

  5. LODS/LODSB/LODSW/LODSD • Examples: • LODSB AL=DS:[SI]; SI=SI  1 • LODSW AX=DS:[SI]; SI=SI  2 • LODSD EAX=DS:[SI]; SI=SI  4 • LODS MEAN AL=DS:[SI]; SI=SI  1 (if MEAN is a byte) • LODS LIST AX=DS:[SI]; SI=SI  2 (if LIST is a word) • LODS MAX EAX=DS:[SI]; SI=SI  4 (if MAX is a double word)

  6. LODS/LODSB/LODSW/LODSD

  7. STOS/STOSB/STOSW/STOSD • Transfers the contents of the AL, AX or EAX registers to the memory byte, word or double word pointed to by DI relative to ES. After the transfer is made, the DI register is automatically updated as follows: • DI is incremented if DF=0. • DI is decremented if DF=1.

  8. STOS/STOSB/STOSW/STOSD • Examples: • STOSB ES:[DI]=AL; DI=DI  1 • STOSW ES:[DI]=AX; DI=DI  2 • STOSD ES:[DI]=EAX; DI=DI  4 • STOS MEAN ES:[DI]=AL; DI=DI  1 (if MEAN is a byte) • STOS LIST ES:[DI]=AX; DI=DI  2 (if LIST is a word) • STOS MAX ES:[DI]=EAX; DI=DI  4 (if MAX is a double word)

  9. STOS/STOSB/STOSW/STOSD

  10. MOVS/MOVSB/MOVSW/MOVSD • Transfers the contents of the the memory byte, word or double word pointed to by SI relative to DS to the memory byte, word or double word pointed to by DI relative to ES. After the transfer is made, the DI register is automatically updated as follows: • DI is incremented if DF=0. • DI is decremented if DF=1.

  11. MOVS/MOVSB/MOVSW/MOVSD • Examples: • MOVSB ES:[DI]=DS:[SI]; DI=DI  1;SI=SI  1 • MOVSW ES:[DI]= DS:[SI]; DI=DI  2; SI=SI  2 • MOVSD ES:[DI]=DS:[SI]; DI=DI  4; SI=SI  4 • MOVS MEAN1,MEAN2 ES:[DI]=DS:[SI]; DI=DI  1; SI=SI  1 (if MEAN1 and MEAN2 are byte sized) • MOVS LIST1,LIST2 ES:[DI]=DS:[SI]; DI=DI  2; SI=SI  2 (if LIST1 and LIST2 are word sized) • MOVS MAX1,MAX2 ES:[DI]=DS:[SI]; DI=DI  4; SI=SI  4 (if MAX1 and MAX2 are double word sized)

  12. MOVS/MOVSB/MOVSW/MOVSD

  13. INS/INSB/INSW/INSD • Transfer the contents of the port addressed by DX to the memory byte, word or double word pointed to by DI relative to ES. After the transfer is made, the DI register is automatically updated as follows: • DI is incremented if DF=0. • DI is decremented if DF=1.

  14. INS/INSB/INSW/INSD • Examples: • INSB ES:[DI]=[DX]; DI=DI  1 • INSW ES:[DI]= [DX]; DI=DI  2 • INSD ES:[DI]=[DX]; DI=DI  4 • INS MEAN ES:[DI]=[DX]; DI=DI  1 (if MEAN is a byte) • INS LIST ES:[DI]=[DX]; DI=DI  2 (if LIST is a word) • INS MAX ES:[DI]=[DX]; DI=DI  4 (if MAX is a double word)

  15. OUTS/OUTSB/OUTSW/OUTSD • Transfer the contents of the memory byte, word or double word pointed to by SI relative to DS to the port addressed by DX. After the transfer is made, the SI register is automatically updated as follows: • SI is incremented if DF=0. • SI is decremented if DF=1

  16. OUTS/OUTSB/OUTSW/OUTSD • Examples: • OUTSB [DX]=DS:[SI]; SI=SI  1 • OUTSW [DX]= DS:[SI]; SI=SI  2 • OUTSD [DX]=DS:[SI]; SI=SI  4 • OUTS MEAN [DX]=DS:[SI]; SI=SI  1 (if MEAN is a byte) • OUTS LIST [DX]=DS:[SI]; SI=SI  2 (if LIST is a word) • OUTS MAX [DX]=DS:[SI]; SI=SI  4 (if MAX is a double word)

  17. CMPS/CMPSB/CMPSW/CMPSD • Compares the contents of the the memory byte, word or double word pointed to by SI relative to DS to the memory byte, word or double word pointed to by DI relative to ES and changes the flags accordingly. After the comparison is made, the DI and SI registers are automatically updated as follows: • DI and SI are incremented if DF=0. • DI and SI are decremented if DF=1.

  18. SCAS/SCASB/SCASW/SCASD • Compares the contents of the AL, AX or EAX register with the memory byte, word or double word pointed to by DI relative to ES and changes the flags accordingly. After the comparison is made, the DI register is automatically updated as follows: • DI is incremented if DF=0. • DI is decremented if DF=1.

  19. REP/REPZ/REPNZ • These prefixes cause the string instruction that follows them to be repeated the number of times in the count register ECX or until: • ZF=0 in the case of REPZ (repeat while equal). • ZF=1 in the case of REPNZ (repeat while not equal).

  20. REP/REPZ/REPNZ • Use REPNE and SCASB to search for the character ‘f’ in the buffer given below. • BUFFER DB ‘EE3751’ • MOV AL,’f’ • LEA DI,BUFFER • MOV ECX,6 • CLD • REPNE SCASB • JE FOUND

  21. REP/REPZ/REPNZ • Use REPNE and SCASB to search for the character ‘3’ in the buffer given below. • BUFFER DB ‘EE3751’ • MOV AL,’f’ • LEA DI,BUFFER • MOV ECX,6 • CLD • REPNE SCASB • JE FOUND

  22. Modular Programming • Many programs are too large to be developed by a single individual. • A team of programmers develops different parts of the system and their program modules are linked together, thus becoming a large program which includes all modules programmed separately.

  23. The Assembler and Linker • The Assembler converts an ASCII source file created by the programmer into hexadecimal object file. • TASM PROG1.ASM • The Linker reads the object file and creates the executable file. • TLINK PROG1.OBJ

  24. PUBLIC and EXTERN • These two directives allow the programmer to define labels, data, and entire segments as follows: • PUBLIC defines that labels, data, and entire segments are available for other program modules to use. • .DATA PUBLIC LIST LIST DB 50 DUP(?) • .

  25. PUBLIC and EXTERN • EXTERN declares that labels are external to a module. If data is defined as external, their sizes must be defined. • .DATA • Extrn LIST:byte • .CODE • Extrn POWER:far

  26. Libraries • Collections of procedures that may be used by many different programs.

  27. DOS and BIOS Interrupts • DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from keyboard, etc. • They are used by identifying the interrupt option type, which is the value stored in register AH and providing, whatever extra information that the specific option requires.

  28. BIOS Interrupt 10H • Option 0H – Sets video mode. • Registers used: • AH = 0H • AL = Video Mode. • 3H - CGA Color text of 80X25 • 7H - Monochrome text of 80X25 • Ex: • MOV AH,0 • MOV AL,7 • INT 10H

  29. BIOS Interrupt 10H • Option 2H – Sets the cursor to a specific location. • Registers used: • AH = 2H • BH = 0H selects Page 0. • DH = Row position. • DL = Column position. • Ex: • MOV AH,2 • MOV BH,0 • MOV DH,12 • MOV DL,39 • INT 10H

  30. BIOS Interrupt 10H • Option 6H – Scroll window up. This interrupt is also used to clear the screen when you set AL = 0. • Registers used: • AH = 6H • AL = number of lines to scroll. • BH = display attribute. • CH = y coordinate of top left. • CL = x coordinate of top left. • DH = y coordinate of lower right. • DL = x coordinate of lower right.

  31. BIOS Interrupt 10H • Clear Screen Example: • MOV AH,6 • MOV AL,0 • MOV BH,7 • MOV CH,0 • MOV CL,0 • MOV DH,24 • MOV DL,79 • INT 10H • The code above may be shortened by using AX, BX and DX registers to move word size data instead of byte size data.

  32. BIOS Interrupt 10H • Option 7H – Scroll window down. This interrupt is also used to clear the screen when you set AL = 0. • Registers used: • AH = 7H • AL = number of lines to scroll. • BH = display attribute. • CH = y coordinate of top left. • CL = x coordinate of top left. • DH = y coordinate of lower right. • DL = x coordinate of lower right.

  33. BIOS Interrupt 10H • Option 8H – Read a character and its attribute at the cursor position. • Registers used: • AH = 8H and returned attribute value. • AL = Returned ASCII value. • BH = display page.

  34. BIOS Interrupt 10H • Option 9H – Write a character and its attribute at the cursor position. • Registers used: • AH = 9H. • AL = ASCII value. • BH = display page. • BL = attribute. • CX = number of characters to write.

  35. Attribute Definition • Monochrome display attributes • Blinking • D7 = 0 - Non-blinking • D7 = 1 - Blinking • Intensity • D3=0 - Normal intensity • D3=1 - Highlighted intensity • Background and foreground • D6 D5 D4 and D2 D1 D0 • White = 0 0 0 • Black = 1 1 1

  36. Attribute Definition • Color display attributes • Blinking • D7 = 0 - Non-blinking • D7 = 1 - Blinking • Intensity • D3=0 - Normal intensity • D3=1 - Highlighted intensity • Background and foreground • D6 D5 D4 and D2 D1 D0 • RGB values defined by the table to the right.

  37. DOS Interrupt 21H • Option 1 – Inputs a single character from keyboard and echoes it to the monitor. • Registers used: • AH = 1 • AL = the character inputted from keyboard. • Ex: • MOV AH,1 • INT 21H

  38. DOS Interrupt 21H • Option 2 – Outputs a single character to the monitor. • Registers used: • AH = 2 • DL = the character to be displayed. • Ex: • MOV AH,2 • MOV DL,’A’ • INT 21H

  39. DOS Interrupt 21H • Option 6 – Inputs a single character from keyboard without an echo to the monitor. • Registers used: • AH = 6 • AL = the character inputted from keyboard. • DL = 0FFH or -1 • Ex: • MOV AH,6 • MOV DL,-1 • INT 21H

  40. DOS Interrupt 21H • Option 9 – Outputs a string of data, terminated by a $ to the monitor. • Registers used: • AH = 9 • DX = the offset address of the data to be displayed. • Ex: • MOV AH,09 • MOV DX,OFFSET MESS1 • INT 21H

  41. DOS Interrupt 21H • Option 0AH – Inputs a string of data from the keyboard. • Registers used: • AH = 9 • DX = the offset address of the location where string will be stored. • DOS requires that a buffer be defined in the data segment. It should be defined as follows: • 1st byte contains the size of the buffer. • 2nd byte is used by DOS to store the number of bytes stored.

  42. DOS Interrupt 21H • Ex: • .DATA • BUFFER1 DB 0FH,?,0FH DUP (0FFH) • . • . • MOV AH,0AH • MOV DX,OFFSET BUFFER1 • INT 21H • Assume “Go Tigers!” was entered on the keyboard. • BUFFER1 = 0FH,0BH,’Go Tigers!’,CR,0FFH, 0FFH, 0FFH, 0FFH

  43. DOS Interrupt 21H • Option 4CH – Terminates a process, by returning control to a parent process or to DOS. • Registers used: • AH = 4CH • AL = binary return code. • Ex: • MOV AH,4CH • INT 21H

  44. Macros • Format • Name MACRO Argument,Argument • Macro code • ENDM • Example • Power MACRO X,N

  45. SWAP MACRO X,Y PUSH AX PUSH DX MOV AX,X MOV DX,Y MOV Y,AX MOV X,DX POP DX POP AX ENDM SWAP VAR1,VAR2 PUSH AX PUSH DX MOV AX,VAR1 MOV DX,VAR2 MOV VAR2,AX MOV VAR1,DX MOP DX POP AX Macros

  46. Macros • A local variable is a variable that appears only in the macro. • Local variables need to be defined with the local directive. • Example: • DELAY MACRO COUNT • LOCAL AGAIN • PUSH CX • MOV CX,COUNT • AGAIN:LOOP AGAIN • POP CX

More Related