Apple Assembly Line
Volume 5 -- Issue 1October 1984

In This Issue...

Index to Volume 4

This time last year we published a cumulative index to the first three years of Apple Assembly Line. In this issue we add a separate index to Volume 4, covering October 83 through September 84. Perhaps in another year or two we can do another complete index.

65802 is Here!

After nearly a year of more or less patient waiting, we finally have a sample 65802 microprocessor. It does indeed plug right into an Apple //e, and works just fine. See Bob's story inside for all the details.

Blind Word Processor

Subscriber Larry Skutchan, of Little Rock, Arkansas, has adapted the S-C Word Processor to work with the Echo Two Speech Synthesizer. He now has a special word processor for the blind, which he says is the best available. The price will be $95.50. Larry is a blind university student, majoring in Computer Science. You can reach him at (501) 568-2172.


18-Digit Arithmetic, Part 6Bob Sander-Cederlof

This month's installment will cover some of the elementary functions: VAL, INT, ABS, SGN, and SQR. I will also introduce a general polynomial evaluator, which will be used by most of the other math functions.

Most of the functions expect a single argument, which will be loaded into DAC by the expression evaluator just before calling the function code. The function code will compute a value based on the argument, and leave the result in DAC. As the expression evaluator calls with JSR, the function code returns with RTS.

One exception to the above paragraph is the VAL function. VAL processes a string expression, and converts it into a value in DAC. The code in lines 1350-1610 of the listing closely parallels the VAL code in the Applesoft ROMs. Lines 1350-1370 evaluate the string expression. Lines 1380-1460 save the current TXTPTR value (which points into your Applesoft program), and makes TXTPTR point instead at the resulting string. Lines 1470-1520 save the byte just past the end of the string and store a 00 terminator byte in its place. FIN will evaluate the string, placing the numeric value into DAC. Then lines 1540-1600 restore the byte after the string and TXTPTR.

The INT function zeroes any digits after the decimal point in a number. A number in DAC has 20 digits. The exponent will be $00 if the value is zero, $01-40 if the value is all fractional, $41-53 if the value has from 1 to 19 digits before the decimal point, or $54-7F if the value has no fractional digits.

Lines 1650-1700 remove the $40 bias from the exponent. If the exponent was $00-40, DP.ZERO will force DAC to zero. Lines 1730-1740 check for the case of no fractional digits, and exit immediately. Lines 1750-1860 zero the digits after the decimal point. If the exponent was odd, there is one digit to be removed in the first byte to be cleared; the rest get both digits zeroed.

The simplest function is ABS, or absolute value. All it requires is forcing the sign positive, handled at lines 1910-1930.

Almost as simple is SGN, or sign function. SGN returns -1, 0, or +1, according as DAC was negative, zero, or greater-than- zero. Lines 1970-1980 check DAC.EXPONENT, which will be zero if-and-only-if DAC is zero. If the value is not zero, lines 1990-2030 force the value to be 1.0, while retaining the original sign.

SQR, the square root function, is more interesting. Do you remember the way you learned to take square roots in high school? Neither do I, but there is a handier way in computers anyway.

Suppose I want to find square root of 25. I could start with a wild guess, check it to see if I am close by squaring and comparing with 25, and then refining my guess until it is as accurate as I need. Suppose my wild guess is 7 (pretty wild!).

7*7 is 49, which is bigger than 25, so my next guess should be less than 7. Instead of just guessing wildly for the next one, why not take the average between 7 and 25/7? That average is 5.286. The average of 5.286 and 25/5.286 is 5.0076. The next one is 5.0000079. You can see that I am rapidly approaching the answer of 5.0.

The method of refining an approximation as exemplified above was derived originally be Sir Isaac Newton. His method involves calculus, can get quite complex, and applies to all sorts of problems. But in the case of the square root, it is as simple as averaging an approximation with the argument divided by the approximation.

It turns out that it is a very good method, because if you can get an initial approximation that has the first few digits right, the number of digits that are correct will slightly more than double each time you run through Newton's improver.

The next trick is to reduce the range of possible arguments from the full range of zero to 10^63 down to the range from .1 to 1.0. The zero case is easy, because SQR(0) = 0, and is handled at lines 2100-2110. Notice that lines 2120-2130 weed out negative arguments, which are not allowed.

Remember that the square root of X*10^n is equal to SQR(X)*10^(n/2). Lines 2150-2190 save the exponent, and change it to $40. This changes the value in DAC to the range .1 to 1.0. I have a book which gives polynomial approximations to the square root in that range. One with the form aX^4+bX^3+...+e gives an approximation with is accurate in the first 2.56 digits. Three iterations by Newton yield more than 22 accurate digits. The same book shows a cubic polynomial which gives 2.98 accurate digits if we can get the value into the range between .25 and 1.0.

Lines 2200-2280 fold the values between .1 and .25 up to the range .4 through 1.0 by multiplying the value by 4. (This multiplication goes pretty fast, since most of the bytes are zero.) The fact that we quadrupled the value is remembered, so that we can later halve the approximate root at lines 2350-2410. The cubic polynomial is evaluated in lines 2290-2340, by calling POLY.N. The result, by the time we reach line 2420, is an approximate square root of the number between .1 and 1; now we need to make it an approximate root of the original argument.

Lines 2420-2480 compute the exponent of the square root, by simply dividing the original exponent by two. If there is a remainder, meaning the original exponent was odd, then we also need to multply the trial root by SQR(10). This is handled in lines 2490-2550. The halved original exponent next is added to the trial exponent, giving a good first approximation to the square root of the original argument. Lines 2600-2740 run through three cycles of the Newton iteration, giving plenty of precision. If we were carrying enough digits along, the 2.98 digits of precision our polynomial produced would be refined to a full 26 digits, according to my book.

Speaking of the book, it is one I bought a number of years ago when working on double precision math for a Control Data 3300 time sharing system. As far as I know, it is still the best book in its field. Computer Approximations, by J. F. Hart and about seven other authors, was published in 1968 by John Wiley & Sons. I don't know if it is still in print or not, but if you ever need to create some high precision math routines, you ought to try to find a copy.

A very common element in the evaluation of many math functions is an approximation to the function over a limited range by a polynomial, or by the quotient of two polynomials. Therefore it is handy to have an efficient subroutine to evaluate a polynomial. Two different entry points allow efficient evaluation of two kinds: those whose first coefficient is 1, and the rest. POLY.N evaluates those whose first coefficient is not one, and POLY.1 does those whose first is 1.

       POLY.N --  a*x^n + b*x^n-1 + ...
       POLY.1 --    x^n + a*x^n-1 + ...

In both cases, you enter with the address of a table of coefficients in the Y- and A-registers (hi-byte in Y, lo-byte in A), and the degree of the polynomial in the X-register. Thus you see that in lines 2290-2340 the table P.SQR is addressed, and the degree of polynomial is 3 (cubic). Both POLY.N and POLY.1 assume that the value of x is in TEMP2. Where all terms have been computed and added, the result will be in DAC.

Actually, I may have misled you a little in the last sentence. The terms of the polynomial are not separately computed and added, but rather they are accumulated in a simple serial fashion:

       poly = ((( a * x + b) * x + c) * x + d) * x + e

