I don't understand how to use Interrupt 21, AH=0ah

▼魔方 西西 提交于 2019-11-27 09:29:19

That DOS function retrieves a buffer with user input. See this table. It seems that program is using that call to pause execution waiting for the user to resume the program.

Edit: I just reread the question. I thought you were only asking what the function call did in your given source. If you want to read input of no more than 20 characters, you first need memory to store it. Add something like this:

bufferSize  db 21  ; 20 char + RETURN
inputLength db 0   ; number of read characters
buffer      db 21 DUP(0) ; actual buffer

Then fill the buffer:

mov ax, cs
mov ds, ax ; ensure cs == ds
mov dx, offset bufferSize ; load our pointer to the beginning of the structure
mov ah, 0Ah ; GetLine function
int 21h

How to convert to uppercase is left to the reader.

That description says you put the address of a buffer in ds:dx before calling the interrupt. The interrupt will then fill that buffer with the characters it reads.

Before calling the interrupt, the first byte of the buffer is how many characters the buffer can hold, or 20 in your case. I do not understand the description of the second byte of the buffer (on input to the interrupt), so I would set it to zero. On return, that byte will tell you how many characters of input were read and placed into the buffer.

free
.model small
.stack 100h
.data 
    N db ?
    msg db 10,13,09,"Enter number of arrays---->$"
.code   
.startup
    mov ax,@data
    mov ds,ax
    call read_N;read N from console




    mov ah,4ch
    int 21h  

Read_N  proc
    ;get number of arrays from user

    push ax
    push dx

 readAgain:   

    mov ax,03h ;Clear screen
    int 10h

    mov dx,offset msg
    mov ah,09h
    int 21h

    call ReadNumber

    ;Inuput number must be in 2<=N<=10 bounery  
    cmp al,2
    js readAgain ;input out of boundary read again
    cmp al,10
    jg readAgain 
    mov N,al
    pop dx
    pop ax
    ret
Read_N endp

ReadNumber proc
    ;read decimal number 0-99 using 
    ;character by character in askii and conver in to decimal   
    ;return result in al
    xor ax,ax
    xor bx,bx
    xor dx,dx

    mov ah,01h
    int 21h

    sub al,'0'  ;conver in to decimal
    mov bl,al  

    mov ah,01h
    int 21h 
    cmp al,0dh  ;Exit if enter pressed
    jnz cont  
    mov al,bl
    jmp exit
  cont:
    sub al,'0'  ;conver in to decimal
    mov dl,al  

    xor al,al
    xor bh,bh
    mov cx,bx
  addnum:    
    add al,10
 loop addnum  

    add al,dl
  exit:   
  ret
 ReadNumber endp  

end           
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!