【问题标题】:Insert a line break into Assembly code Easy 68k (68000)在汇编代码 Easy 68k (68000) 中插入换行符
【发布时间】:2011-12-19 19:01:30
【问题描述】:

我对汇编很陌生,我正在尝试构建一个小程序。我不知道如何使用 Easy68k 在汇编中插入换行符。例如,我开始编写基本的黑杰克模拟器,我需要在问候第一个玩家后进行换行。我尝试将“\n”合并到变量声明中,但它只是打印出来,就好像它是文本的一部分。

根据 Easy 68K Help I/O 部分,我可以使用 “LF EQU $0A 新行(换行)”但我不知道如何实现这一点。

START   ORG        $400             ; Start of program area
    CLR.L      D0               ; Clear D0
    CLR.L      D1               ; Clear D1
    CLR.L      D2               ; Clear D2
    CLR.L      D3               ; Clear D3
    CLR.L      D4               ; Clear D4
    CLR.L      D5               ; Clear D5
    CLR.L      D6               ; Clear D6
    MOVE.L     playerTotal, D2  ; Store Player total in D1
    MOVE.L     card, D3         ; Store current card in D2
    MOVE.B     playerAce, D4    ; Store number of aces player has in D3
    MOVE       #14, D0      
    LEA        playerGreeting, A1   ; Load Player Greeting in A1
    TRAP       #15              ; Display Player Greeting
* insert line break     
    STOP       #$2700  ; Stop execution

        ORG         $1000   ;Start of data area
playerTotal DS.L        1       ; Save 1 byte of memory for playerTotal
dealerTotal DS.L        1       ; Save 1 byte of memory for dealerTotal
card        DC.L        5       ; Save 1 byte of memory for card dealt
keepPlaying DS.B        1       ; Save 1 byte of memory for Play again value
playerAce   DS.B        1       ; Save 1 byte of memory to track player Aces
playerGreeting  DC.B        'Hello Player 1!', 0    ; Message 

                LF        EQU       $0A
                END     START                  ; End of program and entry point

【问题讨论】:

    标签: assembly 68000


    【解决方案1】:

    试试这个:

    CR EQU $0D
    LF EQU $0A
    playerGreeting  DC.B        'Hello Player 1!',CR,LF,0    ; Message
    

    这将在您的消息后插入回车符 (CR) 和换行符 (LF)。基本上,它会在空终止符 (0) 之前在输出字符串中添加两个附加字符。

    【讨论】:

    • 天啊,太棒了。谢谢!!!对于任何未来的读者,请确保在 info 部分中将 CR 定义为“CR EQU $0D ;Carriage Return”(除了 LF)。
    • @kelly,说得好。我更新了答案以使其更清楚。
    • 有什么特别的原因需要回车吗?我很困惑到底什么是马车。换行不是足以停止字符串并向下移动吗?
    • @kaz 这取决于您要做什么。新行只是将光标向下移动一行,但它保留在同一列中。回车将光标移动到行首。两者结合起来就像一台“打字机”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    • 2011-09-26
    相关资源
    最近更新 更多