Skip to first unread message

Richard Deane

unread,
Jul 12, 2019, 4:53:53 PM7/12/19
to retro-comp
I have what I expect is actually a simple problem, but it is defeating me.

I have a simple assembler program (hellow.asm)
; Hello world in Z80 Assembly for CP/M
BDOS    equ     05h
WRTLINE equ     09h
;
        org     0100h
start:  lxi     d,sHello
        mvi     c,WRTLINE
print:  call    BDOS
finish: ret;
sHello  db      'Hello, World!$'

The program, quite obviously, writes "Hello, World!" to the console.

My problem is that debuggers are documented as loading a program in at 100h, but mostly this loads in at 200h, but the symbols are based at 100h. I usually do RMAC Hellow, followed by LINK Hellow. 

I have  tried SID,ZSID, DDT, Z8E and DEBUGZ  and usually same problem, loading at 200h; however I did somehow on several occasions without realising how manage build and correctly load at 100h.

If I use ASM to create a hex file and then ddt hellow.hex then it does correctly load in at 100h.

What is the secret of getting a linked com file to load in at 100h?

And I thought CP/M was supposed to be simple :)

Richard
(p.s. you can tell I am addicted to computers because I put 512g flour in the bread machine :) )


John Kennedy

unread,
Jul 12, 2019, 9:44:20 PM7/12/19
to retro-comp
Can’t you use LOAD hellow to make a COM that will load into 0100h?

Richard Deane

unread,
Jul 13, 2019, 2:48:12 AM7/13/19
to retro-comp
I will try load, but that doesn't really solve the problem, as I don't think it will be generating a symbol table. I need to understand where my error is with assembler and link so that I conquer that build process.

Bill Shen

unread,
Jul 13, 2019, 7:36:54 AM7/13/19
to retro-comp
Richard,
Instead of writing in 8080 assembly, you may be interested in zsm4 extensively rewritten by Hector Pereza.  It is a native Z80 assembler for CP/M.  It also assemble Z180, Z280 codes.  The sources are in his GitHub here: https://github.com/hperaza/ZSM4  There is also a ready-to-run version here: https://www.retrobrewcomputers.org/forum/index.php?t=msg&th=93&goto=3700&#msg_3700

Below is a session of your program running on my Z80MB64:
--------------------------------------------------------
b>ed helloz.asm

NEW FILE
     
: *i
   
1:  bdos equ 5
   
2:  wrtline equ 9
   
3:    org 100h
   
4:    ld de,sHello
   
5:    ld c,wrtline
   
6:    call bdos
   
7:    ret
   
8:  sHello db 'Hello World!$'
   
9:
     
: *e

b
>zsm4 helloz=helloz.asm
Z80
/Z180/Z280 Macro-Assembler V4.1

Errors: 0
Finished.

b
>dir helloz.*
B
: HELLOZ   BAK : HELLOZ   ASM : HELLOZ   REL
b
>a:link helloz=helloz
LINK
1.31

ABSOLUTE    
0000
CODE SIZE    
0116 (0100-0215)
DATA SIZE    
0000
COMMON SIZE  
0000
USE FACTOR    
00

b
>dir helloz.*
B
: HELLOZ   BAK : HELLOZ   ASM : HELLOZ   REL : HELLOZ   COM
B
: HELLOZ   SYM
b
>helloz
Hello World!
b
>

Phillip Stevens

unread,
Jul 13, 2019, 9:20:57 AM7/13/19
to retro-comp
Richard Deane wrote:
I have what I expect is actually a simple problem, but it is defeating me.

I have a simple assembler program (hellow.asm)
Hello world in Z80 Assembly for CP/M

Hi Richard,

I often use the z80asm assembler in the z88dk, and the good thing about it is that you can move between assembly and C seamlessly, and link the two together very simply. That means time critical stuff (libraries and so forth) can be written in assembly, and the boring stuff can be done in C.

Names are mangled between the two worlds simply by prepending an underscore in assembly.
The linker uses the ALIGN word is used to put the code at a certain location, or to skip to a start of page or similar.

If you have z88dk installed on any of linux, mac, or windows, then the following will get you some interesting assembly to look at if you choose the verbose option. Noting there are two C compilers and two libraries in use below, but thankfully only one assembler. Usually everything is called by using the common front end tool, zcc, to keep thing simple.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>


// for cpm target using sccz80 C compiler and "classic" library, run test.com
// zcc +cpm test.c -o test.com


// or again more verbosely
// zcc +cpm -v -m --list test.c -o test.com


// for rc2014 target using sdcc C compiler and "new" library, rename test_CODE.bin and run as test.com
// zcc +rc2014 -subtype=cpm test.c -o test


