Problems with reading char and moving to string

Started by xaviergxf, November 18, 2006, 06:26:43 PM

Previous topic - Next topic

xaviergxf

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

MichaelW

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?
eschew obfuscation

xaviergxf

ops .. this add al,30h was a mistake...

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

Thanks

eek


sinsi

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
Light travels faster than sound, that's why some people seem bright until you hear them.

xaviergxf

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

Zest

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