ENGR 4862 Microprocessors Lecture 19 - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

ENGR 4862 Microprocessors Lecture 19

Description:

DOS will put the number of characters that come in through the keyboard in the second byte ... Can be used to display '$' since it can't be displayed with function 09H ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 21
Provided by: lihong2
Category:

less

Transcript and Presenter's Notes

Title: ENGR 4862 Microprocessors Lecture 19


1
ENGR 4862 MicroprocessorsLecture 19
2
DOS INT 21H 09H Output String
  • INT 21H is provided by DOS after it is loaded
  • Option 09H output a string of data to monitor
  • Send a set of ASCII data for displaying
  • AH 09
  • DX offset addr. of the ASCII data to be
    displayed
  • This function will display ASCII data string
    pointed by the DX until it encounters the dollar
    sign ()
  • What if without a at the end of the string?

3
  • data_ASC DB The earth is but one
  • MOV AH, 09H
  • MOV DX, OFFSET data_ASC
  • INT 21H

4
DOS INT 21H 0AH Input String (I)
  • AH 0AH
  • DX offset address at which the data string is
    stored
  • Referred to as a buffer area
  • DOS requires
  • A buffer area is defined in data segment (DS)
  • First byte specifies the size of the buffer
  • DOS will put the number of characters that come
    in through the keyboard in the second byte
  • The data in the buffer starts at the third byte
  • The return key will not be counted as an input
    character

5
DOS INT 21H 0AH Input String (II)
  • What if input string is more than the buffer
    size?
  • The first characters will be put in the buffer
  • The last place in the buffer will be a ltCRgt (0DH)
  • The remaining characters are ignored
  • If no other characters entered, just ltCRgt
    pressed?
  • The fist byte holds the buffer size
  • The second byte 00H, since no character inputted
  • The third byte ltCRgt (0DH)
  • Remaining bytes unchanged
  • ltCRgt ASCII 0DH ltLFgt ASCII 0AH

6
Define a Buffer String
  • A more systematic way of defining buffer area
  • data_buf LABEL BYTE word, dword
  • max_size DB 10
  • buf_count DB ?
  • buf_data DB 10 DUP (?)
  • MOV AH, 0AH
  • MOV DX, OFFSET data_buf
  • INT 21H
  • MOV CL, buf_count
  • MOV SI, OFFSET buf_data

7
DOS INT 21H Char IN/OUT
  • Option 02H output a single character to monitor
  • AH 02
  • DX the character to be displayed
  • Can be used to display since it cant be
    displayed with function 09H
  • Option 01H input a single character with echo
  • AH 01
  • AL the input character in ASCII
  • Wait until a character is input from the
    keyboard, then echo it to the monitor

8
DOS INT 21H Char IN/OUT
  • Option 07H input a single character without echo
  • AH 07
  • AL the input character in ASCII
  • Wait until a character is input from the
    keyboard, but without echo to the monitor

9
INT 16H Keyboard Programming
  • Check a key press
  • Function 01 (in AH) of INT 16H
  • This function does not wait for the user to press
    a key
  • Simply checks if there is a key press
  • On return, ZF 0, there is a key press
  • ZF 1, there is no key press
  • Check which key is pressed
  • Function 00 (in AH) of INT 16H
  • Can be used immediately after function 01H
  • On return, AL contains the ASCII code of the key

10
  • display press y to exit
  • wait MOV AH, 01H
  • INT 16H
  • JZ wait
  • MOV AH, 00H
  • INT 16H
  • CMP AL, y
  • JNE wait

11
String Instruction and Operation
  • Capable of performing operations on a series of
    operands located in consecutive memory locations
  • In 8086/88, SI and DI always point to the source
    and destination operands
  • Default segment register
  • ES must be initialized for the string operation
    to work

12
String Instructions
  • Often you will need to perform operations on a
    series of data
  • The 8086/8088 provides string instructions to
    operate on a series of operands located in
    consecutive memory locations
  • Storing, loading, moving, scanning, and comparing
  • In string instructions, operands can be byte or
    word, distinguished by letter B or W in mnemonic

13
String Instructions
  • When designing the 8086/8088, the designers set
    aside certain registers for the string
    instructions
  • SI (source index) points to the source operand
  • DI (destination index) points to the destination
    operand
  • Both are offsets the segments are different for
    each
  • SI uses DS, DI uses ES

14
String Instructions
  • These instructions have their own addressing
    modes
  • The only 8086/8088 operations capable of memory
    to memory operations (moving and comparing)
  • Wrong mov byte ptr DI, SI
  • Right movsb

15
Direction Flag
  • Increment or decrement the pointer SI or DI
  • The string instructions automatically do this
  • The programmer should specify the direction
  • By setting the direction flag to high or low
  • CLD ? DF0, auto-increment
  • STD ? DF1, auto-decrement

16
Some Useful Prefix
  • REP
  • Allows a string instruction to perform repeatedly
    until CX register is decremented to 0, e.g., REP
    MOVSB
  • REPZREPE
  • Repeat as long as the source and destination
    operands are equal (ZF1) or until CX becomes
    zero
  • REPNZREPNE
  • Repeat as long as the source and destination
    operands are not equal (ZF0) or until CX becomes
    zero

17
String Instructions
  • MOVSB, MOVSW
  • STOSB, STOSW
  • Store the byte/word in AL/AX register into the
    memory specified by ESDI and increment or
    decrement DI
  • LODSB, LODSW
  • Load the byte/word in memory specified by DSSI
    to AL/AX register and increment or decrement SI

18
String Instructions
  • CMPSB, CMPSW
  • Compare two arrays of data pointed by the SI and
    DI registers
  • Can test the equality or inequality of data by
    use of the REPE or REPNE

19
Example1 Copy a String
  • MOV SI, OFFSET SOURCE
  • MOV DI, OFFSET DESTINATION
  • CLD increment
  • MOV CX, 8
  • REP MOVSB
  • MOV CX, 4
  • REP MOVSW

20
Example2 Compare Two Strings
  • MOV SI, OFFSET string1
  • MOV DI, OFFSET string2
  • CLD
  • MOV CX, 16
  • REPZ CMPSB
  • JZ correct
  • ltDisplay wrong messagegt
  • correct
  • ltDisplay correct messagegt
Write a Comment
User Comments (0)
About PowerShow.com