confusion in asembly language

Programming, for all ages and all languages.
Post Reply
vishal
Posts: 17
Joined: Sun Nov 11, 2007 3:30 pm

confusion in asembly language

Post 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....
Last edited by vishal on Fri Dec 07, 2007 12:12 am, edited 1 time in total.
User avatar
ManOfSteel
Member
Member
Posts: 60
Joined: Tue Feb 01, 2005 12:00 am

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

you mean the ascii code for enter...? i thought everyone knew that!


btw, its 0x13...
vishal
Posts: 17
Joined: Sun Nov 11, 2007 3:30 pm

Post 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
User avatar
ManOfSteel
Member
Member
Posts: 60
Joined: Tue Feb 01, 2005 12:00 am

Post 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?
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

@JAAman:
You mean 13 (in decimal).
doh! i knew i was going to do that... mixing my decimal and hex :oops:
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

reply

Post 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
Matías Beretta
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post 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.
Author of COBOS
User avatar
ManOfSteel
Member
Member
Posts: 60
Joined: Tue Feb 01, 2005 12:00 am

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