The coefficients and other constants shown in lines 2770-2830 are in a special format which includes an extra two digits. You will remember that the basic operations (+-*/) are carried out to 20 digits. Therefore these constants are carried out to 20 digits. They are not critical in the square root computation, thanks to Sir Isaac, but the log and trig functions will need them.

  1000 *SAVE S.DP18 FUNC 1
  1010 *--------------------------------
  1020 AS.CHRGOT  .EQ $00B7
  1030 AS.FRMEVL  .EQ $DD7B
  1040 AS.CHKSTR  .EQ $DD7B
  1050 AS.FRESTR  .EQ $E600
  1060 AS.ILLERR  .EQ $E199
  1070 *--------------------------------
  1080 DMULT      .EQ $FFFF
  1090 DDIV       .EQ $FFFF
  1100 DADD       .EQ $FFFF
  1110 FIN        .EQ $FFFF
  1120 DP.TRUE    .EQ $FFFF
  1130 DP.ZERO    .EQ $FFFF
  1140 MOVE.DAC.TEMP3 .EQ $FFFF
  1150 MOVE.DAC.TEMP2 .EQ $FFFF
  1160 MOVE.TEMP2.DAC .EQ $FFFF
  1170 MOVE.YA.DAC.1  .EQ $FFFF
  1180 MOVE.YA.ARG.1  .EQ $FFFF
  1190 MOVE.TEMP3.ARG .EQ $FFFF
  1200 MOVE.TEMP2.ARG .EQ $FFFF
  1210 *--------------------------------
  1220 TXTPTR     .EQ $B8,B9
  1230 DEST       .EQ $60,61
  1240 *--------------------------------
  1250 TEMP2      .BS 1
  1260 TEMP3      .BS 1
  1270 P1         .BS 2
  1280 DAC.EXPONENT .BS 1
  1290 DAC.HI       .BS 10
  1300 DAC.SIGN     .BS 1
  1310 *--------------------------------
  1320 *      VAL (X$) FUNCTION
  1330 *--------------------------------
  1340 DP.VAL JSR AS.CHRGOT
  1350        JSR AS.FRMEVL     GET STRING
  1360        JSR AS.CHKSTR MAKE SURE IT IS A STRING
  1370        LDA TXTPTR   SAVE TXTPTR
  1380        PHA          ...ON STACK
  1390        LDA TXTPTR+1
  1400        PHA
  1410        JSR AS.FRESTR FREE THE STRING;GET ADR IN
  1420        STX TXTPTR   Y,X AND LEN IN A
  1430        STX DEST    SAVE BEGINNING OF STRING
  1440        STY TXTPTR+1
  1450        STY DEST+1
  1460        TAY          LENGTH TO Y
  1470        STA TEMP2    SAVE LENGTH
  1480        LDA (TXTPTR),Y
  1490        PHA          SAVE CHAR AT END OF STRING
  1500        LDA #0
  1510        STA (TXTPTR),Y  PUT 0 AT END OF STRING
  1520        JSR FIN      GET THE NUMBER
  1530        PLA          GET CHAR
  1540        LDY TEMP2    GET LENGTH
  1550        STA (DEST),Y
  1560        PLA           RESTORE TXTPTR
  1570        STA TXTPTR+1
  1580        PLA
  1590        STA TXTPTR
  1600        RTS          VAL IS IN DAC
  1610 *--------------------------------
  1620 *      INT FUNCTION
  1630 *--------------------------------
  1640 DP.INT LDA DAC.EXPONENT
  1650        SEC
  1660        SBC #$40     REMOVE OFFSET
  1670        BPL .1       POSITIVE EXP
  1680 *---ALL FRACTION, MAKE = 0-------
  1690 .0     JMP DP.ZERO
  1700 *---SOME INTEGER, TRUNCATE-------
  1710 .1     BEQ .0       ...ALL FRACTION
  1720        CMP #20      ALL INTEGER?
  1730        BCS .4       ...YES, NONTHING TO LOP
  1740        LSR          DIVIDE BY 2
  1750        TAY          BYTE INDEX
  1760        BCC .3       ...NO NYBBLE TO CLEAR
  1770        LDA DAC.HI,Y ...CLEAR A NYBBLE
  1780        AND #$F0
  1790        STA DAC.HI,Y
  1800 .2     INY          ...NEXT BYTE
  1810        CPY #10      FINISHED?
  1820        BCS .4       ...YES
  1830 .3     LDA #0       CLEAR A BYTE
  1840        STA DAC.HI,Y
  1850        BEQ .2       ...ALWAYS
  1860 .4     RTS
  1870 *--------------------------------
  1880 *      ABS (DAC)
  1890 *--------------------------------
  1900 DP.ABS LDA #0       STORE 0 IN
  1910        STA DAC.SIGN SIGN
  1920        RTS
  1930 *--------------------------------
  1940 *      SGN (DAC)
  1950 *--------------------------------
  1960 DP.SGN LDA DAC.EXPONENT
  1970        BEQ .1       IT IS 0, SO LEAVE IT
  1980        LDA DAC.SIGN
  1990        PHA          SAVE SIGN
  2000        JSR DP.TRUE  PUT 1 IN DAC
  2010        PLA
  2020        STA DAC.SIGN RESTORE SIGN
  2030 .1     RTS
  2040 *--------------------------------
  2050 *      SQR (DAC)
  2060 *      #0072 IN HART, ET AL
  2070 *--------------------------------
  2080 ERR.SQ JMP AS.ILLERR  ILLEGAL QUANTITY
  2090 DP.SQR LDA DAC.EXPONENT
  2100        BEQ .3        SQR(0)=0
  2110        LDA DAC.SIGN
  2120        BMI ERR.SQ   MUST BE POSITIVE
  2130        JSR MOVE.DAC.TEMP3 SAVE X
  2140 *---REDUCE RANGE TO .1 - 1-------
  2150        LDA DAC.EXPONENT
  2160        PHA          SAVE EXPONENT
  2170        LDA #$40     CHANGE RANGE TO .1 THRU .9999...9
  2180        STA DAC.EXPONENT
  2190 *---REDUCE RANGE TO .25 - 1------
  2200        LDA DAC.HI
  2210        CMP #$25     LESS THAN .25?
  2220        PHP          SAVE ANSWER
  2230        BCS .4       ...NO
  2240        LDA #CON.FOUR
  2250        LDY /CON.FOUR
  2260        JSR MOVE.YA.ARG.1
  2270        JSR DMULT
  2280 *---CALC FIRST APPROX.-----------
  2290 .4     JSR MOVE.DAC.TEMP2
  2300        LDA #P.SQR   GET FIRST APPROXIMATION
  2310        LDY /P.SQR   FROM AX^3+BX^2+CX+D
  2320        LDX #P.SQR.N
  2330        JSR POLY.N
  2340 *---ADJUST APPROX FOR FOLDING----
  2350        PLP          WAS X<.25?
  2360        BCS .5       ...NO
  2370        LDA #CON.HALF
  2380        LDY /CON.HALF
  2390        JSR MOVE.YA.ARG.1
  2400        JSR DMULT
  2410 *---COMPUTE SQR EXPONENT---------
  2420 .5     PLA          GET EXPONENT FROM BEGINNING
  2430        SEC
  2440        SBC #$40     REMOVE OFFSET
  2450        ROR          DIVIDE BY TWO (KEEP SIGN)
  2460        EOR #$80
  2470        BCC .1       DON'T MULT BY SQR(10)
  2480 *---ADJUST APPROX FOR ODD EXP----
  2490        PHA          SAVE EXPONENT/2
  2500        LDA #CON.SQR10
  2510        LDY /CON.SQR10
  2520        JSR MOVE.YA.ARG.1
  2530        JSR DMULT
  2540        PLA
  2550 *---INSTALL NEW EXPONENT---------
  2560 .1     CLC
  2570        ADC DAC.EXPONENT
  2580        STA DAC.EXPONENT
  2590 *---THREE NEWTON ITERATIONS------
  2600        LDA #3
  2610        STA TEMP3
  2620 .2     JSR MOVE.DAC.TEMP2     TEMP2 = Y
  2630        JSR MOVE.TEMP3.ARG     GET X
  2640        JSR DDIV               X/Y
  2650        JSR MOVE.TEMP2.ARG
  2660        JSR DADD               X/Y+Y
  2670        LDA #CON.HALF
  2680        LDY /CON.HALF
  2690        JSR MOVE.YA.ARG.1
  2700        JSR DMULT              (X/Y+Y)/2
  2710        DEC TEMP3              ANY MORE?
  2720        BNE .2                 ...YES
  2730 .3     RTS                    ...DONE
  2740 *--------------------------------
  2750 P.SQR.N  .EQ 3
  2760 P.SQR      .HS 4028736982400000000000
  2770            .HS C082588889100000000000
  2780            .HS 4113225638600000000000
  2790            .HS 4021701867200000000000
  2800 CON.SQR10  .HS 4131622776601683793320
  2810 CON.HALF   .HS 4050000000000000000000
  2820 CON.FOUR   .HS 4140000000000000000000
  2830 *--------------------------------
  2840 *      POLYNOMIAL EVALUATOR ROUTINES
  2850 *      (Y,A) = ADDRESS OF COEFFICIENT TABLE
  2860 *      ARRANGED HIGHEST POWER TO LOWEST
  2870 *      CONSTANTS DO USE GUARD BYTE (11 TOTAL)
  2880 *--------------------------------
  2890 *   DO A POLYNOMIAL WITH 1ST CONSTANT 1
  2900 *      (TEMP2) IS X-VALUE
  2910 *      (X-REG) IS N
  2920 *           WHERE N = POWER OF X
  2930 *           FOR EXAMPLE, IF N=2 : X^2+AX+B
  2940 *                           N=4 : X^4+AX^3+BX^2+CX+D
  2950 *--------------------------------
  2960 POLY.1
  2970        STA P1
  2980        STY P1+1
  2990        STX TEMP3
  3000        JSR MOVE.TEMP2.DAC
  3010 POLY   LDA P1
  3020        LDY P1+1
  3030        JSR MOVE.YA.ARG.1
  3040        JSR DADD
  3050        DEC TEMP3    FINISHED YET?
  3060        BNE POLY2    ...NO
  3070        RTS          ...YES
  3080 *--------------------------------
  3090 *      DO A POLYNOMIAL WITH 1ST CONSTANT <> 1
  3100 *      (TEMP2) IS X-VALUE
  3110 *      (X-REG) IS N
  3120 *           WHERE N = POWER OF X
  3130 *           FOR EXAMPLE, IF N=2 : AX^2+BX+C
  3140 *                           N=3 : AX^3+BX^2+CX+D
  3150 *--------------------------------
  3160 POLY.N
  3170        STA P1
  3180        STY P1+1
  3190        STX TEMP3
  3200        JSR MOVE.YA.DAC.1
  3210 POLY2  JSR MOVE.TEMP2.ARG
  3220        JSR DMULT
  3230        CLC
  3240        LDA P1
  3250        ADC #11      NUMBER OF BYTES
  3260        STA P1
  3270        BCC POLY
  3280        INC P1+1
  3290        BNE POLY     ...ALWAYS
  3300 *--------------------------------

