6 Replies - 15044 Views - Last Post: 28 January 2012 - 06:23 AM

#1 Fredex  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 86
  • Joined: 16-January 12

how to display the input string in TASM 2.O, such entering username..

Posted 24 January 2012 - 04:12 AM

Title greeting
.model medium
.stack 10h
.data
prompt db "Enter your name:$"
greet db "Hello $"
nam db 7 dup(?)
stop_nam db,10,13,"$"

.code
mov ax,@data
mov ds,ax

mov ah,9
lea dx,prompt
int 21h

mov cx,7

balik:
mov si,cx
mov ah,7
int 21h

mov nam[si],al

loop balik

mov cx,2

ulit:
mov ah,2
mov dl,10
int 21h

mov dl,13
int 21h
loop ulit

mov ah,09h
lea dx,greet
int 21h

mov cx,7

balik2:
mov si,cx
mov ah,2
mov dl,nam[si]
int 21h
loop balik2

mov ah,4ch
int 21h

end


my problem is how to display input in asterisk form and such that:
Enter your name:******
Welcome Fredex
In this case I discover that we need to enter the input into buffer and get it again..but I dont know how to apply ;it..Share if you have knowledge about it..

This post has been edited by no2pencil: 24 January 2012 - 04:15 AM
Reason for edit:: Corrected code tags


Is This A Good Question/Topic? 0
  • +

Replies To: how to display the input string in TASM 2.O, such entering username..

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10396
  • View blog
  • Posts: 38,464
  • Joined: 27-December 08

Re: how to display the input string in TASM 2.O, such entering username..

Posted 24 January 2012 - 08:08 AM

Please post your Assembly questions in the Assembly forum. Moved to Assembly.
Was This Post Helpful? 1
  • +
  • -

#3 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: how to display the input string in TASM 2.O, such entering username..

Posted 24 January 2012 - 06:36 PM

Well, you are getting characters typed WITHOUT echo - int 21/ah7. So it is up to you to display whatever you want with int 21/ah9.

I forgotten the nuances of TASM so I re-wrote your code in MASM, it is basically the same thing. Why in the world are you using TASM 2.0? A bit ancient no?

Got rid of the loop to "display" CRLF instead just printed it to screen, and rewrote your balik loop, no need for the slow loop instruction
prompt  db  'Enter your name (7 Chars Max):$'
greet   db  "Hello $"
nam     db  8 dup(?) ; 7 plus term char $
Ast     db  "*$"
crlf    db  13, 10, 24H


main   proc
    mov     ax, seg prompt
    mov     ds,ax
    
Start:   
    ; Display Name prompt
    lea     dx, prompt
    mov     ah, 9
    int     21h

    mov     cx, 7   ; get 7 chars   
    lea     si, nam ; buffer to hold name
    lea     dx, Ast ; display *
    
balik:
    ; get char typed
    mov     ah, 7
    int     21h
    ; save in our buffer, current pos in si
    mov     byte ptr[si], al
    
    ; Display Asterick
    ; Asterick already in dx
    mov     ah, 9
    int     21h
    
    ; increase our buffer pointer
    inc     si
    
    ; No need for the "slow" loop instruction
    dec     cx
    jnz     balik

    ; properly terminate our string
    mov     byte ptr[si], "$"

    ; insert blank line
    lea     dx, crlf
    mov     ah, 9
    int     21h
    
    ; display hello
    lea     dx, greet
    mov     ah, 9
    int     21h

    ; Now display entered name
    lea     dx, nam
    mov     ah, 9
    int     21h

    ; exit
    mov     ah, 4ch
    int     21h
main   endp
end main



Please get into the habit of commenting your code!!!

This is the output:
Attached Image
Was This Post Helpful? 1
  • +
  • -

#4 Fredex  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 86
  • Joined: 16-January 12

Re: how to display the input string in TASM 2.O, such entering username..

Posted 26 January 2012 - 08:36 PM

View PostGunnerInc, on 25 January 2012 - 01:36 AM, said:

Well, you are getting characters typed WITHOUT echo - int 21/ah7. So it is up to you to display whatever you want with int 21/ah9.

I forgotten the nuances of TASM so I re-wrote your code in MASM, it is basically the same thing. Why in the world are you using TASM 2.0? A bit ancient no?

Got rid of the loop to "display" CRLF instead just printed it to screen, and rewrote your balik loop, no need for the slow loop instruction
prompt  db  'Enter your name (7 Chars Max):$'
greet   db  "Hello $"
nam     db  8 dup(?) ; 7 plus term char $
Ast     db  "*$"
crlf    db  13, 10, 24H


main   proc
    mov     ax, seg prompt
    mov     ds,ax
    
Start:   
    ; Display Name prompt
    lea     dx, prompt
    mov     ah, 9
    int     21h

    mov     cx, 7   ; get 7 chars   
    lea     si, nam ; buffer to hold name
    lea     dx, Ast ; display *
    
balik:
    ; get char typed
    mov     ah, 7
    int     21h
    ; save in our buffer, current pos in si
    mov     byte ptr[si], al
    
    ; Display Asterick
    ; Asterick already in dx
    mov     ah, 9
    int     21h
    
    ; increase our buffer pointer
    inc     si
    
    ; No need for the "slow" loop instruction
    dec     cx
    jnz     balik

    ; properly terminate our string
    mov     byte ptr[si], "$"

    ; insert blank line
    lea     dx, crlf
    mov     ah, 9
    int     21h
    
    ; display hello
    lea     dx, greet
    mov     ah, 9
    int     21h

    ; Now display entered name
    lea     dx, nam
    mov     ah, 9
    int     21h

    ; exit
    mov     ah, 4ch
    int     21h
main   endp
end main



Please get into the habit of commenting your code!!!

This is the output:
Attachment Hello.png


thanks for your help..now I've learn something, Can you tell me a few differences between TASM and MASM, and the equivalent of some codes from TASM to MASM..THANKS again very much.
Was This Post Helpful? 0
  • +
  • -

#5 Fredex  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 86
  • Joined: 16-January 12

Re: how to display the input string in TASM 2.O, such entering username..

Posted 27 January 2012 - 05:04 AM

what is the meaning and purpose of the code "byte ptr" and "crlf? Is there other alternative code to it?
Was This Post Helpful? 0
  • +
  • -

#6 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: how to display the input string in TASM 2.O, such entering username..

Posted 27 January 2012 - 05:57 PM

I guess it is not needed for 16bit code, but it helps make your code self-documenting. If you were to move al to si, you would need it in 32 bit and above though.

What is crlf? It is in the code above in the strings: crlf db 13, 10, 24H it is a carrage return, line feed and a string terminator.
Was This Post Helpful? 1
  • +
  • -

#7 Fredex  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 86
  • Joined: 16-January 12

Re: how to display the input string in TASM 2.O, such entering username..

Posted 28 January 2012 - 06:23 AM

Thank you very much again for you explanation..I've understand it well.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1