flat assembler
Message board for the users of flat assembler.

Index > DOS > calling dos functions - input string

Author
Thread Post new topic This topic is locked: you cannot edit posts or make replies.
xddxogm3



Joined: 09 Nov 2005
Posts: 12
xddxogm3
Code:
0 input_string_here: 
1        mov ax, 0A00h 
2        int 21h    

I snagged this snippen of code from another post and wanted some clearification of what it actually says.
line 1 says move 0A00h to the ax register.
What exactly does 0A00h stand for in this code?
Post 10 Nov 2005, 04:45
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
hello,
this means
put 16 bit value into ax register and call interrupt dos (21h)
(ah is hi part, al is low part of ax)
generally dos functions use only ah, but of course functions differ,

in this case
int 21h
function
ah=0Ah
function is started,
al is ignored
Post 10 Nov 2005, 04:54
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
yes, it can as well be
Code:
mov ah,10 ;10 = 0Ah
int 21h    
Post 10 Nov 2005, 12:38
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
xddxogm3



Joined: 09 Nov 2005
Posts: 12
xddxogm3
so you are saying it is looking at the command

mov ax, 0A00h

;mov ah/al =0Ah/00h
;mov ah = 0Ah
;mov al = 00h

move the value 10d or 0Ah into ah register.
what does the value 10 in ah and 0 in the al register do when i execute
int 21h?
Post 11 Nov 2005, 01:23
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
xddxogm3 wrote:
so you are saying it is looking at the command

mov ax, 0A00h

;mov ah/al =0Ah/00h
;mov ah = 0Ah
;mov al = 00h

move the value 10d or 0Ah into ah register.
what does the value 10 in ah and 0 in the al register do when i execute
int 21h?


interrupt 21h function does a

Code:
cmp ah, 01h
je @func1
cmp ah, 02h
je @func2
cmp ah, 03h
je @func3
.
.
.
    
Post 11 Nov 2005, 02:41
View user's profile Send private message Visit poster's website Reply with quote
xddxogm3



Joined: 09 Nov 2005
Posts: 12
xddxogm3
Code:
cmp ah, 10h 
je @func10 
    


so what happens when this occurs?
what is executed by @func10

I'm sorry if I'm not picking this up fast, but let me ask this.

I want to perform this c++ task.
Code:
int x=0;
cin>>x;
    
Post 11 Nov 2005, 03:13
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
if ah=function10 then dos input string function is executed
this was really logical i guess
Post 11 Nov 2005, 05:03
View user's profile Send private message Visit poster's website Reply with quote
xddxogm3



Joined: 09 Nov 2005
Posts: 12
xddxogm3
so it reads in a full string.
is it read in null terminated?
where does it store the address place of the first character?
would it be located in register starting at al?
can i read the string as decimal number?
or can i convert it after it has been inputed like atoi() //c++?
or do i have to write that myself too?
so is it fair to say i could do this.
Code:
input_string_here:
     mov eax,0A0000h
     int 21h
    

read in a string upto 32bits
is there a place were i can find a list of values ah can be to execute functions?
Twisted Evil
Post 11 Nov 2005, 05:50
View user's profile Send private message Reply with quote
daluca



Joined: 05 Nov 2005
Posts: 86
daluca
tou can think of int 21h like a dll,a dll has a lot of useful functions right?
and setting ah to 10 is selecting one of that functions,10 is for the user to
enter some text,making ah = 9 is for displaying text,ah = 4ch is exit
and so.... and so....

basically you need 2 things set up prior to make the int 21h:
1) ah = 10 with mov ah,10
2) dx = offset of some place in memory to hold what the user inputed

that offset needs to be leaded(initiated) with 2 bytes: one for you to tell
how many characters you want(since is a byte maximum is 255)
and the other byte to let int21 tell you how many characters the user typed
if you make the first byte 5 and the user type ABC...
the user will only be capable of typing: ABCD if he/she presses any key after
the D the speaker of the cpu will sound and nothing more can be typed

hey? but I said 5 characters why the user coud only input 4?
well the int 21h (function 10) makes room for a CR character
(13,decimal,0Dh in hex that will be put at the end of the string entered
how can you make this buffer and how can you put its offset in dx?
well it goes something like this:
Code:
org 100h
mov ah,10
mov dx,buffer
int 21h
ret
buffer db 10,0    ;10 characters maximum and the other byte will get the
                        ;number of characters typed (excluding the final CR)
db 0,0,0,0,0,0,0,0,0,0   ;this is actually the buffer with 10bytes initi
                                  ;alized to 0 but you can initialize them with any
                                  ; value you want
    


NOTES:
fasm will produce a com file if you execut it the cursor will go to the next
line and there you can type your 9 characters (remember CR will be the
10 character)
I sugest you load that com in debug and analice it.
just type debug [the name of your file here].com at the command prompt
Post 11 Nov 2005, 08:32
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
xddxogm3: http://www.ctyme.com/intr/int-21.htm (warning - this list is extrmely complete, look only at most simple cases)
Post 11 Nov 2005, 09:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
xddxogm3



Joined: 09 Nov 2005
Posts: 12
xddxogm3
how can i get the inputed buffer translated into an integer?
similar to the atoi() function.
can i have the buffered string converted into an integer?
Post 11 Nov 2005, 23:03
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Code:
;ds:si = input buffer
;cx will contain number
;not very foolproof, just demonstrates algorithm
atoi:
mov bx,10 ;we'll be multiplying by 10
.digitloop:
mul bx ;shift ax by one decimal digit left (eg. multuiply by 10)
or dx,dx
jz .overflow
movzx cx,byte [si]  ;mov byte[si] to CL and zero CH
inc si
or cx,cx ;end if 0 found
jz .done
sub cx,'0' ;convert from ascii digit to digit
add ax,cx
jmp .digitloop
...
    

PS: not tested, but idea is there
Post 14 Nov 2005, 15:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic This topic is locked: you cannot edit posts or make replies.

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.