An Even Trickier Index to MaskCharles Putney
Dublin, Eire

I got AAL today (September 1984 issue), and pored through it as usual. The index article on page 18 caught my eye. Naturally I tried to think of a smaller way of coding the routine like your TRICKIER.WAY of 32 bytes. Here it is, in only 23 bytes!

     1000 *--------------------------------
     1010 *      PUTNEY'S WAY
     1020 *--------------------------------
     1030 PUTNEY.WAY
     1040        AND #7       .....421
     1050        LSR          ......42, 1 IN CARRY
     1060        PHA          SAVE FOR LATER PLP
     1070        LDA #1       INITIAL MASK VALUE
     1080        BCC .1       NO NEED TO SHIFT 1
     1090        ASL
     1100 .1     PLP          GET 1.....42 AS NV.BDIZC
     1110        BCC .2       NO NEED TO SHIFT 2
     1120        PHP
     1130        ASL
     1140        ASL
     1150        PLP
     1160 .2     BNE .3       NO NEED TO SHIFT 4
     1170        ASL
     1180        ASL
     1190        ASL
     1200        ASL
     1210 .3     RTS

The timing, not including a JSR to it nor the RTS at the end, varies from a best case of 21 cycles to a worst case of 39 cycles.

[One note of warning: the PLP pulls a status of 000000xx, setting the I-status to zero. This enables IRQ interrupts, which might be very dangerous if you have an interrupting source connected and were otherwise unprepared.]


Correction to DP18, Part 5Paul Schlyter

The following comments relate to the listing on page 13 of the September 1984 issue.

It appears to me that lines 4610-4620 and 4650-4660 can be deleted. They check for the non-tokenized forms of + and -, which I believe will never be presented to DP18.

There is a definite bug at line 4460: the LDA #$02 should be LDA #$04. Compare with lines 4370 and 4410, and you will see how I caught it. Also the comment on line 4170, which says the bit map is in the form 00000<=>.


Another Tricky WayBruce Love
Hamilton, New Zealand

Here is my effort to improve your version of turning an index into a mask. It uses (shudder!) self-modifying code, but it is shorter and faster and I think easy to understand.

LOVE.VERSION
       AND #7
       EOR #7
       STA .1+1
       LDA #1
.1     BNE .1  (OFFSET FILLED IN)
       ASL
       ASL
       ASL
       ASL
       ASL
       ASL
       ASL
       RTS

And still anotherDavid Eisler
Littleton, Colorado

With reference to Turn Index into a Mask (AAL Sept 84), here is another tricky alternative. It uses only the A-register, is only 16 bytes long, and takes 9 to 23 cycles.

EISLER.VERSION
       AND #7
       STA .1+1
       LDA #$80
.1     BNE .1  (OFFSET FILLED IN)
       LSR
       LSR
       LSR
       LSR
       LSR
       LSR
       LSR
       RTS

The 65802 is Here!Bob Sander-Cederlof

I think it was last December that I learned of the new 16-bit versions of our old friend, the 6502. You will remember my enthusiastic description in the Jan 84 issue. People at Western Design Center were optimistic about shipping chips in a month or so. Very optimistic. Way too optimistic. Nevertheless, they followed the tradition of our whole industry by continuing to stick by their commitment. Every time we called, it was always in a month or so!

But yesterday (Oct 12th) it arrived. Nice shiny new COD sticker on top, for $98.05, and nice new 40-legged bug inside. I plugged the 65802 into my //e, after carefully removing the 65C02 I had just put in a week before. Power on, the drive whirrs, RESET works, hurray!

