5 Replies - 10384 Views - Last Post: 28 June 2012 - 07:19 PM

#1 minsu44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-June 11

problem basic user input and printing[TASM]

Posted 28 June 2012 - 07:13 AM

Hello i am really just a begginner in assembly (TASM).
anyway, my program is quite simple it is tasked to just ask the user's name and ID number. after which i have to print "hello <name> your ID is <number>"

but I cant seem to print both of them at the same line. the second user input seems to over write the first user input for some odd reason.


the out put should be:
hello, <name> your ID is: <number>

but it keeps getting over written and usually its like
hello, <number> or <number> <part of name>

help please?

TITLE simple proj
         DOSSEG
         .model SMALL
         .stack 100h
         .data
GREET    db "Hello, $"
PNAME    db "Name: $"
SNAME    db 24 dup("$")
CRLF     db 13,10,"$"
PID      db "ID# : $"
SID      db 12 dup("$")
URID	 db "! Your ID number is: $"

         .code

BEGIN:mov ax, @data
          mov ds, ax
          mov es, ax
		  

          mov al, 03h    		 	; clear screen
          mov ah, 00h
          int 10h

		 
		  
	 mov dx, OFFSET PNAME		; Print NAME: 
          mov ah, 09h				
          int 21h					
		  
		
          mov byte ptr SNAME, 21
          mov dx, OFFSET SNAME		; scanf Name		
          mov ah, 0Ah
	int 21h

	mov	dx, OFFSET CRLF 	; print \n
          mov ah, 09h
          int 21h
		  
          mov dx, OFFSET PID  		; Print ID:			
          mov ah, 09h
          int 21h


          mov byte ptr SID, 9
          mov dx, OFFSET SID 		; Scanf ID			
          mov ah, 0Ah
		  int 21h
		  
		  
	 mov	dx, OFFSET CRLF 	; print \n
          mov ah, 09h
          int 21h


	mov	dx, OFFSET GREET	; print Hello,
          mov ah, 09h
          int 21h


          mov SI, 0002
          lea DX, SNAME[SI]  		; Print Name Entered
          mov ah, 09h
		  int 21h
		 
		 
	mov dx, OFFSET GREET		; print URID
          mov ah, 09h
          int 21h
		  
		  
	mov SI, 0002
          lea DX, SID[SI]  		; Printf ID Entered
          mov ah, 09h
	int 21h
		  
		
          mov ah, 4ch
          int 21h
          end BEGIN



Is This A Good Question/Topic? 0
  • +

Replies To: problem basic user input and printing[TASM]

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,281
  • Joined: 28-March 11

Re: problem basic user input and printing[TASM]

Posted 28 June 2012 - 04:01 PM

Is this for school? Is that why you are using TASM? TASM is a bit old and outdated. Many opcodes are not supported. Is that why you are also using 16bit DOS code?

Anyway, you need to make a buffer large enough for all of your strings and concate all the strings together to display them. Or just display the name on one line and the id on another.
Was This Post Helpful? 0
  • +
  • -

#3 minsu44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-June 11

Re: problem basic user input and printing[TASM]

Posted 28 June 2012 - 06:15 PM

Actually yes, they want us to try the basics.

oh there is actually concate or is it that we try to merge the 2 different strings by saving them in an address one after the other?

unfortunately the task was try to print them in one line. so i was thinking maybe there is something like an opposite of carriage return character. meaning after it prints the first input, it can point to the end of line then start printing other things.

Thanks so much for the reply and taking your time to look at this. as for now though i am trying to read up on the so many different functions available in TASM, so its really confusing since i just started
Was This Post Helpful? 0
  • +
  • -

#4 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,281
  • Joined: 28-March 11

Re: problem basic user input and printing[TASM]

Posted 28 June 2012 - 06:20 PM

Ok, had to brush up on my 16bit. You need to use INT 10/AH=2, this is the set cursor position interrupt.

AH = 2
BH = 0
DH = row (0 is top line)
DL = column (0 is left)

How do you set DH (The row)? Use a register or variable to keep track of your CRLFs and add 1 to that total.

How do you set the DL (Column/Cursor pos):
        xor     bx, bx
        mov     bl, SNAME[1]            ; Get entered string len
        
        mov     dx, offset [SNAME + 2]  ; pointer to beginning of string
        mov     ah, 09h
        int     21h                     ; Print name

        mov     al, bl                  ; mov strin len to al
        add     al, 7                   ; add 7 for "Hello, " len
        
        mov     dh, 2
        mov     dl, al
        mov     bh, 0
        mov     ah, 2h
        int     10h                     ; move cursor to column/Row

        ; print your ID string here



And this is the output:

Attached Image
Was This Post Helpful? 0
  • +
  • -

#5 minsu44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-June 11

Re: problem basic user input and printing[TASM]

Posted 28 June 2012 - 07:16 PM

Oh my goodness, i never knew you could (and have to) do that.
Thank you so much. i know this must've been a bit time consuming and the fact you did not have to help me. but Thank you so much, i really didnt know the capability of some functions (int 10h particularly). But it makes sense now since you clarified their meaning.
Was This Post Helpful? 0
  • +
  • -

#6 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,281
  • Joined: 28-March 11

Re: problem basic user input and printing[TASM]

Posted 28 June 2012 - 07:19 PM

THE place for DOS interrupts is Ralf Brown's Interrupt List
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1