title: Simple 8086 Assembly String Array and Printing
body: <p>I have to write a program for my Assembly class that allows the user to enter his/her full name and the program then utilizes and array to store the characters and print them in the following order: "LastName", "Middle"(Optional and can have more than one middle name" "First".  I have gotten my program to almost do this except it prints out a '$' at the start of the Last name. I have tried incrementing the index (bx) but then it gives me a garbled output. I am fairly new to assembly so please bear with me. I am thinking my macros might be interfering with my output when I increment the index. Also please bear with my formatting. I can never transfer code correctly. Thanks in Advance!</p>
  
  <p>Here is my code:</p>
  
  <pre><code>       ;This Program Reads in a user's full name and prints out the results in the format 
          'Lastname', 'Middle'(Optional), First using an array. 
  
   include pcmac.inc
  .MODEL SMALL
      .586  ;Allows Pentium instructions. Must come after .MODEL
  
      .STACK 100h
  
      .DATA
   MAXBUF EQU 100
   GetBuf DB MAXBUF
   GetCnt DB ?
   CharStr DB  MAXBUF DUP (?)
   Message DB 'Enter your full name',10,13,'$'
   Message2 DB 'Here is your name in the correct format', 10,13,'$'
   Count DB 0
  
      .CODE
  Array PROC  
      _Begin
      _PutStr Message
      _GetStr GetBuf
  
  
  mov bl, GetCnt
  sub bh,bh
  
     FindLast:
  
     cmp [CharStr+bx],32
     je SeperateLast
     dec bx
     inc Count        ;Counter to record how long the lastname is
     jmp FindLast
  
  
  
    SeperateLast:
  
       mov [CharStr+bx],'$'
      _PutStr Message2
      jmp Printlast
  
  
  
   FirstName:
  
       _PutCh ',',32              ;Add comma and space for readability
       _PutStr CharStr            ;Print up to the inputted dollar sign
       _PutCh 10,13
  
       jmp Done
  
  
     Printlast:
  
        cmp Count,0    
        je FirstName
        _PutCh[CharStr+bx]           ;Print Last Name Character by Character
        inc bx
        dec Count
        jmp Printlast
  
  Done:
  
  
       _Exit 0
           Array ENDP
  
                END Array
  </code></pre>