So far I have spent about six hours exploring the new opcodes. I used the new but yet unreleased version 2.0 of the S-C Macro Assembler, naturally. The literature available up till now has been very sketchy on the details of some of the new opcodes and addressing modes. Anyway, no matter how well the printed word is used, the chip itself will always have the final say, the last word.

Which reminds me that I have already had to correct one mis-understanding (bug?). I was not computing the relative offsets for the 16-bit relative address mode. There are two opcodes which use this mode: BRL, Branch Relative Long; and PER, Push Effective address Relative.

BRL can branch anywhere within a 64K memory, using an offset of 16-bits. Compare this with the other relative branches, which use only an 8-bit offset and can only branch inside a 256-byte space centered around the instruction. BRL's offset ranges from -32768 to +32767.

PER pushes two bytes onto the stack. The two bytes pushed are the high byte and then the low byte of the address calculated by adding the 16-bit offset to the current PC-register. For example,

       0800- 62 FD FF    PER $0800
       0803-

pushes first $08 and then $00 onto the stack. Voila! Now we really can write position independent code! Using the 16-bit mode, I can PER the address of a data item or table onto the stack, and then PLX (Pull to X-register) that address, and access data by LDA 0,X or the like.

Another favorite pair are the two block move instructions: MVN and MVP. With these I can move any block of memory from 1 byte up to 64K bytes from anywhere to anywhere. With the 65802, anywhere is still limited to the 64K address space, but with the 65816 it can be anywhere in 16 megabytes.

To get full advantage of MVP and MVN, you need to be in the 16-bit mode. You get there in two steps: first you turn on the 65802 mode, as opposed to the 6502-emulation mode; and then you set some status bits which select 16-bit memory references and 16-bit indexing.

You turn on the 65802 mode by clearing the new E-bit in the status register. The E-bit hides behind the Carry bit, and you access it with the XCE (Exchange C and E) instruction.

       CLC
       XCE     turns on 65802 mode

       SEC
       XCE     turns on 6502 emulation mode

Then REP #$30 turns on the 16-bit mode. REP stands for Reset P-bits. Wherever there are one bits in the immediate value, the corresponding status bits will be cleared. Where there are zero bits in the immediate value, the corresponding status bits will be unaffected. The two bits cleared by REP #$30 are the M- and X-bits. If either of these, or both, are zero, the immediate mode of LDA, LDX, LDY, CMP, ADC, SBC, AND, ORA, and EOR become three byte instructions. For example,

       LDA ##$1234

loads $1234 into the extended 16-bit A-register. The long A-reg gets a new name or two. The high byte is called the B-register, the low byte is still the A-register, and the pair together are called the C-register.

Okay. Now back to the block movers. Both of the moves require some setting up first. You put the 16-bit address of the source block into the X-register, the destination address in Y, and the move count in C. For example, suppose I want to move the block $0800-$0847 up to $0912:

       LDX ##$0800     source
       LDY ##$0912     destination
       LDA ##$0047     # bytes - 1
       MVN 0,0         move it

As each byte is moved, X and Y are incremented and A is decremented. After all is complete, A will have $FFFF, X=$0848, and Y=$095A.

MVP, on the other hand, decrements the A-, X- and Y-registers for each byte moved. If the block source and destination overlap, you can use the one which moves in the order that prevents mis-copying.

Those two zeroes after the MVN instruction above are two 8-bit values. In the 65802 they don't mean anything, but in the 65816 they are the high 8-bits of the 24-bit addresses of source and destination. In the 65816, you could copy one entire 64K bank to another with just four instructions! And it only takes 3 cycles per byte moved!

The 65802 plugs directly into the 6502 socket in your Apple //e. It may or may not work in older Apples ... I haven't tried it yet. The 65816 will not plug into any current Apple II, even though it also has forty pins. The extra 8-bits of address are multiplexed on the 8 data lines, and the meaning of the other pins is somewhat changed.

Please don't get the idea that plugging in this new chip will speed up your old software. Old software will stay in the 6502 emulation mode, and will run at exactly the same pace as before. New software can be written which will take advantage of the new features, and it can be a little faster, more compact, and so on. The exciting future of the 65802 and 65816 lies not inside old Apples, but in the Apples yet to be born. I am dreaming of a 4-megahertz, 1- to 8-megabyte Apple ...

Meanwhile, here is a REAL example. Way back in the January 1981 issue of Apple Assembly Line I published a General Move Subroutine. It was set up as a control-Y command for the monitor. As an improvement over the monitor M-command, it could move blocks which overlapped either up or down in memory without repeating the leading bytes.

The following program takes advantage of the MVN and MVP commands to greatly speed up and shrink my previous effort. The old one took 149 bytes, the new one only 80. Disregarding all the setup time, which also improved, the time to move a single byte changed from a minimum of 16 cycles to a consistent 3 cycles.

Lines through 1090 describe how to set up and run the program, but don't even TRY it until you get a 65802 chip into your Apple! The new opcodes will do amazing things in an old 6502 chip, but nothing at all like intended.

Line 1100, the .OP 65816 directive, tells version 2.0 that it should allow and assemble the full 65816 instruction set.

Lines 1180-1250 are executed if you use $300G after assembling, or if you BRUN it from a type-B file.

A1, A2, and A4 are monitor variables which are setup by the control-Y command. When you type, for example, 800<900.957^Y (where by ^Y I mean control-Y), $800 is stored in A4, $900 in A1, and $957 in A2.

Lines 1270-1290 save the three registers, and these will be restored later at lines 1500-1520. Lines 1320-1340 get us unto the 16-bit mode described above. Just before returning to the monitor we will switch back to 6502 emulation mode, at lines 1480-1490.

Lines 1360-1390 calculate the #bytes-1 to be moved, by using 16-bit subtraction. Note that the opcodes assembled are exactly the same as they would be for 8-bit operations; the cpu does 16-bit steps here because we set the 16-bit mode.

Lines 1410-1460 determine which direction the block is to be moved: up toward higher memory addresses, or down toward lower addresses. By using two separate routines we prevent garbling the move of an overlapping block.

Lines 1610-1660 move a block down. It is as easy as rolling off a log.... Just load up the registers, and do an MVN command.

Lines 1680-1760 move a block up. Here we need the addresses of the ends of the blocks, so lines 1690-1720 calculate the end address for the destination. Then we do the MVP command, and zzaappp! it's done.

  1000 *SAVE S.GENERAL MOVER
  1010 *--------------------------------
  1020 *   BRUN the program to set it up as
  1030 *      a control-Y monitor command.
  1040 *--------------------------------
  1050 *   Use like the Monitor M-command:
  1060 *      A1 -- Source start address
  1070 *      A2 -- Source end address
  1080 *      A4 -- Destination start address
  1090 *--------------------------------
  1100        .OP 65816
  1110        .OR $300
  1120 *--------------------------------
  1130 A1     .EQ $3C,3D
  1140 A2     .EQ $3E,3F
  1150 A4     .EQ $42,43
  1160 BLKSIZ .EQ $00,01
  1170 *--------------------------------
  1180 CONTROL.Y.SETUP
  1190        LDA #$4C
  1200        STA $3F8
  1210        LDA #GENERAL.MOVER
  1220        STA $3F9
  1230        LDA /GENERAL.MOVER
  1240        STA $3FA
  1250        RTS
  1260 *--------------------------------
  1270 GENERAL.MOVER
  1280        PHA
  1290        PHY
  1300        PHX
  1310 *--------------------------------
  1320        CLC          65816 MODE
  1330        XCE
  1340        REP #$30     16-BIT MODE
  1350 *--------------------------------
  1360        SEC          Compute block length - 1
  1370        LDA A2
  1380        SBC A1
  1390        STA BLKSIZ
  1400 *--------------------------------
  1410        LDA A1
  1420        CMP A4       Determine direction of move
  1430        BCC .1       ...UP
  1440        JSR MOVE.DOWN
  1450        BRA .2       ...ALWAYS
  1460 .1     JSR MOVE.UP
  1470 *--------------------------------
  1480 .2     SEC          RETURN TO 6502 MODE
  1490        XCE
  1500        PLX
  1510        PLY
  1520        PLA
  1530        RTS
  1600 *--------------------------------
  1610 MOVE.DOWN
  1620        LDX A1       Source start address
  1630        LDY A4       Destination start address
  1640        LDA BLKSIZ   # Bytes - 1
  1650        MVN 0,0
  1660        RTS
  1670 *--------------------------------
  1680 MOVE.UP
  1690        CLC
  1700        LDA A4
  1710        ADC BLKSIZ
  1720        TAY          Destination end address
  1730        LDX A2       Source end address
  1740        LDA BLKSIZ   # Bytes - 1
  1750        MVP 0,0
  1760        RTS

