The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: xaviergxf on November 18, 2006, 06:26:43 PM

Title: Problems with reading char and moving to string
Post by: xaviergxf on November 18, 2006, 06:26:43 PM
Hi everyone,

I´m trying to do a program that reads some characters like '1', '2,'...,'9', '+', '-'. the program stops reading when the buffer of the string is full or if the user had entered "--". Here´s my code:

.data
    string db 20 dup("$")
    contador WORD 0
    menoscont db 0

.code
start:

Lecarac:
    xor ax,ax
    mov si,0
    mov ah,1h
    mov dl,0Dh
    int 21h
    add al,30h
    mov string[si], al
    inc si
    cmp al, "-"
    jnz Lecarac
    inc menoscont
    cmp menoscont, 2
    jnz Lecarac
Fimleitura:
    mov contador, si

Aparently there´s a problem with the si register, when i try to move to zero.
Can someone tell me what am i doing wrong?

Thanks
Title: Re: Problems with reading char and moving to string
Post by: MichaelW on November 18, 2006, 07:05:23 PM
I put your code between code tags to make it a little easier to read.

You are inputting characters, and putting characters in the string, so what is the add al,30h for?
Title: Re: Problems with reading char and moving to string
Post by: xaviergxf on November 18, 2006, 09:21:15 PM
ops .. this add al,30h was a mistake...

But beyond this mistake there others ..
Did someone know what have i done???

Thanks
Title: Re: Problems with reading char and moving to string
Post by: eek on November 19, 2006, 02:06:18 AM
mov string[si],al

Is that a valid instruction?
Title: Re: Problems with reading char and moving to string
Post by: sinsi on November 19, 2006, 02:48:19 AM
Every time you loop back to Lecarac: you are resetting SI back to 0, so put it before the label -
start:
  mov si,0
Lecarac:
  mov ah,1
  int 21h
  ...

You can also use SI as a counter instead of menoscont
Title: Re: Problems with reading char and moving to string
Post by: xaviergxf on November 19, 2006, 03:53:31 PM
I´ve tryed like that but when i run the program it doesn´t work. I think this mighty been something related to the int 21 function

Thanks
Title: Re: Problems with reading char and moving to string
Post by: Zest on November 23, 2006, 02:17:12 PM
Hi,
This is not related to your code but it shows how to correct some parts in your code.
I hope it can help you.
Regards,
Zest.


TITLE To Read A Char And Move it to A String
PAGE 60,133

.DOSSEG

stseg SEGMENT STACK 'STACK'
      BYTE 4*1024 DUP(?)
stseg ENDS

dtseg SEGMENT PARA PUBLIC 'DATA'
    string db 20 dup("$")
    contador WORD 0
    menoscont db 0
    PtrString  DWORD  string
     
dtseg ENDS

cdseg SEGMENT PARA PUBLIC 'CODE'
      ASSUME cs:cdseg,ds:dtseg,ss:stseg,es:dtseg
     
main PROC FAR
     mov ax,SEG dtseg
     mov ds,ax
     mov es,ax
     
     mov si,0
     les si,PtrString
     mov ax,'a'
     
@@:  mov es:[si],ax
     inc si
     cmp si,14
     jne @b
     mov BYTE PTR es:[si+1],'!'
     mov ah,9h
     mov dx,OFFSET string
     int 21h
     
     
     

     
     xor ax,ax ;Waiting for a KeyPress
     int 16h
     
     mov ah,4ch
     int 21h
main ENDP
cdseg ENDS

PUBLIC main
END main