Page 1 of 1

confusion in asembly language

Posted: Thu Dec 06, 2007 12:21 am
by vishal
i am trying to display a string entered by the user but it is not giving any ouptut. plz help.

i dont know the code for the enter key so i have used '+' instead
i have made
Print : for displaying a string using int 10h
GET_CHAR : for netering a character
COM1 : for moving COMMAND (the string to be displayed) into si and to call Print
and finally the start:

Code: Select all

jmp start
Print:
lodsb							
or 			al, al				
jz 			PrintDone			
mov			ah,	0eh			
int			10h
jmp			Print				
PrintDone:
			ret

GET_CHAR:	
MOV  			AH,00
INT 			0x16     ;character is stored in AL register      
RET

COM1 :				; this procedure moves COMMAND into si and displays it using Print
xor 			si,si	
mov 			si,COMMAND
CALL 			Print
ret

start:			
xor 			si,si
			mov cx,0000H
LBL1 :	
			CALL GET_CHAR   ;call get_char to enter a character
			CMP AL,'+'	;i dont know the code for enter so written '+' instead
			JE LBL2		;if '+' has been entered the string is over
			inc cx			
			mov BYTE[si],al ;else store the next character in COMMAND
			call Print           :to display the character entered
			inc si
 			jmp LBL1
LBL2 :
mov BYTE[si],0 				;make last character 0
inc cl
sub si,cl
mov di,[COMMAND]			;copy the string from si to COMMAND
mov [di],si
call COM1
jmp $
COMMAND db 0
please point out any other errors if any....

Posted: Thu Dec 06, 2007 7:03 am
by ManOfSteel
Try making the buffer (COMMAND db 0) bigger as you will cause a buffer overflow when the command is more than one character long.

Print should work when used as in COM1:, but probably won't work in LBL1: since si points to address 0 (xor si,si after start:).

Try this instead:

Code: Select all

start:
mov si,COMMAND
...
inc cx
mov BYTE[si],al
mov ah,0eh
int 10h
inc si
jmp LBL1
...
(BTW, xor si,si in COM1: is useless).

Code: Select all

mov di,[COMMAND]         ;copy the string from si to COMMAND
This will only copy the first byte of COMMAND into di.

Posted: Thu Dec 06, 2007 7:54 am
by Combuster
i dont know the code for the enter key so i have used '+' instead
:shock: (I thought we put up a link to this in a prominent location)

Posted: Thu Dec 06, 2007 10:02 am
by JAAman
you mean the ascii code for enter...? i thought everyone knew that!


btw, its 0x13...

Posted: Fri Dec 07, 2007 12:10 am
by vishal
i am sorry about that enter key code as i am so messed with program....

i want to write a program that stores the string entered by the user in a string variable and then display it with the help of the string variable

in the above code i store the string in COMMAND and later print it but am unable to do it ...

ManOfSteel thanks a lot for your help but iwas unable to do so by your modifications

Combuster,JAAman thank you for replies

plz somebdy help

Posted: Fri Dec 07, 2007 12:31 pm
by ManOfSteel
@JAAman:
You mean 13 (in decimal).

@vishal:
What I suggested in my last post is enough to make it work.
So what's the problem? What's happening? What does it display? Does it crash? Please, post the modified code.
You're writing it for DOS, right? You didn't forget the org 100h, did you?

Posted: Sun Dec 09, 2007 10:00 am
by JAAman
@JAAman:
You mean 13 (in decimal).
doh! i knew i was going to do that... mixing my decimal and hex :oops:

reply

Posted: Sat Dec 15, 2007 4:38 pm
by matias_beretta
here is the code you want:

Code: Select all

org 100h

mov si, String1
call print
mov di, String2
call input
mov si, String3
call print
mov si, String2
call print
mov si, String4
call print
mov ah, 0h
int 16h
ret

String1:
   db "What is your name?", 13, 10, 0
String2:
   rb 11
String3:
   db 13, 10, "Your name is ", 0
String4:
   db '.', 13, 10, 0

print:
   mov ah, 0eh
   .a:
      mov al, [si]
      inc si
      cmp al, 0
      je .b
      int 10h
      jmp .a
   .b:
      ret

input:
   mov cx, 0
   .a:
       mov ah, 0h
       int 16h
       cmp al, 0dh
       je .b
       cmp cx, 10
       je .a
       mov [di], al
       inc di
       mov ah, 0eh
       int 10h
       inc cx
       jmp .a
    .b:
       mov byte [di], 0
       ret

Posted: Mon Dec 17, 2007 2:00 am
by os64dev
Might i point out that giving the 'solution' code does not help developers. It only helps them to get to the next problem faster without understanding what they are doing. If you want the help point to the faulting code and explain why it is wrong and let them come up with the solution.

Posted: Mon Dec 17, 2007 7:06 am
by ManOfSteel
os64dev, I can't agree more.
let them come up with the solution
I was waiting for that to happen. After posting enough suggestions and corrections, I waited for days but the OP never replied. Considering the oddly written and sometimes totally incomprehensible and useless code in the source and then the sudden loss of interest of the OP when I asked for the corrected code, I'm suspecting he wants to "program" without even knowing the very basics of assembler.