Out of PrintBob Sander-Cederlof

After printing the mini-review of Gene Zumchak's Microprocessor Design and Troubleshooting last month, we naturally started receiving orders for the book. I had some on order from Sams, but Lo! It is now out-of-print! I talked with someone inside Sams and they said it will probably remain out-of-print.

I talked with the author directly, and I believe that if necessary he will re-publish the book himself. It is a worthy book, and needs to be available. He wants to update some of the material, too. We'll let you know when we can get it again.

You may have noticed that computer books are now the in thing to publish. I would not be surprised if some publishers began having serious difficulties because of their eagerness to grab this market. They are publishing fluff for the neophytes, forgetting the really useful technical titles. I hope Sams does not forget how it got where it is today.

Meanwhile, as Art Carlson says, If you see a book you need you had better get while it is still available.

On this same subject, let's see if we can put some pressure on Apple to make their reference manuals more readily available. I find that very few (hardly any) Apple dealers will stock or even special order the ProDOS, //e, and //c Reference Manuals. More than twice I have been told that (for example) the //e manual had never been published, even though I bought a copy at a store many moons ago. It seems that Apple will only sell the books in bundles of five or more of the same title, and then only to Apple dealers. Apple dealers seem to not want to order five or more of what are a relatively slow moving item. After all, they are not book stores. And consequently, Apple gets the erroneous impression that they really do not need to publish the manuals, because no one is buying them! If you know anyone in Apple, pass the word to them: WE DO WANT REFERENCE MANUALS. Maybe it does make sense not to ship a copy of every manual with every computer, but some means MUST be available for EVERY owner to buy the manuals he needs.


Corrections to Line Number Cross ReferenceBill Morgan

Allen Miller just called up from Hong Kong (at 3:30 AM his time!) to report a problem with the Line Number Cross Reference program in the August issue. It seems that as published it only prints out the first line number list in each chain. The troublemaker is line 4560, which says BNE .1. Well .1 is the next line, so the routine is always exiting after only one pass. Line 4560 should read BNE PRINT.CHAIN, to go back to the beginning rather than on to the end.

Then Chuck Welman called to point out yet another problem. It seems that an undefined line number greater than the last line of the program caused LCR to head off into the wilderness. When I investigated this one it proceeded to get even stranger. LCR would hang only if the undefined line number was greater than 19668! Less than 19668 came out just right, and equal to 19668 worked, but LCR mistakenly said the line was defined. Now here was a real creepy crawler of a bug!

Well the problem turned out to be in the CHECK.DEFINITION routine. Here are the offending lines:

     4790 .4    LDY #0
     4800       LDA (PNTR),Y    lo-byte of next line address
     4810       PHA
     4820       INY
     4830       LDA (PNTR),Y    and hi-byte
     4840       STA PNTR+1
     4850       PLA
     4860       STA PNTR
     4870       JMP CHECK.DEFINITION

This code is called when CHECK.DEFINITION wants to get the next line of the Applesoft program. The trouble comes up because there is no check for end-of-program. Sooner or later we come to the zero bytes that mark the end, load up PNTR with zeroes, and go back to CHECK.DEFINITION to try what seems to be the next line. That routine then compares the line number we are checking to the contents of locations 2 and 3 of memory, which Applesoft has loaded with D4 and 4C. Now $4CD4 equals 19668, so that's where that funny number came from!

Here is a slightly rearranged, working version of lines 4790-4870. Note that we have reversed the hi-lo byte sequence and added a check for a zero hi-byte:

     4790 .4    LDY #1
     4800       LDA (PNTR),Y    hi-byte of next line address
     4805       BEQ .2          end of program?
     4810       PHA
     4820       DEY
     4830       LDA (PNTR),Y    and lo-byte
     4840       STA PNTR
     4850       PLA
     4860       STA PNTR+1
     4870       JMP CHECK.DEFINITION

Index to Articles in Apple Assembly Line, Volume 4

AAAA
Applesoft
  Fast Garbage Collection..........................Paul Shetler... 3/84/2-12
  Faster Amper-Routine to Zero Arrays..........Johan Zwiekhorst... 9/84/16-17
  Generalized GOTO and GOSUB............................Bob S-C...12/83/15-17
  Random Numbers for Applesoft..........................Bob S-C... 5/84/2-13
  More Random Number Generators.........................Bob S-C... 6/84/15-18

BBBB Benchmarks Rod's Color Pattern in 6502 Code............Charles H. Putney... 3/84/21-26 Sieve Benchmark on the 68000...............Peter J. McInerney... 7/84/16-17 Updating the 6502 Prime Sifter........................Bob S-C... 7/84/18-19 Book Reviews Annotated 68000 Bibliography......................Bill Morgan... 2/84/19 Assembly Cookbook for the Apple II/IIe................Bob S-C... 9/84/28,30 Beneath Apple ProDOS..................................Bob S-C... 9/84/28,31 Bibliography on Apple Hi-Res Graphics.................Bob S-C... 9/84/23-27 The Computer Hacker and Dataphile Digest....................11/83/24 Demise of Dataphile Digest..................................12/83/1 Don Lancaster's Micro Cookbook, Volume 2........Bill Morgan... 1/84/9 Don Lancaster Strikes Again (another new book).................. 7/84/1 Microcomputer Design & Troubleshooting................Bob S-C... 9/84/30 Understanding the Apple II, by Jim Sather.............Bob S-C... 1/84/25-26

CCCC Corrections Corrections to Generic Screen Dump...............Steve Knouse...10/83/12 Corrections to the Intellec Hex Converter.............Bob S-C... 5/84/1 Cross Assemblers Changing Tab Stops in the 68000 Cross Assembler.......Bob S-C... 3/84/15 Converting to Intellec Hex Format.....................Bob S-C... 4/84/14-18 Corrections to the Intellec Hex Converter...........Bob S-C... 5/84/1 Converting to Motorola S-Format.......................Bob S-C... 6/84/22-27 Hitachi 6301 Cross Assembler (announcement)...........Bob S-C...11/83/21 New Cross Assemblers: Z-8, GI-1650, GI-1670.................... 8/84/1 Zilog Z-8 Cross Assembler....................................... 4/84/1 Cyclic Redundancy Check Subroutine......................Bob S-C... 4/84/2-10 Finding the Erroneous Bit Using CRC................Bruce Love... 6/84/20-21

