PDA

View Full Version : CPM 2.2 assembly language



Mike_Z
September 22nd, 2016, 02:26 PM
Now that the weather is starting to turn, so am I from old cars back to old computers. I was reading about library files and though that I'd try some. I use Word Star 3.0 to write my source file and have discovered how to use it with the library files. So I thought that I would make a library file with ASCII constants in it. And as usual I ran into trouble. Seems that none of the numbers work and only half of the letters work.


0 EQU 030H ;does not work
zero EQU 030H ;does work

So apparently there must be some rules about labels that I'm missing. Yet


A EQU 041H ;does not work
Z EQU 05AH ;does work

When I say it doesn't work, I mean that when it is assembled I get an 'S' error. What am I missing? Mike

commodorejohn
September 22nd, 2016, 02:29 PM
I have a sneaking suspicion that it's a namespace collision with the A register.

Randy McLaughlin
September 22nd, 2016, 02:33 PM
A label cant start with a digit or special character.

A register can't be a label in many assemblers, some it's fine.

I find short label names can be confusing so I try not to use single letter labels.


Randy

Chuck(G)
September 22nd, 2016, 02:35 PM
If I were a mean soul, I'd just say "RTFM", which is here (http://www.cpm.z80.de/randyfiles/DRI/ASM.pdf).

But basically, Section 2:


...The identifier is a sequence of alphanumeric characters (alphabetics and numbers), where the first character is alphabetic...

and Section 3.3, "Reserved Words", which are essentially the register set. So, A...E, H, L, M, SP, and PSW cannot be redefined.

Mike_Z
September 22nd, 2016, 02:44 PM
As you guys were responding I did come across the reserved words in section 3.3. I do read the manual, 'occasionally'. But after thinking about what I was doing, I do not think I need to EQU the ASCII letters and numbers at all. I probably only need the carriage return, line feed, question mark, etal. Thanks Mike.

Chuck(G)
September 22nd, 2016, 03:32 PM
That's why the FSM gave us quotation marks--for character literals. Don't confuse the name of something with its value. Symbols are a way to refer to a value. So A is not the same as 'A'.

Mike_Z
September 23rd, 2016, 05:45 AM
Yes, that's what I was thinking, if belated. So anyway, since my old assembler did not use library files, I was thinking what kind of stuff should be in the library files. Maybe some ASCII characters, some CPM stuff like BDOS functions and addresses, maybe some I/O routines. What other things would be appropriate? Mike

JonB
September 23rd, 2016, 07:11 AM
A general purpose reply to "What should be in a library file?" might be:


Any function that you intend to reuse (in other executables).
Utilities, usually grouped in separate libraries. Examples might include "string handling functions", "mathematical functions", "file operation functions" and (as you suggested) "I/O routines".
Commonly used constants - numeric or strings (although these may be defined in include files, too).



Ultimately, it depends on the design of your software. If it is modular, then you should find you have many candidate functions to put in a library. By convention, the functions in a particular library will share a common functionality or have some functional relationship. For example, a "string handling" library might include functions to concatenate strings, count the number of characters in a string, truncate a string, copy the content of one string into another, etc. Such a library needs to have a common representation of a "string"; again, for example, in C a string is represented as a contiguous buffer containing the ASCII representation of the string value, followed by a special character (a NULL, which has an ASCII code of 0) to indicate the end of the string. Bearing this in mind, you can imagine that one function that operates on a string will not alter the way the string is stored, so that any other string library function may still operate on it.

Oh dear, I think I am getting into ramble mode....

Chuck(G)
September 23rd, 2016, 08:54 AM
The basic CP/M 2.2 assembler, in my recollection, does not support library ("include") files.

JonB
September 23rd, 2016, 11:42 AM
Deleted post

Mike_Z
September 23rd, 2016, 01:40 PM
No I don't think that INCLUDE files work in CPM. I have been studing MASM 5.1 and they work there. But the included stuff can be read into the source file. Probably a precursor of Include. So, I'm attempting to build up some lib files. Thanks for the help. Mike

