Hi There,

I'm trying to learn a bit of assembler and have got the grasp of the majority of the basics. However I'm struggling to allow a user to enter a string, terminated by a null character when the user hits carriage return. I'd also like to be able to print the string back out afterwards. I'm using NASM. I've got the following code so far:

.bss
Stringbuff resb 0100H


Sub Routines:

GetString:
push AX ; Store value of AX
push DX ; Store value of DX
mov DI, Stringbuff ; Set start address of StringBuff Array
cld
DoGet:
call Getinput ; Gets 1 char input and places in DL
call Printchar ; Prints character in DL (echos input as you type)
cmp AL, 0DH ; Check to see if input is a carriage return
je End ; if it is then end the inputting
stosb ; else store the character in the array
jmp DoGet ; Loop

End:
mov AL, 000H ; Move null termination value into AL
stosb ; Add null termination to the end of the array
pop DX ; restore DX
pop AX  ; Restore AX
ret

;********************************************
PutString:
push AX ; Store value of AX
push DX ; Store value of DX
MOV SI, Stringbuff      ; Move offset of stringbuff into SI
DoPrintString:
lodsb                        ; Load the character from string array
cmp AL, 0H                ; Check to see if we've hit the null termination character     
jle Finish                    ; If we have, finish
        mov DL,AL                  ; Else: Move character into  DL ready to print
call Printchar ; Prints character in DL
jmp DoPrintString        ; Start reading loop again
Finish:
pop DX ; restore DX
pop AX  ; Restore AX
ret


Main:

call GetString
call Putsring



The problem:
Well my program seems to allow me to enter the string ok, but then it doesnt print anything back out. If i remove the following lines from the putstring sub it sucessfully prints only the first character i input. But with the following lines in it prints none of the input


cmp AL, 0H                ; Check to see if we've hit the null termination character     
jle Finish                    ; If we have, finish
jmp DoPrintString        ; Start reading loop again

Posted on 2009-03-27 08:17:34 by Flux
I believe your problem is here
cmp AL, 0H                ; Check to see if we've hit the null termination character     
jle Finish                    ; If we have, finish


consider this:
xor al, al
dec al, al (AL is minus 1 now!)
cmp al, 0
jle address (you may compare AL to minus 1 which will always jump)

maybe try just cmp al, 0 and then JE address since 00 is your terminating string and nothing else
Posted on 2009-04-01 09:48:59 by GoldStar611