DDDD Disassemblers Building Label Tables for DISASM......................Bob S-C... 7/84/12-13 Using EXEC Files with Rak-Ware's DISASM............Bob Kovacs... 4/84/26-28 Disk Drive Pressure Pads................................Bob S-C... 3/84/20 DOS Enhancements and Patches Changing VERIFY to DISPLAY............................Bob S-C... 3/84/13-14 DOS Checksummer Debate Update.........................Bob S-C... 2/84/10 DOSology and DOSonomy.................................Bob S-C... 6/84/9 Feedback on our DOSonomy...................................... 7/84/1 Faster Booting for Screenwriter II.................Bob Leedom...10/83/14 Killing the EXEC..................................Bob Bragner...11/83/22 Modify DOS for Big BSAVEs.............................Bob S-C... 8/84/28 DOS Enhancements and Patches, contd. Patches to Avoid Interrupt Trouble......... .......Bruce Field, Bob S-C, and Bill Morgan... 1/84/10-11 Peeking at the CATALOG................................Bob S-C... 2/84/6 Quick DOS Updating vs. MASTER.CREATE..................Bob S-C... 4/84/19-23 Using EXEC Files with Rak-Ware's DISASM............Bob Kovacs... 4/84/26-28 Double Precision Arithmetic Package DPFP Now Includes Source Code................................... 4/84/1 Decimal 18-Digit Floating Point Arithmetic Package....Bob S-C... Part 1, Addition and Subtraction.............................. 5/84/20-25 Part 2, Over/Underflow, Load/Store, Multiplication, Rounding.. 6/84/2-8 Part 3, Division and Input Conversion......................... 7/84/2-11 Part 4, Output Conversion..................................... 8/84/2-11 Part 5, Applesoft Linkage and Expression Parsing.............. 9/84/2-15 Speed vs. Space, Faster Multiplication........................ 7/84/26-28

EEEE Enhancements and Patches to S-C Macro Assembler Changing Tab Stops in the 68000 Cross Assembler.......Bob S-C... 3/84/15 EXTRA DEFINITION ERROR, Avoiding..................Bill Morgan...10/83/17 Large Assembly Listing into Text File.......Robert F. O'Brien...10/83/16 Lower Case Titles in Version 1.1................Bob Matzinger...10/83/17 Lower Case Titles Revisited.....................Bob Matzinger...11/83/28 More on Assembly Listing into Text File.......Tracy L. Shafer...12/83/12-14 Procedure for Converting S-C Source Files to Text Files without Owning an S-C Assembler..........Bob S-C...12/83/26-28 S-C Macro and GPLE.LC on the //e..................Bob Bragner... 3/84/16 Suppressing Unwanted Object Bytes in Listings...David Roberts...10/83/19 Using the PRT Command in S-C Macro................Bill Morgan... 6/84/12-14 EPROMs Burning and Erasing EPROMs............................Bob S-C... 4/84/23-24 Converting to Intellec Hex Format.....................Bob S-C... 4/84/14-18 Corrections to Intellec Hex Converter...............Bob S-C... 5/84/1 Converting to Motorola S-Format.......................Bob S-C... 6/84/22-27

GGGG Graphics Bibliography on Apple Hi-Res Graphics.................Bob S-C... 9/84/23-27 If You Like Shapes, Try Shapemaker....................Bob S-C...10/83/24 Macro Generates Quotient/Remainder Table for Hi-Res...Bob S-C... 2/84/28 Rod's Color Pattern in 6502 Code............Charles H. Putney... 3/84/21-26

HHHH Hardware Troubleshooting About Disk Drive Pressure Pads........................Bob S-C... 3/84/20 Finding Trouble in a Big RAM Card.....................Bob S-C...12/83/21-24 Making a 65C02 Work in My Apple II Plus........William O'Ryan... 6/84/28 Quick Memory Testing..................................Bob S-C... 7/84/14 Review of Microcomputer Design & Troubleshooting.....Bob S-C... 9/84/28-31 Speaking of Slow Chips..............................Bob Stout... 8/84/27 Hardware Reviews Amazing quikLoader Card.............................Bob S-C... 2/84/27 An Apple Mouse, and other news.................................. 1/84/1 Apple //c.............................................Bob S-C... 5/84/14-16 Our //c came in and we love it; however.............Bob S-C... 7/84/24 Burning and Erasing EPROMs............................Bob S-C... 4/84/23-24 Hardware Reviews, contd. More Clocks for Apple.................................Bob S-C... 4/84/10 More on the New 65802 and 65816.......................Bob S-C... 1/84/14-20 Non-volatile RAM Chip (mention)..................Rodney Jacks...11/83/1 Qwerty 68000 Training/Development System..............Bob S-C...11/83/16-17 So That's a Macintosh!............................Bill Morgan... 2/84/11 Timemaster II from Applied Engineering................Bob S-C...12/83/19-20

IIII Interrupts DOS Patches to Avoid Interrupt Trouble..... .......Bruce Field, Bob S-C, and Bill Morgan... 1/84/10-11 Enable/Disable IRQ from Applesoft.....................Bob S-C... 8/84/13-14 Profiler: Using 60Hz IRQ's to Profile a Program...Bill Morgan... 1/84/2-9

LLLL Language Card Finding Trouble in a Big RAM Card.....................Bob S-C...12/83/21-24 Fixing the Andromeda 16K RAM Card.................Bob Bernard... 6/84/19 Table of //e Soft Switches............................Bob S-C... 2/84/20-21 Line Number Cross Reference for Applesoft...........Bill Morgan... 8/84/15-26 Listing into Text File, Large Assembly........Robert F. O'Brien...10/83/16 More on Assembly Listing intor Text Files.....Tracy L. Shafer...12/83/12-14 Lower Case Titles in Version 1.1...........................Bob Matzinger...10/83/17 Titles Revisited................................Bob Matzinger...11/83/28

MMMM Macros Building Label Tables for DISASM......................Bob S-C... 7/84/12-13 Counting Lines Produced by Macro Expansion........Bill Morgan...10/83/21 Macro-calculated Spiral Screen Clear............Bruce V. Love...10/83/20 Macro Generates Quotient/Remainder Table for Hi-Res...Bob S-C... 2/84/28 Sorting and Swapping..................................Bob S-C... 7/84/20-23 Memory Testing Finding Trouble in a Big RAM Card.....................Bob S-C...12/83/21-24 Quick Memory Testing..................................Bob S-C... 7/84/14 Monitor Enhancements Booting ProDOS with a Modified Monitor ROM......Jan Eugenides... 6/84/18 Compilation of Monitor Modifications.............Steve Knouse...10/83/2-9 Fast Scroll for the //e 80-column.....................Bob S-C... 2/84/8-10 Apple //e ROM Revision................................Bob S-C... 5/84/18-19 Monitor Information Erv Edge's Source of //e CxROM on Disk.......................... 2/84/1 Delays, delays, delays (especially $FCA8).............Bob S-C... 2/84/14-18

