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

前端 未结 3 872
轮回少年
轮回少年 2020-12-02 00:04

My information is coming from here. The assignment asks for a program that reads in no more than 20 characters, converts those characters to upper case, and then prints the

相关标签:
3条回答
  • 2020-12-02 00:46
    .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           
    
    0 讨论(0)
  • 2020-12-02 00:47

    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.

    0 讨论(0)
  • 2020-12-02 00:52

    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.

    0 讨论(0)
提交回复
热议问题