Jump to content





Diamond MULTIPLY(39) Macro

Posted by kPack, 24 June 2018 · 70 views

Diamond Multiply

The MULTIPLY function for Diamond GOS is stated as:
 
MULTIPLY (39) - Word sized multiply(please note overflow error are not detected)
   Receives:
     W5 - Multiplicand 1
     W6 - Multiplicand 2
   Returns:
      W7 - Result
 
As with the DIVIDE macro,  the original macro received the numbers when calling it.  It was changed to accept an address of the numbers and the numbers are then copied into W5 and W6.
 
Original macro
8500 ;
8510     .MACRO MULTIPLY
8520     LDA # <%1   ;MULTIPLICAND 1
8530     STA W5
8540     LDA # >%1
8550     STA W5+1
8560     LDA # <%2   ;MULTIPLICAND 2
8570     STA W6
8580     LDA # >%2
8590     STA W6+1
8600     LDA #MULTIPLY
8610     JSR DIAMOND
8620     .ENDM
8630 ;
 
Modified macro
8500 ;
8505 ;MODIFIED TO LOAD NUM FROM ADDR.
8506 ;KPACK - 5/16/2018
8510     .MACRO MULTIPLY
8520     LDA %1      ;MULTIPLICAND 1
8530     STA W5
8540     LDA %1+1
8550     STA W5+1
8560     LDA %2      ;MULTIPLICAND 2
8570     STA W6
8580     LDA %2+1
8590     STA W6+1
8600     LDA #MULTIPLY
8610     JSR DIAMOND
8620     .ENDM
8630 ;
 
The test program:
10 ;THIS PROGRAM IS TO TEST CHANGES
20 ;TO THE DIAMOND MULTIPLY MACRO
30 ;
40 ;MACRO  NOW LOAD NUMBERS AT ADDR
50 ;  -NOT NUMBERS
60 ;DOUBLE BYTE MATH ON TWO NUMBERS.
70 ;RESULTS PRINTED IN HEX.
80 ;
90 ;
95       .OPT NO LIST
96       .OPT OBJ
0100     *=  $2200
0110     .INCLUDE #D2:DMACRO01.M65
0120 ;
0130 NUM01 .WORD 1211
0140 NUM02 .WORD 37
0150 MULRST .WORD 0  ; MUL RESULTS
0180 DVAR .WORD 0
0190 HEXSTG .BYTE "$    ",255
0200 HEXCHR .BYTE $30,$31,$32,$33,$34
0210     .BYTE $35,$36,$37,$38,$39
0220     .BYTE $41,$42,$43,$44,$45
0230     .BYTE $46
0240 ;
0250 START  INIT  0
0260      MULTIPLY  NUM01,NUM02
0270     LDA W7      ;STORE RESULTS
0280     STA MULRST
0290     LDA W7+1
0300     STA MULRST+1
0400     LDA NUM01   ;LOAD NUM TO CONVERT
0410     STA DVAR
0420     LDA NUM01+1
0430     STA DVAR+1
0440     JSR DB2HEX
0450      SYSDRAW  HEXSTG,10,20,0
0460     LDA NUM02   ;LOAD NUM TO CONVERT
0470     STA DVAR
0480     LDA NUM02+1
0490     STA DVAR+1
0500     JSR DB2HEX
0510      SYSDRAW  HEXSTG,10,30,0
0520     LDA MULRST  ;LOAD NUM TO CONVERT
0530     STA DVAR
0540     LDA MULRST+1
0550     STA DVAR+1
0560     JSR DB2HEX
0570      SYSDRAW  HEXSTG,10,40,0
0691 LOOP  EVENT 
0692     LDA EVENTTYPE
0693     BEQ LOOP
0694      EXIT       ;DIAMOND
0695      EXECDESKTOP 
0696 ;
0700 ;
0710 ;CONVERT HEX TO STRING
0720 DB2HEX LDA DVAR
0730     AND #$0F
0740     TAX
0750     LDA HEXCHR,X
0760     STA HEXSTG+4
0770     LSR DVAR
0780     LSR DVAR
0790     LSR DVAR
0800     LSR DVAR
0810     LDX DVAR
0820     LDA HEXCHR,X
0830     STA HEXSTG+3
0840     LDA DVAR+1
0850     AND #$0F
0860     TAX
0870     LDA HEXCHR,X
0880     STA HEXSTG+2
0890     LSR DVAR+1
0900     LSR DVAR+1
0910     LSR DVAR+1
0930     LSR DVAR+1
0935     LDX DVAR+1
0940     LDA HEXCHR,X
0950     STA HEXSTG+1
0960     RTS
0970 ;
0980     *=  $02E0
0990     .WORD START
 
My test results are as follows: 
 
TEST#   NUM01 * NUM02 = Result   Correct
   1         $0B44       $0025      $2F07    $AF07
   2         $FFF6        $0025      $7E8E
   3         $1FFF        $0004      $7FFC
   4         $1FFF        $0005      $9FFB
   5         $0004       $1FFF       $7FFC
   6         $0005       $1FFF       $9FFB
   7         $00FF       $00FF       $FE01
   8         $FFFF        $0001      $7FFFF   $FFFF
   9         $0001       $04BB      $04BB
  10        $0001       $FFFF          ----      CRASH
 
Every time I look at this list, I see numbers I should have tried.  I just got tired of trying.  There seems to be a problem when the result is above $7FFF but not always(#4).  Switching the numbers can have unexpected results(#8 and #10).  Zero should have been tested.
 
The only recommendations I will make at this time is to  know the limits of the numbers you will be using in your program and test them using the macro call. 
 
Now, I'm hoping I will remember that I wrote those words of wisdom the next time I have the need to call Diamond's MULTIPLY macro.
 

Attached Files






July 2018

S M T W T F S
1234567
891011121314
1516 17 18192021
22232425262728
293031    

My Picture

Latest Visitors