PPPP Patches and Modifications to Other Software Booting ProDOS with a Modified Monitor ROM......Jan Eugenides... 6/84/18 Faster Booting for Screenwriter II.................Bob Leedom...10/83/14 More on ProDOS and Non-Standard Apples.......................... 6/84/1 S-C Macro and GPLE.LC on the //e..................Bob Bragner... 3/84/16 Speaking of Locksmith 5.0...................Warren R. Johnson... 3/84/19 Using EXEC Files with Rak-Ware's DISASM............Bob Kovacs... 4/84/26-28 Will ProDOS Work on a Franklin?.....................Bob Stout... 3/84/20 Prime Number Sieve Benchmark Sieve Benchmark on the 68000...............Peter J. McInerney... 7/84/16-17 Updating the 6502 Prime Sifter........................Bob S-C... 7/84/18-19 Printer Interfaces Using the PRT Command in S-C Macro................Bill Morgan... 6/84/12-14 ProDOS Booting ProDOS with a Modified Monitor ROM......Jan Eugenides... 6/84/18 Clock Drivers and ProDOS..............................Bob S-C...11/83/25-28 Commented Listings $F800-F90B, $F996-FEBD..............................Bob S-C...11/83/2-14 $F142-F1BE..........................................Bob S-C...11/83/25-28 $F90C-F995, $FD00-FE9A, $FEBE-FFFF..................Bob S-C...12/83/2-11 More on ProDOS and Non-Standard Apples.......................... 6/84/1 Review of Beneath Apple ProDOS......................Bob S-C... 9/84/28-31 Will ProDOS Really Fly?...............................Bob S-C... 3/84/28 Will ProDOS Work on a Franklin?.....................Bob Stout... 3/84/20 Profiler: Using 60Hz IRQ's to Profile a Program.....Bill Morgan... 1/84/2-9

RRRR Random Number Generators Random Numbers for Applesoft..........................Bob S-C... 5/84/2-13 More Random Number Generators.........................Bob S-C... 6/84/15-18 Reviews, see Book Reviews, Hardware Reviews, Software Reviews

SSSS S-C Macro Assembler Enhancements and Patches........ .........see Enhancements and Patches to S-C Macro Assembler S-C Software Corporation Clarification about our Copyrights....................Bob S-C... 2/84/8 I Think It Was a Bad Dream (Suits, Suits, Suits)......Bob S-C... 1/84/12-14 New Cross Assemblers: Z-8, GI-1650, GI-1670.................... 8/84/1 New Products: Z-8 Cross Asm, DPFP, and Macro 1.1 Source......... 4/84/1,28 Orphans and Widows, Updating the S-C Word Processor...Bob S-C... 7/84/25 Price Changes.........................................Bob S-C...10/83/13 Where To? (68000? C?)............................Bill Morgan...10/83/19 Where To? Revisited...............................Bill Morgan...12/83/28 Screen Dump, Corrections to Generic................Steve Knouse...10/83/12 Screenwriter II, Faster Booting for..................Bob Leedom...10/83/14 Software Reviews Aztec C Compiler for Apple DOS....................Bill Morgan...11/83/18-20 Note on Aztec C.................................Bill Morgan...12/83/14 Barkovitch Utilities............................................ 6/84/21 Lancaster's OBJ.APWRT][F..............................Bob S-C... 3/84/19 Locksmith 5.0.........................................Bob S-C... 1/84/26 Speaking of Locksmith 5.0.................Warren R. Johnson... 3/84/19 OBJ.APWRT][F Updated to AW//e Toolkit...........Don Lancaster... 6/84/10 Shapemaker If You Like Shapes, Try Shapemaker..................Bob S-C...10/83/24 Shapemaker Enhancements......................Frank Belanger...11/83/24 Source Code On Disk DPFP (Double Precision for Applesoft)........................... 4/84/1 Erv Edge's Source for //e CxROM................................. 2/84/1 S-C Macro Assembler Version 1.1 Source Code..................... 4/84/1,28 Spiral Screen Clear, Macro-Calculated.............Bruce V. Love...10/83/20

TTTT Techniques Cyclic Redundancy Check Subroutine....................Bob S-C... 4/84/2-10 Finding the Erroneous Bit Using CRC..............Bruce Love... 6/84/20-21 Delays, delays, delays (especially $FCA8).............Bob S-C... 2/84/14-18 Enable/Disable IRQ from Applesoft.....................Bob S-C... 8/84/13-14 Fast Scroll for the //e 80-column.....................Bob S-C... 2/84/8-10 Listing Buried Messages...............................Bob S-C... 2/84/2-5 Making a Map of Differences...........................Bob S-C... 5/84/27-28 Peeking at the CATALOG................................Bob S-C... 2/84/6 Put Your Messages on the Screen...............William R. Reed... 9/84/22 Redundancy in Tables for Faster Lookups...............Bob S-C... 3/84/17-18 Text Area Erase Routine..........................Jeff Creamer... 2/84/22-25 Turn an Index into a Mask.............................Bob S-C... 9/84/18-21 Sorting and Swapping..................................Bob S-C... 7/84/20-23 Speed vs. Space, faster DP18 Multiplication...........Bob S-C... 7/84/26-28 Tips and Hints Reminder about Wrap-Around Addressing.............Bill Parker... 2/84/12 Table of //e Soft Switches............................Bob S-C... 2/84/20-21 What That Code Did....................John Broderick, Bob S-C... 5/84/26

UUUU Utility Programs Corrections to Generic Screen Dump...............Steve Knouse...10-83/12 Converting S-C Source Files to Text Files without Owning an S-C Assembler..................Bob S-C...12/83/26-28 Line Number Cross Reference for Applesoft.........Bill Morgan... 8/84/15-26 PROFILER: Using 60Hz IRQ's to Profile a Program...Bill Morgan... 1/84/2-9 Still More Tinkering with VCR......................Louis Pitz...10/83/11

VVVV VCR, Still More Tinkering with.......................Louis Pitz...10/83/11

WWWW Wagner, Roger, Some Interesting News.............................. 5/84/17 Wozniak, Steve On-Line with Steve Wozniak...................................... 1/84/27-28 Evening with Woz..................................Bill Morgan... 4/84/11-12

6502 65802, 65816 More on the New 65802 and 65816.......................Bob S-C... 1/84/14-20 65C02 Making a 65C02 Work in My Apple II Plus........William O'Ryan... 6/84/28 Will Rockwell's 65C02 Work in an Old Apple?.........Bob Stout... 3/84/16 65C02 vs. the Older Apples............................Bob S-C... 5/84/19 68000 Annotated 68000 Bibliography......................Bill Morgan... 2/84/19 Qwerty 68000 Training/Development System (review).....Bob S-C...11/83/16-17 68000 Color Pattern...............................Bob Urschel... 1/84/21-24 Changing Tab Stops in the 68000 Cross Assembler.......Bob S-C... 3/84/15 Sieve Benchmark on the 68000...............Peter J. McInerney... 7/84/16-17


Macintosh AssemblersLane Hauck
San Diego, CA

I have the privilege* of Beta testing two 68000 assemblers for the Macintosh -- the one from Apple (Workshop), and the one from Mainstay. Mainstay is the serious side of Funsoft.

* (If you are masochistic, and enjoy little surprises like alert boxes with no messages or GoAwayButtons in them, frequent crashes, and system fonts abruptly changing; you too might want to become a Beta Tester.)

I've gotten permission from both Apple and Mainstay to talk about these products. The versions I'm testing are preliminary, and therefore subject to change.

