hellompm.mac

        ;; Tell the assembler that this is z80 code                                                                                                          

        .Z80


        ;; Define system calls                                                                                                                               

reset   EQU     0

bdos    EQU     5

cwrites EQU     9

attach  EQU     92h

detach  EQU     93h


        ;; Display msg1                                                                                                                                      

        LD      DE,msg1

        LD      C,cwrites

        CALL    bdos

        ;; Detach console                                                                                                                                    

        LD      C,detach

        CALL    bdos

        ;; Copy msg2 to msg3 while console is detached                                                                                                       

        LD      HL,msg2

        LD      DE,msg3

        LD      BC,28

        LDIR

        ;; Attach console                                                                                                                                    

        LD      C,attach

        CALL    bdos

        ;; Display msg3                                                                                                                                      

        LD      DE,msg3

        LD      C,cwrites

        CALL    bdos

        ;; Exit program                                                                                                                                      

        JP      reset


        ;; Define a memory address to store a string                                                                                                         

msg1:   DB      "Hello World! Detaching console...$"

msg2:   DB      "Attached console. Good bye!$" ;length is 28                                                                                                 

msg3:   DB      "                            " ;same length                                                                                                  


        ;; Tell the assembler that this is it                                                                                                                

        END


 © Andrew Brehm 2016