You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MARIE汇编语言:实现含$终止符的姓名输入及带空格打印功能的技术问询

Fixing the Missing Space Between First and Last Name in Your MARIE Assembly Program

Hey there! Let's get that space showing up between the first and last name when your program prints. The root issue is that your current code doesn't insert a space character into memory after capturing the first name, right before starting to store the last name. Here's how to adjust your code and resolve this:

Modified Full Code

/main 主程序
FirstNameLoop, JnS SubInputFirstName
Load Name
Add One
Store Name
Jump FirstNameLoop

LastNameLoop, JnS SubInputLastName
Load Name
Add One
Store Name
Jump LastNameLoop

/输入名的子程序
SubInputFirstName, Hex 0
Input
Store Temp
Subt Comma
Skipcond 400
Jump StoreFirstName
; When comma is detected, store space first
Load Space       
StoreI Name      
Load Name        
Add One
Store Name
Jump LastNameLoop

StoreFirstName, Load Temp
StoreI Name
JumpI SubInputFirstName

End, JnS subPrintString
Load NamePrint
Add One
Store NamePrint
Jump End

Finish, Halt

/输入姓的子程序
SubInputLastName, HEX 0
Input
Store Temp
Subt Dollar
Skipcond 400
Jump StoreLastName
Jump End

StoreLastName, Load Temp
StoreI Name
JumpI SubInputLastName

/打印姓名的子程序
subPrintString, HEX 0
LoadI NamePrint
Store Temp
Subt Dollar       ; Check for end marker ($) instead of period
Skipcond 400
Jump PrintName
Jump Finish

PrintName, Load Temp
Output
JumpI subPrintString

NamePrint, HEX 300
Dollar, Dec 36
Name, HEX 300
One, DEC 1
Temp, DEC 0
Space, DEC 32
Comma, DEC 44
Period, DEC 46

Key Changes Explained

  • Inserting the Space: In the SubInputFirstName routine, when the program detects the comma (your first/last name separator), we now:

    1. Load the Space value (ASCII 32)
    2. Store it at the current Name memory location
    3. Increment the Name pointer to move past the space
    4. Jump to the last name input loop
      This ensures a space is stored between the end of the first name and start of the last name.
  • Fixing the Print Termination: I also adjusted the subPrintString routine to check for the Dollar character (ASCII 36) instead of Period to properly stop printing when it reaches the end marker you're using (since users input $ to finish). Your original code was checking for a period, which wasn't aligned with your input termination logic.

Now when you run the program:

  1. Enter your first name characters, finish with a comma (e.g., John,)
  2. Enter your last name characters, finish with $ (e.g., Doe$)
  3. The program will print John Doe with the proper space in between!

内容的提问来源于stack exchange,提问作者Bryan Hii

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 08:24:19