DOS FUNCTION CALLS - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

DOS FUNCTION CALLS

Description:

DOS FUNCTION CALLS. ICS33. INT 21h. This is called a DOS Function call. ... If the buffer becomes full, the computer beeps and extra keystrokes are ignored. ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 31
Provided by: F223
Category:

less

Transcript and Presenter's Notes

Title: DOS FUNCTION CALLS


1
DOS FUNCTION CALLS
  • ICS33

2
INT 21h
  • This is called a DOS Function call.
  • There are 87 different functions supported by
    this interrupt, identified by a function number
    placed in the AH register.

3
INT 21h
4
INT 21h
  • Example.
  • mov ah,1 console input function
  • int 21h call DOS, key returned in AL
  • mov char,al save the character

5
INT 21h
6
INT 21h
  • Example.
  • mov ah,2 select DOD function2
  • mov dl, character to be displayed
  • int 21h call DOS to do the job
  • Caution AL is modified by DOS during the call to
    INT 21h, so you may want to push it on the stack
    before calling INT 21h and restore it afterward.

7
INT 21h
8
INT 21h
  • Example.
  • mov ah,5 select printer output
  • mov dl, character to be printed
  • int 21h call DOS
  • mov dl,0Dh print a carriage return
  • int 21h call DOS
  • Note05 is not yet supported by Emu8086.

9
INT 21h
10
INT 21h
  • Example. Character Input
  • mov ah,6 request DOS function 6
  • mov dl,0FFh look for input, dont wait
  • int 21h if key pressed, AL character,
  • otherwise the Zero flag is set
  • Character Output
  • mov ah,6 request DOS function 6
  • mov dl, character to be output
  • int 21h call DOS

11
Keyboard Typeahead Buffer
  • The typeahead buffer is a 15-character circular
    buffer used by DOS to store keystrokes as they
    are pressed. This makes it possible for you to
    type faster than a program is able to act on the
    input DOS will remember the keystrokes. If the
    buffer becomes full, the computer beeps and extra
    keystrokes are ignored.

12
Clear the Keyboard Buffer
  • Application programs occasionally need to clear
    the keyboard typeahead buffer to prevent users
    from making catastrophic mistakes.
  • clear_keyboard proc
  • mov cx,15 size of typeahead buffer
  • L1 mov ah,6 DOS function check buffer
  • mov dl,0FFh
  • int 21h
  • loop L1 loop until CX0
  • ret return to calling program
  • clear_keyboard endp

13
INT 21h
  • Example.
  • mov ah,7 console input function
  • int 21h call DOS
  • mov char,al save the character

14
INT 21h
15
INT 21h
  • Example.
  • mov ah,8 console input function
  • int 21h call DOS
  • mov char,al save the character
  • ----------------------------------
    ---
  • mov ah,9 string output function
  • mov dx, offset string offset address of
    the string
  • int 21h
  • .
  • .
  • string db This is a byte string.,0Dh,0Ah,

16
INT21h
17
Nested Loops
  • mov cx,5
  • nameLabel
  • push cx
  • mov cx,9
  • nameLabel2
  • mov ax,0
  • mov ax,si
  • mov di,ax
  • inc si
  • inc di
  • loop nameLabel2
  • add di,23
  • pop cx
  • loop nameLabel

18
Nested Loops
  • As you can see we have two loops. The problem is
    that both of these loops use cx as their counter.
    To remedy this when we enter the loop we push the
    value of cx onto the stack and then when the
    inner loop is done we pop the top of the stack
    into cx.

19
Arrays
  • Here are some examples of different kinds of
    arrays.
  • someStrings db "hello world","hello 2 ","hello 3
    ",0
  • The first variable is an array of strings. One
    thing you should do is make all the strings the
    same length. It makes it a lot easier to use
    them.

20
Arrays
  • someNumbers dw 10 dup(?)
  • The second variable uses the dup command to make
    ten empty locations which you can set later on.
    You can put a number in those parentheses and it
    will put that number in each location.

21
Arrays
  • moreNumbers dw 2,1,2,5,5,6,3,2
  • The third variable is just an array of numbers.
    Each number needs to separated by a comma.

22
Arrays
  • someChars db 'adsf',0
  • The last variable is an array of characters.

23
Arrays
  • To use these arrays you must load the offset of
    one of them into a register. Here is an example.
  • mov si,offset someStrings
  • Once the offset is in the register you can access
    the values like this.
  • mov ax,si
  • That will put whatever is in the first position
    of si which would be the letter h not the whole
    string because a string is an array itself. To
    get to the next character do this.
  • inc si

24
Procedures and Macros
  • Procedures and macros are very similar to
    functions in c. They can be used to make
    repetitive tasks easier.

25
Procedures
  • Procedures
  • Do you remember the main proc that is in every
    program, well that is a procedure. A procedure
    can be created by giving it a name then putting
    proc after it. Put your code there. Then end it
    with a ret, then the name you chose then endp.
    You should put all this outside of the main
    procedure.

26
Procedures
  • Procedures
  • To use this procedure you use the call command
    and then the name of the procedure. Here is an
    example
  • .code
  • main proc
  • mov ax,_at_data
  • mov ds,ax
  • call myProc
  • mov ax,4c00h
  • int 21h
  • main endp
  • myProc proc
  • inc bx
  • ret
  • myProc endp

27
Procedures
  • This is how it works. When the procedure is
    called it goes down to the location of the
    procedure. It does it stuff then ret is called
    and it returns to where it was in main.

28
MACRO
  • A macro is very similar syntactically but it's
    inner workings is different. First it can be
    passed a parameter. Second instead of the program
    going to where the macro is located it pastes a
    copy of it into the program wherever it is
    called. For this reason it is not a good idea to
    use a macro in a loop. Here is an example of a
    macro.

29
MACRO
  • .code
  • main proc
  • mov ax,_at_data
  • mov ds,ax
  • aMacro 100
  • mov ax,4c00h
  • int 21h
  • main endp
  • aMacro macro theParameter
  • mov ax,theParameter
  • endm

30
MACRO
  • This macro is passed the value 100 and the macro
    puts that into ax.
Write a Comment
User Comments (0)
About PowerShow.com