title: Printing a String with a Start and Length Assembly Language
body: <p>I was trying to build an Assembly Code, that ask for a string, start where the string would be printed and the desired length to be printed. <em>assume start and length are always valid</em> Can you help me to determine the start and length.</p>
  
  <p>How it should work:</p>
  
  <pre><code>Enter String: Hello World
  Enter Start: 3
  Enter Length: 5
  Mid-String: llo W
  </code></pre>
  
  <p>So I have a problem on how to determine the start and length of the string. I tried several things which is shown in my code below:</p>
  
  <pre><code>.model small
  .stack
  .data
  msg1 db "Enter String:$"
  msg2 db 13,10,"Enter Start:$"
  msg3 db 13,10,"Enter Length:$"
  msg4 db 13,10,"Mid-String:$"
  nwln db 13,10
  mySample label byte
  maxlen db 10
  actlen db 0
  string db 19 dup (?)
  .code
  mov ax,@data
  mov ds,ax
      lea dx, msg1 ;print msg1
      mov ah,9
      int 21h
  
      lea dx,mySample ;accept string
      mov ah,0Ah
      int 21h
  
      mov bh,0
      mov bl,maxlen
      mov string[bx],'$'
      mov ah,9
      lea dx,string   ;print string accept
      int 21h
  
      lea dx, msg2    ;print msg2 and accept start
      mov ah,9
      int 21h
      mov ah,1
      int 21h
      sub al,30h
      mov bh,0
      mov bl,al
  
      lea dx, msg3    ;print msg3 and accept length
      mov ah,9
      int 21h
      mov ah,1
      int 21h
      sub al,30h
      mov dl,al
  
      ;mov maxlen,dl
      mov bh,0
      mov bl,maxlen
      mov string[bx],'$'
      lea dx,msg4     ;print msg4
      mov ah,9
      int 21h
      lea dx,string   ;print mid-string
      int 21h
  mov ah,4ch
  int 21h
  END
  </code></pre>
  
  <p>OUTPUT LOOKS LIKE:
  <a href="https://i.stack.imgur.com/gROkB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gROkB.jpg" alt="output from the code above"></a></p>