The Workshop is in version 0.6 release, and is expected to be available about October (I'd guess November). The Mainstay product is scheduled for early October release, and judging from their staff and working hours, I think they'll make it. (I visited them in Agoura, CA, and found a very smart and hard working group of programmers.)

Although both assemblers do the same thing -- translate 68000 source programs into runnable programs on the Macintosh -- they couldn't be more different in how they operate!

The Apple Assembler

The Workshop has several parts. EDIT, ASM, LINK and EXEC are four applications that do the actual code development. Additionally, RMAKER creates resource files from text source files created by EDIT. And finally, MacDB and its associated Nub programs provide debug support for when your code doesn't run.

The development system can run on one drive, but two are highly recommended.

EDIT: This is a DISK BASED editor, so the short document frustrations of MacWrite are avoided. Additionally, you can open up to four documents, and cut and paste between them (a la Lisa)! This is a bare bones (but wonderful) editor, without fancy fonts or formatting. One improvement over the Lisa editor: it has a reverse tab -- hitting backspace from a tab stop takes you back not one space, but back one tab position. This is a great convenience when you're entering formatted source code.

ASM: Supports conditional assembly, macros (both Lisa-type and new Mac-type). It's tailored to the Mac development environment (for example it helps you write relocatable code).

Toolbox support is provided by special, compressed equate files (they are compressed by a program called PacSyms, which you can use to compress your own equate files). The Workshop provides all the Trap and symbol equates mentioned in Inside Macintosh.

LINK: Links .REL code modules produced by the Assembler, and (eventually -- not working yet) output files from RMAKER to produce a final file, complete with your code and resources. Takes its direction from a .LINK text file.

EXEC: Lets you automate the entire ASM-LINK process. One great improvement over the Lisa version: you can direct EXEC to reenter the editor if any assembly or link errors occur.

FIVE debuggers are supplied. MacDB is the best, most visible debugger I'ver ever seen. It requires two Macs (or one Mac and a Lisa running MacWorks). The Workshop will be supplied with an interconnect cable for two Macs. Other debugger versions (which don't require the second Mac) let you debug from an 8-line onscreen window on the Mac, and from any remote terminal.

This is a professional, complete, industrial strength 68000 assembly language development package. Its utilization of the Macintosh environment is total and outstanding. My only real quibble is that it takes a fair amount of time (a few minutes) to turn one cycle from EDIT to running the new code. A hard disk would presumably improve this greatly.

If you're an interactive programmer who likes to make changes and see their results QUICKLY, you might be interested in the Mainstay Assembler.

The Mainstay Assembler

If you've ever used any of the assemblers for the Apple II from S-C Software, you'll feel right at home with the Mainstay environment. It's patterned after the S-C 68000 Cross Assembler, and it looks and feels just like you're running on an Apple //e!

The fact that none of the Macintosh interface is used will bother some, especially the Mac purists. Mainstay's intention is to get a quality assembler to market quickly, and the approach they've taken allows this to happen. I don't mind non-fidelity to the Mac interface in a DEVELOPMENT product -- we developers are EXPECTED to put up with all sorts of indignities!

This is an absolute assembler, meaning that your code module is produced with an address origin, and it is loaded and run at that address. It does not produce linkable code modules, as does the Apple Workshop Assembler. In fact no linker is supplied or required.

The Editor is built in, and it functions much like the Apple II. The cursor is moved around with keyboard commands. The Editor has BASIC-like line numbers and the normal complement of line-number oriented commands (RENumber, COPY, MOVE, etc.).

Resources are handled right inside your source code (remember there is only one code module). This is more convenient than the Apple RMAKER approach.

The Assembler supports conditional assembly, macros, and local labels. It takes a novel approach in how it is installed and run on the Macintosh.

When you start the Assembler, it grabs a large chunk of memory from the application heap, and uses it for storing the symbol table, source code, and object code. Typing MEM shows you exactly where these three memory areas are. While you're in the Assembler environment, your code stays put, so you can deal with absolute addresses without fear that the memory manager will move things around on you.

This means that you can edit, assemble, and test your code IMMEDIATELY, without goin through a linking and (optionally) a resource compiling step. This is the primary strength of this assembler -- it allows quicklook programming which is ideal for experimentation and learning the Macintosh system.

Eventually you will want to make your application an installable Macintosh program, so you should get into the habit of writing position independent code. The Mainstay package will supply the tools necessary to make your application runnable on the Mac. It will also contain Toolbox and Operating System equate files.

There are some nice Apple II-like features, such as typing DIR to look at the disk catalog. In the Mac environment, you have to exit the application and get back to the desktop to see your files. You can also type EJECT and eject a disk immediately. I like to do this just before running new code, to protect disks from my runaway test programs that mysteriously fire up the disk drive.

Having this assembler, a Mac, and a copy of INSIDE MACINTOSH might just be the most efficient way to learn the Macintosh. The prime benefit of this assembler is its very high speed in moving between editing, assembling, and running your test code.

Which One?

Which assembler would I recommend? At this stage I'd have to give the universal Computer Salesman answer: It depends.

The Apple one allows you to write separate code modules, assemble them, and then link them together later. This allows you to utilize already written and debugged modules in new programs.

Another advantage of the linker approach is that a single module can be changed and reassembled, and then linked to other already-debugged modules. This saves reassembling the whole shebang every time you make a change.

If you like this relocatable assembler approach, you'll want the Apple Assembler. (If you're comfortable with the Lisa Assembler, ditto.)

The Mainstay Assembler, by contrast, is an absolute assembler - it puts code at a particular place in memory (set by an ORG - origin statement), and allows only one module -- your entire program. (Better write relocatable code if you want it to run as an application, though!)

The Mainstay Assembler is so fast (especially if you put a LIST OFF directive at the beginning of your code), that it negates the speed advantage of the linked module approach. I would guess that it takes you from source code edit to running reassembled code in about one-twentieth the time required by the Apple Assembler. if you're an interactive programmer who likes to see results of program changes FAST, the Mainstay Assembler is for you.

If time is a factor, the Mainstay product will ship within a week; the Apple Assembler is supposed to come out in October, but I doubt it.

If you're unhappy with non-Mac-user-interface products, you're better off with the Apple version. The operation of the Mainstay assembler is a bit strange at first, but anyone with Apple II roots will adjust quickly.

Here's a factor I consider very important: Apple is a Pascal house with almost no support given to assembly language programming of the Macintosh. I've found their support in this area dismal.

The Mainstay Assembler is a major committment by this small company. I've had quite a bit of technical interaction with them, and have found them to be very intelligent, motivated, and responsive. I've had indications that you'll be able to expect not only Assembler support from Mainstay, but also some Macintosh support as well.

--------

[ 10/15 -- The folks at Mainstay tell me they started shipping last week, so we should have some copies for sale by the time you read this. The introductory price is $100. -- Bill ].


Apple Assembly Line is published monthly by S-C SOFTWARE CORPORATION, P.O. Box 280300, Dallas, Texas 75228. Phone (214) 324-2050. Subscription rate is $18 per year in the USA, sent Bulk Mail; add $3 for First Class postage in USA, Canada, and Mexico; add $12 postage for other countries. Back issues are available for $1.80 each (other countries add $1 per back issue for postage).

All material herein is copyrighted by S-C SOFTWARE, all rights reserved. Unless otherwise indicated, all material herein is authored by Bob Sander-Cederlof. (Apple is a registered trademark of Apple Computer, Inc.)