2 years ago

#67406

test-img

JustAsking

How to write output with buffer in assembly

I have the following code

.model small
.stack 100h 
.data
 msg         db 10, 13, "Introduce string: $"
 bufferSize  db 21  ; 20 char + RETURN
 inputLength db 0   ; numarul de caractere citite - number of characters
 buffer      db 21 DUP("$") ; actual buffer

 .code
   main proc

  mov ax, @data ; ma mut in segmentul de date
  mov ds, ax
  lea dx, msg
  mov ah, 09h ;output
  int 21h

  mov dx, offset bufferSize ; load our pointer to the beginning of the structure
  mov ah, 10 ; GetLine function - 10 este 0A in zecimal, folosim pentru afisarea imputului cu 
  buffer
  int 21h

   mov ax, @data 
   mov ds , ax 
   lea dx, buffer
   mov ah, 09 ;output
   int 21h

   endp
   end main  

I am using TASM and i have a dosbox installed. When i run this code and i write the string i want to output, it overrides with what was already in dx, which is the message. It shows something like this:

Introduce string : Hello, world ==> it outputs Hello, worldtring : How do I correct this? Also i'd like to output the lenght of my string as well and i don't know how to do that. Any ideas ?

assembly

tasm

0 Answers

Your Answer

Accepted video resources