Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
943 views
in Technique[技术] by (71.8m points)

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

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 input as capitals.

I have no idea how to access the input from int21/AH=0ah. I really can't ask a more precise question unless I understand what is linked above. Can someone explain? Also, I'm using TASM if that makes any difference. Also, I'm testing this on freedos.

UPDATE1:

Alright, thanks to your help, I believe I understand how the interrupt needs to be set up and behaves.

Setup: I have to designate a ds:dx where I want this buffer to exist

I have to set ds:dx to 20 (which sets the max number of characters the buffer can hold)

I have to set ds:dx+1 to 0 (which I think somehow set a min number of characters to read in)

Actually call int21/AH=0ah, which will go to ds:dx and interpret the preset bytes. It will halt the program while it waits for input

int21/AH=0ah will fill from ds:dx+2+n with my input (where n is the number of characters input including ' ')

My question is now, how do I do this. I've just looked through the x86 Assembly Language Reference again, but haven't been able to find anything helpful yet.

Code I've got so far

           assume          cs:code,ds:code
code       segment
start:

           mov  ax,code ;moves code segment into reg AX
           mov  ds,ax   ;makes ds point to code segment

           mov  ah,0ah
           int  21h
           mov  ax,1234h  ;breakpoint

           mov  ah,9
           mov  dx,offset message
           int  21h

endNow:
           ;;;;;;;;;;ends program;;;;;;;;;;
           mov  ah,0  ;terminate program
           int  21h   ;program ends

message    db   'Hello world!!!',13,10,'$'
code       ends
           end  start
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...