Z80组装程序失控

Tom*_*rvo 0 assembly z80

我正在研究一个小的Z80汇编程序,这是我的第一个程序。这是我的Z-80汇编代码:

main:
        LD      SP, $FFFF            ; start by setting stack to top of RAM

printChar1:
        LD  A, 'X'                   ; this works
        CALL    transmitCharFromA    ; this works

        LD      HL, (generationMsg)  ; this does not work
        CALL    txAsciiZMsg          ; this does not work

endInNopLoop:
        NOP
        JR  endInNopLoop


generationMsg:  DEFB    "Generation: ", CR, LF, 0 ; null-terminated string
Run Code Online (Sandbox Code Playgroud)

预期的结果是,它将随后输出带有CRLF组合的“ XGeneration:”。

该例程transmitCharFromA效果很好,输出的第一个字符确实是“ X”。这是例程:

transmitCharFromA:
        PUSH    AF              ; store char in A for later
consoleOutput:
        IN  A,($80)             ; read ACIA status byte       
        BIT 1,A                 ; set Z flag if still transmitting character       
        JR  Z,consoleOutput     ; and loop until flag signals ready
        POP AF                  ; get the character back from the stack
        OUT ($81),A             ; send it over RS232 to ACIA outpout address
        RET
Run Code Online (Sandbox Code Playgroud)

正如我提到的,这很好用。因此,我想通过启用以null结尾的字符串的输出为基础:

txAsciiZMsg:
        LD  A, (HL)             ; A holds pointer to start of null-term string
        OR  A                   ; OR A with A to set Z flag if A holds null terminator
        RET Z                   ; return if done
        CALL transmitCharFromA  ; otherwise transmit it using working routine
        INC HL                  ; move pointer to next character
        JR  txAsciiZMsg         ; and keep going
Run Code Online (Sandbox Code Playgroud)

这是行不通的,在停止并(显然)进入循环之前输出一堆垃圾字符endInNopLoop

任何人都可以在txAsciiZMsg例行中建议我做错了什么:

  1. 打印垃圾
  2. 不打印“ Generation:”消息
  3. 显然找不到终止为零的0x00字符

我正在使用z88dk汇编和构建程序。

我可以在程序集清单中看到该LD A, (HL)语句已正确汇编,将消息地址第一个字节显示为LD指令的操作数。因此,我对可能出问题的地方感到困惑。

谁能指出我的错误?

Geo*_*ips 5

You must use:

LD   HL,generationMsg
Run Code Online (Sandbox Code Playgroud)

地址generationMsg入HL,而不是实际使用加载的内容(generationMsg),如汉斯评论。

正确的程序集将显示操作码,$21而不是$2A您现在得到的操作码。但是无论哪种情况,generationMsg都会出现的地址,因此不会用作区分正确性的方法。


LD HL,(generationMsg)是具有绝对直接寻址模式的负载。您想要的指令“装入”立即数操作数,并且即使共享相同的助记符,也完全不同。