Chuck(G)
September 23rd, 2016, 02:59 PM
You may want to search out other assemblers. DRI MAC and RMAC (the relocatable version of MAC) have the MACLIB statement which allows for first-pass definitions to be placed in a separate file. M80 (the Microsoft relocating macro assembler) has a bonafide INCLUDE statement. I believe that both groups of assemblers do not allow nested inclusion of files.

inotarobot
September 23rd, 2016, 08:56 PM
Been a lot of years since I wrote assembler, but back then, as I recall one could NOT use text editors like Wordstar or like as they had a habit of embedding hidden characters, that the assemblers and/or linker's got tied up or crashed on.

Just my 2cents worth.

Chuck(G)
September 23rd, 2016, 09:02 PM
The trick is to use non-document mode in Wordstar. Normal document mode includes formatting information that will screw up most programs expecting normal ASCII.

commodorejohn
September 24th, 2016, 10:23 AM
Yep. Or you could use a Wordstar-a-like like ZDE (http://texteditors.org/cgi-bin/wiki.pl?ZDE) that saves in plain ASCII by default.

Chuck(G)
September 24th, 2016, 10:33 AM
Yep. Or you could use a Wordstar-a-like like ZDE (http://texteditors.org/cgi-bin/wiki.pl?ZDE) that saves in plain ASCII by default.

Maybe, but I believe that requires a Z80 CPU. There were other similar editors, however. VCF has been through the "CP/M Editor" discussion several times in the last decade. There's a bunch in retroarchive (http://www.retroarchive.org/cpm/text/text.htm)

inotarobot
September 24th, 2016, 03:27 PM
Maybe, but I believe that requires a Z80 CPU. There were other similar editors, however. VCF has been through the "CP/M Editor" discussion several times in the last decade. There's a bunch in retroarchive (http://www.retroarchive.org/cpm/text/text.htm)

Just had a look at the archive link. WOW.. like a walk down memory lane. !!!!! also in the yellow/amber dot type font (forgotten the correct name) on black screen, sure brings back some old thoughts.

Mike_Z
September 25th, 2016, 03:57 PM
Yup, you have to use the non document WS function. When I first tried Word Star, I was ignorant of that and was messed up for a while, but now, it works just fine. Today I wrote a couple of simple library files. One that just beeps, BDOS function 2 call and a time delay program, it just counts down from a preset number. I think I have the hang of the CP/M library idea. Thanks again for the help. Mike

geneb
September 26th, 2016, 09:14 AM
You might want to look at VDE as well, I don't think it's Z-80 specific.

g.

Chuck(G)
September 26th, 2016, 09:25 AM
You might want to look at VDE as well, I don't think it's Z-80 specific.

The manual (https://sites.google.com/site/vdeeditor/Home/vde-files/vde-cpm-manual) appears to say otherwise.

BrianS
September 26th, 2016, 04:31 PM
My old CP/m environment- WS3.3, FORTRAN-80, Microsoft M-80, Librarian, and Linker. Re-wrote the multiply and divide routines in FORLIB to use Z80 code, ran 2x faster than the originals. M80 was nice, allowed sharing of common blocks between assembly and FORTRAN. I probably have them on my Pentium Pro running under a CP/m emulator. The Xerox 820-II is still in the basement.

"I seem to recall" that "Winstall for WS3.3" allowed you to customize settings based on file extension. ".MAC" and ".FOR" came up in non-document mode automatically.

Mike_Z
September 27th, 2016, 06:20 AM
Brian, my 8080 cpm machine is a home brew machine, but works just fine. I have WS 3.0 and Fortran 80 for it. Fortran IV was the first language I learned and used in the early 1960's. Currently I'm using the cpm assembly language program. Figure I will learn that the best I can prior to advancing to something else. I enjoy controls. I have a couple of old furnace stepper motors that I want to be able to control with the 8080. I've seen M80 but have not looked closely at it. What is the Librarian you mention? Mike

Chuck(G)
September 27th, 2016, 06:36 AM
M80 is actually several programs: the assembler, the linker and the librarian. (M80, L80 and LIB80). But here we need to differentiate between source and object libraries. LIB80 is an object librarian--that is, it allows one to satisfy external references with a library of precompiled files. For example, if you reference the SIN() function in FORTRAN, an object library containing the compiled object code for the sine routine is referenced and the appropriate routine is added during linkage editing time to form a completed program.

Again, note that M80 is a relocating assembler--that is, it doesn't automatically assign addresses to symbolic locations until the compiled code is linkage-edited into an absolute memory image.

DRI offered a similar program set with RMAC, LINK and LIB. You'll always see these programs offered as a set of three, because that's what's needed to do the job.

BrianS
September 27th, 2016, 08:20 AM
The Microsoft Assembler (M80), Librarian LIB80, and Linker (L80) as mentioned are the best for use with Microsoft FORTRAN-80. They work together "seemlessly" with the later release of F80. I have V3.44 Microsoft Fortran-80 still in my bookcase: it fixed an incompatibility between M80 and F80 common blocks. V3.42 and earlier set a high-order bit in the common block name, M80 did not: meant they were loaded into separate memory, not "common". I wrote a lot of code 35 years ago for CP/m, including processing Landsat-4 Data. I've used Fortran for 40 years now. Pays the bills!

Mike_Z
September 27th, 2016, 09:05 AM
Although I built my home brew 8080 machine around 1977, I did not have CP/M until about 2 years ago. At first my 8080 ran from a cassette interface I made and I also wrote a crude assembler that served me until around 1983, when I changed jobs and the computer stuff was put away, so I could work to feed the family etal. I retired a while back and came across all my old computer stuff and decided to see if I could make CPM run. I had to build a FDC card (I use an old IMSAI motherboard so it's s-100), had to add interrupts and DMA. With the help of Chuck(G) I'm up and running. Chuck, it is interesting what you say about source and object library files. I think the PDP8E I have that uses OS8 and F8 does what you are talking about. Not that smart yet and the old noodle can only take in so much at a time. Thanks Mike

BrianS
September 27th, 2016, 10:18 AM
I'd like to see some pictures of your machine posted here! Sounds cool. "Way back when" I had a friend that made an 8086 machine with a z80 pre-processor: the Z80 ran a program looking for illegal opcodes in the 8086 code!

I found a site with CP/m tools, most of which I had when running the CP/m machine:

http://www.retroarchive.org/cpm/lang/lang.htm

The Fortran-80 ZIP file has M80, Link-80, and librarian in it. Just like on my 8" Floppy in my bookshelf...

I also found an on-line PDF of the manual-

https://archive.org/details/bitsavers_microsoftc0Ver3.4UsersManualNov80_126306 29

My original has the Green 3-ring binder.

Hope you do not mind the links. I got a lot of use from these tools, wrote Fortran callable assembly code to call all the BDOS functions and do fast floppy access on the Xerox 820-II. I did more Z80 code, especially with the mode-2 interrupts. Did a lot with the Ampro Littleboard computers talking with Navigational computers of the P3 Orion. Fun days.

Chuck(G)
September 27th, 2016, 11:45 AM
FORTRAN can take many forms, but always comes with an object library of sorts--even when, back in the dark ages, I ran programs using a punched-card only system, there was a library deck of routines that was read in after the second pass before the object deck was punched.

It's actually pretty surprising what can be squeezed out of a CP/M-80 system. PLI/I and COBOL, for example, exist for the platform, which is a pretty ambitious.

Mike_Z
September 27th, 2016, 12:41 PM
Here is my little corner in the basement.
33450
From left to right, I have an IBM XT, that I use as a terminal and storage device. A Televideo 920C terminal which is primarily used as the console for the 8080. On the top of the rack is a screen for my raspberry PI. The raspberry PI is used as 4 RK05 drives for the PDP8E. There are two 8 inch drives used with the 8080 machine. The black machine is the 8080. The PDP8E is just below the 8080. Next to the rack is a ASR33 used with the PDP8E and a Epson FX86E for the 8080 and a Teletype Model 43 which can be used with the PDP8 or the 8080. So this assorted old junk keeps me busy during the winter months, when it's too cold to run the Model T. Mike.

BrianS
September 27th, 2016, 05:07 PM
Thankyou! Too cool!

The Microsoft FORTRAN-80 suite came on an 8" floppy, still have it. I get 30+ years out of IBM floppies. I need to power-up the Xerox 820-II, see what happens... I still do a lot of assembly language programming for Microchip PICs, 8-bit microcontrollers. A lot of fun, I should buy some of the Zilog chips.

Mike_Z
September 28th, 2016, 08:31 AM
I have a minor question, that I have not been able to figure out. I keep Word Star on the A: drive and there is little room of anything else. I keep my programs on B: along with ASM and LOAD. I run these on the B: drive. Seems that when I assemble a program, when ASM is complete, it does a warm boot and ends up on A:, yet when I use LOAD it will stay on B:. Does the ASM program overwrite CCP and needs to do a warm boot. or......? Thanks Mike

Mike_Z
October 4th, 2016, 10:30 AM
Today, while writing some test programs for some hardware I have, a bug popped up that is a little perplexing. I made a spelling error on two mnemonics and ASM did not flag them. I noticed that in the .PRN file there was no machine code for these misspellings and no errors.
I had


XRAA
INCA ;C instead of R

instead of


XRA A
INR A


What is happening here? Thanks Mike

BrianS
October 4th, 2016, 10:37 AM
Is it making them into Labels? That would occur for some assemblers that I've used much more recently.

Mike_Z
October 4th, 2016, 10:42 AM
That could be. But I don't have a colon after them such as XRAA:. How would I tell if ASM considered them a label? Mike

Chuck(G)
October 4th, 2016, 12:35 PM
The colon is optional in ASM. Leading spaces are ignored. E.g.:



0100 ORG 100H

HERE
0100 DS 64
STK

0140 0001 DW HERE
0142 4001 DW STK

0040 = STKLEN EQU STK-HERE

0144 END

BrianS
October 4th, 2016, 02:28 PM
Microchip ASM- colons are optional, you can use them declaring a label, or not use them. When referring to a label, you don't need it.
; PIC16 code

counter equ 0x20
movlw 0xff
movwf counter
delay:
decfsz counter,F
goto delay

same as

counter equ 0x20
movlw 0xff
movwf counter
delay
decfsz counter,F
goto delay

; 8-bit microcontrollers mean old Assembly language programmers have a bright future...

Chuck(G)
October 4th, 2016, 03:49 PM
On the other hand, the Atmel AVR assembler requires them and even features a weird EQU:

.EQU MYSYM = 4

In general, I find most 8-bit MCU assemblers to be brain-dead. Few even feature macros, much less relocatable binary output.

I'm not even certain when the colon managed to creep into assembly syntax. S/360 and before didn't use it. CDC never used it. I'm not ever certain about Intel ASM80 (on ISIS).

Anyone have a solid date and version of an assembler that demanded it?

BrianS
October 5th, 2016, 01:19 AM
Lack of relocatable executable code has more do do with specifics of the instructions themselves. You would not be able to relocate Jump Tables using Add instructions in several of the instruction sets where the add instruction is not wide enough to cover the entire address range. Jump tables are limited to the lower portion of the page. Use of relocatable output often relied on Jump Relative instructions being available. The mid/high end microcontrollers added it. AVR is big on relative addressing; PIC12 and PIC14 more on absolute addressing. I've seen other assemblers use the .equ for of the statement. The PIC12 uses code-page bits in the STATUS register, and PIC14 architecture uses a shadow register for PC-HIGH. Both allow arithmetic and logical operations on these "hidden bits" in the program counter. (Turns out MPLAB V8 and later allow relocatable code to be generated if you confine yourself to a tight coding style.)

I use colons more as a matter of style, to differentiate statement labels from variable names.

I'll have to dig out some old manuals.

With the CP/M assembler- I need to dig out the code.

Edit- I dug out some old code... Picked up using colons for labels under RT-11 for the PDP and CP/m Microsoft M80 with the 8080 and Z80. I still have my 1977 Intel 8080 manual and Zilog Z80 manual on the bookshelf...

Chuck(G)
October 5th, 2016, 08:47 AM
You don't get it. Anywhere an address is specified as a constant is a candidate for a relocatable assembler. We're not talking about PC-relative addressing as that's self-relocating by default. 8080 CP/M PRL files are relocatable, for example, on a page basis. 8-bit PIC is a weird case owing to its very limited addressing scheme and inability of the ISA to accommodate literal data in the code space. (e.g. using RETLW to create a simple lookup table).

Relocatable assembly usually implies linking of object modules and libraries, since resolution of external addresses usually implies relocation. Very few 8-bit MCU assemblers are that sophisticated--but almost all 32-bit MCU assemblers are.

PDP-11 is too late for comparison, as is any microprocessor assembler. Where does colon appear in any 1950s or 60s assembler syntax? I tend to associate colon-type tags with HLLs, such as PL/I and ALGOL-60. Was the colon directly punchable on the 026 keypunch? It was a "rogue" character on the CDC 6000/CYBER 70 machines as it coded to 00 octal, which was also part of the code for end of line (punching two colons in a row was a craps shoot). CDC ALGOL used two periods (..) as a colon equivalent digraph.

BrianS
October 5th, 2016, 11:21 AM
You don't get it. Anywhere an address is specified as a constant is a candidate for a relocatable assembler. We're not talking about PC-relative addressing as that's self-relocating by default. 8080 CP/M PRL files are relocatable, for example, on a page basis. 8-bit PIC is a weird case owing to its very limited addressing scheme and inability of the ISA to accommodate literal data in the code space. (e.g. using RETLW to create a simple lookup table).

Relocatable assembly usually implies linking of object modules and libraries, since resolution of external addresses usually implies relocation. Very few 8-bit MCU assemblers are that sophisticated--but almost all 32-bit MCU assemblers are.

PDP-11 is too late for comparison, as is any microprocessor assembler. Where does colon appear in any 1950s or 60s assembler syntax? I tend to associate colon-type tags with HLLs, such as PL/I and ALGOL-60. Was the colon directly punchable on the 026 keypunch? It was a "rogue" character on the CDC 6000/CYBER 70 machines as it coded to 00 octal, which was also part of the code for end of line (punching two colons in a row was a craps shoot). CDC ALGOL used two periods (..) as a colon equivalent digraph.

I get it. i understand the machine code. The full use of PIC12s and PIC16s (edit- 12-bit and 14-bit) instruction set do not lend themselves to generating relocatable code.

You are just flat-out wrong. Get over it.

Chuck(G)
October 5th, 2016, 11:32 AM
I get it. i understand the machine code. The PIC12 and PIC16 instruction set do not lend themselves to generating relocatable code.

You are just flat-out wrong. Get over it.

About what, pray tell? Be specific. There is more than one 8-bit MCU family. How about linkage editing? Don't see that either.

BrianS
October 5th, 2016, 11:36 AM
i specified PIC12s and PIC16s, more specifically referring to 12-bit and 14-bit ("classic") architecture. They do not lend themselves to producing relocatable code. (Turns out that MPASM can be used to generate relocatable code for these if you confine yourself to a tight coding style.) You stated that's because the assembler is brain-dead. You are wrong.

Now I remember why I dropped this forum a few years ago.

Chuck(G)
October 5th, 2016, 11:38 AM
And their assemblers are brain-dead. What about external linkage editing? How about extensive macro support? I'm not aware that the PIC assemblers implement either of either of those facilities that have been part of real assemblers since at least the 1960s.

And if you're going to implement that, at least the displacement fields need to be adjusted if a reference to an external symbol is made. Any largish code I've had to produce for an 8-bit PIC has had to be assembled in one fell swoop--no incremental assemblies, linkage editing, etc.

Or perhaps I missed something and someone actually came out with a decent toolset. If so, please enlighten me.

BrianS
October 5th, 2016, 11:42 AM
Whatever, dude.

I'd hate to have my jump table built off an addwf pcl,f instruction relocated. The instruction set is the limit. MPASM produces relocatable code for processor architectures (such as the Pic14 extended instruction set) that actually support it. It's not a problem with the assembler.
(Added: MPASM allows generation of relocatable code for the PIC12 and PIC14 architecture IF you use a tight coding style. The problem is that only parts of the program counter are stored in program memory, code page bits can be in the STATUS register and accessible only shadow registers. Hard to do an address fixup for values generated at runtime and depend on the order of instruction execution. Avoid that- tighten the style, and MPLAB will generate relocatable code as an option at build time. The first time that you do a build with a project, you need to specify "absolute" or "relocatable" code.)

But I do see the problem with this forum.

Chuck(G)
October 5th, 2016, 12:17 PM
Don't blow the topic off, please! Let's think this through.

If we had a full-fledged assembler that could handle generation of relocation information, consider the following:

In program module 1:



EXTERN DOTHIS
CALL DOTHIS

In program module 2:



PUBLIC DOTHIS
DOTHIS:
ADDWF PCL,F
RETLW value_1
RETLW value_2
...


I've invented some pseudo-ops for our hypothetical relocating assembler. PUBLIC and EXTERN should be obvious. For a truly general routine, you may need to update PCLATH in the case of a 256 byte boundary crossing, but that's just more code.

Note that we're only relocating external references and explicit references to the location counter.

This allows me to accumulate a collection of modules and simply link them together, instead of INCLUDE-ing all of the code every time I make a small change.

BrianS
October 5th, 2016, 02:21 PM
The use of the colon for labels is optional in CP/m ASM, but required in Microsoft M80 (unless the label is used with an EQU statement). I always used the latter, but have original manuals for both.

With Microsoft, use of a double-colon makes the Label Public. This carried over to the Microsoft assemblers for the PC. I've been programming Intel assembly since 1981, have always used the colon for statement labels. I've had the CP/m assembler that came with the Xerox 820, still have it- but never used it. I usually did a combination of Microsoft Fortran-80 and Macro-80. Found all the original 5.25 disks for it, and Worstar going back to 2-point-something and 3.0. I disassembled Wordstar 3.0 using ZSID and hex patched it for the newer Xerox keyboard. The tedious part: Patching all the on-screen menus and help files to reflect the changes made in the keystrokes... I've been using Wordstar to write code ever since, 35 years now. Even with MPLAB.

BrianS
October 7th, 2016, 05:23 AM
The point of a discussion forum is to Discuss and Learn.

I cited the PIC programming as examples of 8-bit assembly language relevant in the 21st century. Skills learned on the 8080 and Z80 apply to embedded microcontrollers.

So I learned something,

http://www.amqrp.org/elmer160/lessons/E160L16.pdf

Not sure if I'll use it- but nice to know how. I always used relocatable code with FORTRAN-80 and Macro-80, always used absolute with the PIC12 and PIC14 architectures. As per the link, MPLAB v6 scanned your code before asking if you wanted it relocatable or absolute. It never asked, my code was always self-contained. With F80 and M80 there are special rules covered in the manual about making ROMable code. So Microchip has special rules for making relocatable code. I'll add one- don't implement a loop by using a "BCF PCL,0x0"- it would only work if the instruction itself falls on an odd address. The Xerox 820-II used a Ferguson Bigboard-II; well documented.

For the OP- the Microsoft tools are quite nice for CP/m and available for download. You will not run into the problem encountered. Ran them today under Nice22 CP/M emulator pn my Pentium Pro. The old Xerox 820-II booted up once for me one last time, power-supply blew out. Put it back in the box, when I retire will have some time for it.