flat assembler
Message board for the users of flat assembler.

Index > DOS > Input and Output String

Goto page Previous  1, 2
Author
Thread Post new topic This topic is locked: you cannot edit posts or make replies.
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Remy Vincent,
cool Smile
:/ Very Happy Razz Exclamation Cool

well, i guess this function is not really useful included in dos/windows,
i was testing int21h inputstring function on winxp, and it works something like yours ;> , tested with some texts, but there was some instability "not always working as expected" thing.
so for example i whouldnt like to spend my time with this dos function.

estrang,
it was some bad luck you got your first program on a not working dos function,
but this can be only better than this now, when i started electronics, my circuit was not working because of "all of the transistors were dead" ;>

huh, i got dos input to work, i think it whould be nice if they leave some bugs out, and write in assembly, not talking about the dos $ termination handling..., so, now the backspace bug can be seen on this demonstartion program

Code:
        org 100h
start:  mov dx, hl_text ; display hl_text
         call disp_
input_: mov dx, hl_text ; offset to buffer
        mov bx, dx
        mov byte [bx+1],0 ; zero
        mov ah, 0Ah
        int 21h
         call newline
        mov dx, gl_text
         call disp_
        mov dx, hl_text
        mov bx, dx
        movzx bx, byte [bx+1] ; get number of bytes read
        add bx, dx     ; add offset to read bytes
        inc bx         ; add 2
        inc bx
        mov byte [bx],"$"  ; put dos string termination char
        inc dx
        inc dx
        call disp_
getch:  xor ah,ah     ; zero out ah
        int 16h ; bios wait keypress
        mov ax, 4C00h
        int 21h ; exit function, errorcode 00
disp_:  mov ah,09h
        int 21h       ; display
        ret
newline:mov dx, .text_
        call disp_
        ret
.text_: db 0Dh,0Ah,"$"

gl_text: db 'You entered the string: ', "$"
hl_text: db 'Please Enter a string: ', "$" ; order this so wont be possible to owerwrite the other string

