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

MARIE汇编双子程序合并问题:仅执行预定义打印,无法触发用户输入

Fixing MARIE Program Execution Flow When Merging Two Subroutines

Ah, I see the issue here—this is a classic program flow problem with MARIE's sequential execution model. When you just tack the second subroutine right after the first without adjusting the control flow, the first subroutine is probably ending with a Halt instruction, which stops the entire program dead in its tracks before it ever gets to your user input logic. Let's break down how to fix this step by step:

Key Problem

MARIE executes instructions in order from top to bottom unless explicitly told to jump elsewhere. If your first "print predefined string" subroutine ends with a Halt, the program will terminate immediately after printing the string—no chance for the second subroutine to run. Even if there's no Halt, you might still need to explicitly direct the program to jump to the start of the second subroutine to avoid accidentally executing leftover or unintended instructions between the two blocks.

Step-by-Step Fix

  1. Remove or replace the Halt in the first subroutine
    Instead of ending the first subroutine with Halt, use a Jump instruction to send the program counter directly to the start of your user input subroutine.

  2. Label your subroutines clearly
    Give each subroutine a unique, descriptive label so you can easily reference them in jump commands.

  3. Add a proper termination to the second subroutine
    Make sure the second subroutine has a Halt (or conditional exit logic) to end the program when needed—otherwise it might loop infinitely or behave unpredictably.

Example Working MARIE Code

ORG 100
; First Subroutine: Print Predefined String
PrintPredefined,  Load MsgAddr   ; Load address of our predefined string
                  Output         ; Print the string to console
                  Jump ReadNPrint; Jump to start of user input subroutine

MsgAddr,          DEC "Hello from predefined string!"
                  HEX 00         ; Null terminator for MARIE string

; Second Subroutine: Read and Print User Input Character-by-Character
ReadNPrint,       Input          ; Accept a single character from user
                  Output         ; Print the input character immediately
                  ; Optional: Add conditional exit here (e.g., check for Enter key: HEX 0D)
                  Jump ReadNPrint; Loop to keep accepting input (remove for single input)
                  Halt           ; Uncomment if you add an exit condition above

Explanation

  • After printing the predefined string, Jump ReadNPrint forces the program to move directly to the user input subroutine instead of stopping.
  • The second subroutine uses a loop (Jump ReadNPrint) to keep accepting and printing characters until you add a conditional check (like comparing the input to the ASCII value of the Enter key) to trigger the Halt.

If you originally had a Halt at the end of the first subroutine, that's definitely why the second subroutine never ran—MARIE stops execution as soon as it hits that instruction. Adjusting the control flow with jumps is the core fix here.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:18:49