【发布时间】:2015-12-05 03:16:26
【问题描述】:
我必须为我的 Assembly 类编写一个程序,该程序允许用户输入他/她的全名,然后程序利用数组来存储字符并按以下顺序打印它们:“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
【问题讨论】:
-
我唯一能建议的就是这个。您似乎正确地找到了姓氏,并在姓氏之前用 $ 符号替换了空格(这似乎是正确的)。在我看来,您想通过将
BX递增 1,然后将 Count 递减 1 来跳过 $ 符号。因此,在mov [CharStr+bx],'$'之后尝试添加inc bx,然后添加dec Count -
做到了。我只是增加 BX 而忘记减少计数。谢谢!它没有显示将您的答案标记为正确答案的箭头。我会弄清楚并让你代表你。谢谢!
标签: arrays assembly x86-16 dosbox