;--------D-210A-------------------------------
;INT 21 - DOS 1+ - BUFFERED INPUT
;        AH = 0Ah
;        DS:DX -> buffer (see #01344)
;Return: buffer filled with user input
;Notes:  ^C/^Break are checked, and INT 23 is called if either detected
;        reads from standard input, which may be redirected under DOS 2+
;        if the maximum buffer size (see #01344) is set to 00h, this call returns
;          immediately without reading any input
;SeeAlso: AH=0Ch,INT 2F/AX=4810h
;
;Format of DOS input buffer:
;Offset  Size    Description     (Table 01344)
; 00h    BYTE    maximum characters buffer can hold
; 01h    BYTE    (call) number of chars from last input which may be recalled
;                (ret) number of characters actually read, excluding CR
; 02h  N BYTEs   actual characters read, including the final carriage return
    


you write a line, then when you got a line break, you can not normally use backspace, not handled even in xp ;>
the code i posted before can be made to handle cut and paste easily, and uses bios functions, so should be boot sector compatible


standard input output :

type characters fast, and push 70cps backspace, some chars remain, and data pointer wraps in xp pro, press esc, \ and goes down a line

Please enter a s666666634564564564564564564564565\ 6 6
\
\
\
\
\
\
333333\ 5
\
\
\
\
\
\
333333333333333333333333333333333
Post 09 Nov 2005, 05:52
View user's profile Send private message Visit poster's website Reply with quote
estrang



Joined: 02 Nov 2005
Posts: 38
estrang
Thnks for the help guys. I feel lazy today to read all these post. Ill probably read these when i wake up later.

Question: Ive read a lot about dos and bios function like in this thread. What are the dirrence between these 2 and which one you guys recommend to use?

And when in C compiles a program similar to this. What does code it produce for dos or for bios??
Post 11 Nov 2005, 09:22
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
DOS function (INT) is the INT that only available when you are using DOS Operating System, whether MS-DOS or PC-DOS or DOS clones.

Bios (INT) are the INT that are mostly available in almost every x86 computer.

DOS function (INT) are actually relies on BIOS INT, they are just wrapper functions that enhance the BIOS INT. In another meaning, DOS INT uses BIOS INT and depend on it.

when C compile program, depend on wat output you want, if you compile for MS-DOS, then they would use DOS INT, if you compile for non-DOS, then they would use BIOS INT.
Post 12 Nov 2005, 07:48
View user's profile Send private message Visit poster's website Reply with quote
estrang



Joined: 02 Nov 2005
Posts: 38
estrang
vbVeryBeginner wrote:
DOS function (INT) is the INT that only available when you are using DOS Operating System, whether MS-DOS or PC-DOS or DOS clones.

Bios (INT) are the INT that are mostly available in almost every x86 computer.

DOS function (INT) are actually relies on BIOS INT, they are just wrapper functions that enhance the BIOS INT. In another meaning, DOS INT uses BIOS INT and depend on it.

when C compile program, depend on wat output you want, if you compile for MS-DOS, then they would use DOS INT, if you compile for non-DOS, then they would use BIOS INT.


Thnks very much for the explanation. Now i understand quite a bit. Smile
Post 12 Nov 2005, 08:34
View user's profile Send private message Reply with quote
estrang



Joined: 02 Nov 2005
Posts: 38
estrang
Can someone help me with this code?? This is supposed to be the short version of the problem im trying to do. Can someone convert this conde to fasm??

I got this from emu8086 tut. It has been very useful for me. So sad the author seemed to stopped updating his app.

Code:
org 100h
                mov dx, offset buffer
                mov ah, 0ah
                int 21h
                jmp print
                buffer db 10,?, 10 dup(' ')
                print:
                xor bx, bx
                mov bl, buffer[1]
                mov buffer[bx+2], '$'
                mov dx, offset buffer + 2
                mov ah, 9
                int 21h
                ret
    
Post 12 Nov 2005, 08:37
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
wat u wanna do is almost quite similiar to wat xddxogm3 wanna do, try read this thread, it is almost the same. ur supplied function just want to prepend the "$" at the end of input string.

http://board.flatassembler.net/topic.php?t=4365
Post 12 Nov 2005, 09:02
View user's profile Send private message Visit poster's website Reply with quote
estrang



Joined: 02 Nov 2005
Posts: 38
estrang
I didnt see thnks.Smile
Post 12 Nov 2005, 09:11
View user's profile Send private message Reply with quote
estrang



Joined: 02 Nov 2005
Posts: 38
estrang
I decided to write my own function for learning purposes. And also becoz im having lots of problems with function 0Ah.

Can someone point me to what im doing wrong here?? The problem is commented below. tnks Smile.

Code:
org 100h

jmp start

start:
        mov dx, msg1 ;param for function call below
        call func_printString
        call func_inputString
        mov dx, msgbuffer
        call func_printString
terminate:
        mov ax, 4C00h
        int 21h
func_inputString:
         mov ax, 0600h
         mov dx, 00FFh
         int 21h
         ret

func_printString:
        mov cx, 0200h
  start_input:
        mov ax, 0900h
        int 21h
        cmp ah, 000Ah
        je exit_func
        mov byte [msgbuffer+cx], al ;Im trying to modify address in memory 
;by using a counter. Like pointer arithmethic in C.
 ;But how come this wont work? 
;Can someone tell me how to do a loop 
;correctly with also using a counter variable??
        inc cx
        jmp start_input
  exit_func:
        ret
texts:
 msg1 db 'Enter a String:', 24h
 mm:
 msgbuffer db 0Fh, ?, 0Fh dup( 00h ), 24h

                                                             


Updated Code. Still not working Sad
Code:
org 100h

jmp start

start:
        mov dx, msg1 ;param for function call below
        call func_printString
        call func_inputString
        mov dx, msgbuffer
        call func_printString
terminate:
        mov ax, 4C00h
        int 21h
func_inputString:
         mov cl, 02h
         mov ax, 0100h
  start_input:
         int 21h
         cmp al, ' '
         je exit_func
         mov [msgbuffer+msgctr], al
         inc [msgctr]
         jmp start_input
  exit_func:
         mov [msgbuffer], 0Ah
         mov [msgbuffer+1], 0Dh
         ret

func_printString:
        mov ax, 0900h
        int 21h
        ret
texts:
 msg1 db 'Enter a String:', 24h
 mm:
 msgbuffer db 0Fh, ?, 0Fh dup( 'x' ), 24h
 msgctr db 02h

    
Post 12 Nov 2005, 10:41
View user's profile Send private message Reply with quote
estrang



Joined: 02 Nov 2005
Posts: 38
estrang
I got it working. But i use SI instead of CX for my counter variable. Is this recommended??

Code:
org 100h

jmp start

start:
        mov dx, msg1 ;param for function call below
        call func_printString
        call func_inputString
        mov dx, msg2
        call func_printString
        mov dx, msgbuffer
        call func_printString
terminate:
        mov ax, 4C00h
        int 21h
func_inputString:
         mov si, 01h
         mov ax, 0100h
  start_input:
         int 21h
         cmp al, 0Dh
         je exit_func
         mov [msgbuffer + si], al
         inc si
         jmp start_input
  exit_func:
        mov [msgbuffer + si], 24h
        ret

func_printString:
        mov ax, 0900h
        int 21h
        ret
texts:
  msg1 db 'Enter a String: ', 24h
  msg2 db 0Ah, 'You entered the String: ', 24h
  msgbuffer db 0Fh dup( 00h ), 24h    
Post 12 Nov 2005, 12:24
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
maybe this... i am not sure about dup, i don't use it. and i suppose buffer[x] = [buffer + size_of_buffer_element*x]
Code:
org 100h 
                mov dx, buffer 
                mov ah, 0ah 
                int 21h 
                jmp print 
                buffer db 10, ?, 10 dup(' ') 
                print: 
                xor bx, bx 
                mov bl, [buffer + 1] 
                mov [bx+buffer + 2], '$' 
                mov dx, buffer + 2 
                mov ah, 9 
                int 21h 
                ret    
Post 14 Nov 2005, 16:07
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
estrang



Joined: 02 Nov 2005
Posts: 38
estrang
Thnks for the conversion. Though it doesnt seem to work like the emu8086 version.
Post 14 Nov 2005, 16:16
View user's profile Send private message Reply with quote
daluca



Joined: 05 Nov 2005
Posts: 86
daluca
Code:
org 100h
    mov dx,buffer ;WE SET DE BUFFER
    mov ah,0ah
    int 21h       ;AND CALL INT 21H FOR USER INPUT
;-----------------------
    jmp print     ;WE JUMP THE BUFFER
;-----------------------
    buffer db 10,?, 10 dup ' '  ;WE DEFINE THE BUFFER:
                                ;10 CHARACTERS MAXIMUM
                                ;IN THE ? THE INT 21 WILL
                                ;PUT A BYTE WITH THE NUMBER
                                ;OF CHARACTERS THE USER
                                ;INPUTED. 10 DUP ' ' MEANS
                                ;DUPLICATE 10 TIMES THE CHARACTER
                                ;THAT IS INSIDE THE QUOTES(= SPACE)
    print:
    xor bx,bx          ;WE MAKE BX = 0 ,FASTER THAN MOV BX,0
    mov bl,[buffer+1]  ;WE MOVE THE NUMBER OF CHARACTERS TYPED TO BL
                       ;[buffer] = 10,[buffer+1] = ?,
                       ;now bx = number of characters inputed
    mov [bx + buffer +2],'$' ;we move the $ sign to the end of the string
                             ;= buffer + lenght in bx + 2(to skip the 10,?)
;----------------------------
    mov dx,buffer+2   ;and print the result
    mov ah,9
    int 21h
    ret               ;and exit
    

if you compile this and run it you get the prompt were
you type your name and after presing enter it will look
like nothing hapens becouse your name is being printed
over your typed name, to see more clearly the result
after the mov [bx+buffer+2],'$' put the next line:
mov word[buffer],0a0dh
and instead of the line mov dx,buffer+2 put:
mov dx,buffer
so the line feed and carriage return get printed.
and you can see what you type.
if you want more characters just replace the 10's
with any value you want (up to 255)
Post 16 Nov 2005, 07:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic This topic is locked: you cannot edit posts or make replies.

Jump to:  
Goto page Previous  1, 2

< 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.