// or again more verbosely
// zcc +rc2014 -subtype=cpm -SO3 -clib=sdcc_iy -v -m --list --c-code-in-asm --max-allocs-per-node40000 test.c -o test


void main(void)
{
    fprintf
(stdout,"Hello World R\nHello World C\nHello World 2\nHello World 0\nHello World 1\nHello World 4\n");
}

It is probably more detailed than you're looking for right now. But I find it really valuable to read the preamble and epilogue generated to see what is really going on with my programs. Perhaps you might too?



Cheers, Phillip

John Kennedy

unread,
Jul 13, 2019, 11:02:34 AM7/13/19
to retro-comp
Oh sorry - I guess I don’t understand the question. :)
Is your code not working? Doesn’t it generate a .com that loads and runs?

Richard Deane

unread,
Jul 13, 2019, 11:31:07 AM7/13/19
to retro-comp
Thanks Alan, removing ORG 100h now allows the program to load correctly at 100h in the debuggers so the major part of the problem is solved.
The remaining problem relates to the symbol table - it seems that RMAC creates a correct symbol table, and DRI's LINK is supposed to by default but LINK (v1.31)  creates an empty symbol table overwriting that from RMAC. I shall experiment.

For anyone wondering, I use RMAC and LINK as they are used for PL/I-80, my favourite CP/M language.

Bill & Phillip -  thanks for the info about the other tools, I shall investigate those as well, I need a good tool chain and was put off by the awkwardness of MS M-80 and L-80. I have no prejudice with respect to Intel or Zilog assembler mnemonics and am likely to be only working on Z80.

Back in the original days I did my development mostly in Pascal (TCL Pascal was the best) with a little PL/I-80 or assembler (I came from a mainframe IBM PLI environment into CP/M in 1980 - using Ithaca Intersystems S100 with Z80 and CP/M 2.2). Magicwand was my preferred editor for programming and word processing docs, though I did later have to use Wordstar (and QuickStar a private staff-written DR clone of Wordstar for CP/M and Concurrent CP/M). I used Micro-Integration comms products to talk to IBM mainframes. Anderson-Jacobsen acoustic couplers at 300 Baud - wow that was slow.

Thanks John for responding - the main problem , resolved by Alan, was that the program  built with rmac and link did not load in the debugger at the expected address.

Playtime here we come ...

John Kennedy

unread,
Jul 13, 2019, 11:42:26 AM7/13/19
to retro-comp
Glad it's resolved. I find my major contribution in this kind of situation is to post something so amazingly wrong that it infuriates and encourages others to post the correct solution. 
In other words, you're welcome ;-)

Richard Deane

unread,
Jul 13, 2019, 12:33:51 PM7/13/19
to retro-comp
The important thing is that you were motivated to help, that's why I like some of these groups.

Karl Albert Brokstad

unread,
Jul 14, 2019, 3:49:36 AM7/14/19
to Bill Shen, retro-comp
Hi
May i also point to Marco Maccaferri’s integrated developer platform. Including Editor, z80 assembler, direct download to rc2014 and more. 
- One Package
- No terminal commands
- one Click download and testing
Karl


Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "retro-comp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to retro-comp+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/retro-comp/4aa39986-232d-412a-a742-86db8b8828cf%40googlegroups.com.

Alan Cox

unread,
Jul 14, 2019, 9:03:00 AM7/14/19
to retro-comp
Realized I posted the explanation directly not to the group

LINK when it sees absolute references creates a binary image. If you remove the "org" it will link as expected and by default put the code at 0x100 and the data following. With the org you get 100h of nops in front of the code so it looks like the symbols/code are confused as it loaded the image at 0x100 even though it was an absolute image so began at 0.

Alan

Richard Deane

unread,
Jul 14, 2019, 2:09:08 PM7/14/19
to retro-comp
My observation is that rmac creates a valid symbol table useable in debuggers but link overwrites it with one containing just cr lf .

Alan Cox

unread,
Jul 14, 2019, 4:36:21 PM7/14/19
to retro-comp


On Sunday, 14 July 2019 19:09:08 UTC+1, Richard Deane wrote:
My observation is that rmac creates a valid symbol table useable in debuggers but link overwrites it with one containing just cr lf .

LINK only outputs global symbols I think. Try declaring the symbols you want global ?

Douglas Miller

unread,
Oct 25, 2019, 5:46:26 PM10/25/19
to retro-comp
To answer your original question, the reason your program was getting placed at 0200h while being "relocated" for 0100h is the "org 0100h" line. That is needed for MAC, but does the wrong think for RMAC/LINK. As strange as it sounds, you want to remove the "org 0100h" line, and let LINK properly relocate and position the code.
Reply all
Reply to author
Forward
0 new messages