简单的 8086 组装字符串数组和打印

Simple 8086 Assembly String Array and Printing

我必须为我的程序集 class 编写一个程序,允许用户输入 his/her 全名,然后该程序使用数组来存储字符并按以下顺序打印它们: "LastName", "Middle"(可选,可以有多个中间名" "First"。我已经让我的程序几乎做到了这一点,只是它在姓氏。我曾尝试增加索引 (bx),但随后输出出现乱码。我对汇编还很陌生,所以请多多包涵。我认为当我增加索引时,我的宏可能会干扰我的输出. 也请忍受我的格式。我永远无法正确传输代码。在此先感谢!

这是我的代码:

       ;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

从我在你的代码中看到的情况来看,你似乎正确地找到了姓氏。由于姓氏前的 space 代表名字和中间名的结尾,因此将 space 替换为姓氏前的 $ 符号是有意义的。由于 BX 是您刚刚输入的美元符号的偏移量,因此您应该将 BX 递增 1 以跳过它。然后,您还需要将 Count 变量减 1。

此代码:

mov [CharStr+bx],'$'
_PutStr Message2
jmp Printlast

大概应该是这样的:

mov [CharStr+bx],'$'
inc bx
dec Count
_PutStr Message2
jmp Printlast