プログラム支援室 A0
CPU8A プログラミング
拡張レジスタ

はじめに

CPU8Aのプログラミングは 「プログラム支援室A」 にあります。 プロセッサの8桁レジスタを使ってのプログラムでは レジスタの桁数と個数が少ないのでレジスタとメモリ 間の転送を数多く行うためプログラムが複雑になりま す。
CPU8Aは最小の汎用プロセッサを目指したものですの でプロセッサにこれ以上の拡張はせず、性能の向上も 求めないで使い勝手だけ良くします。

使い勝手を良くするためにメモリに桁数の多いレジス タを必要分確保します。

これらのメモリに拡張した仮想のレジスタをプロセッ サ本来のレジスタと同じように使うためにはマクロを 増やすだけで済みます。


; ------------------------------------------
;    メモリ上の拡張2進数16桁仮想レジスタ
; ------------------------------------------
const _ER   = DR0,DR1,DR2,DR3,DR4,DR5,DR6,DR7,DR8

; ------------------------------------------
;    メモリ位置
; ------------------------------------------
MBE      EQU       10H

; ------------------------------------------
;    MOVR
; ------------------------------------------
MACRO MOVR _ER,_ER
         MOVX      #1*2+MBE
         MOVY      #0*2+MBE
         MOVMR     R0,IX
         MOVRM     IY,R0
         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVRM     IY,R0
ENDM

上はメモリ番地10Hから16桁のレジスタを8個確保して レジスタ間の転送命令 MOVR を追加した部分です。

これで    MOVR   DR0,DR1    などの命令が使えるようになります。

注意点は仮想レジスタを操作する命令では実レジスタ が使われているのでレジスタ値や状態値が命令の前後 で変わります。

実レジスタを保存するようにマクロを書くこともでき ますが、マクロを大きくすると実行速度も遅くなりま すから、保存が必要な値は実レジスタに置かず仮想レ ジスタに置く方が良いでしょう仮想レジスタを増やす 方が効果的と思います。

仮想8桁レジスタ操作命令
命令名 書式 状態値 機能
C Z
MOVR MOVR   BRA,BRB

BRA=BRB
MOVI MOVR   BRA,imm8

BRA=imm8
ADD ADD   BRA,BRB BRA=BRA+BRB
SUB SUB   BRA,BRB BRA=BRA-BRB
ADDC ADDC   BRA,BRB BRA=BRA+BRB+C
SUBC SUBC   BRA,BRB BRA=BRA-BRB-C
SHU SHU   BRA,BRB
C=BRA .7, BRA .1:7=BRB .0:6, BRA .0=0
SHD SHD   BRA,BRB
C=BRA .0, BRA .0:6=BRB .1:7, BRA .7=0
ROU ROU   BRA,BRB
C=BRA .7, BRA .1:7=BRB .0:6, BRA .0=C
ROD ROD   BRA,BRB
C=BRA .0, BRA .0:6=BRB .1:7, BRA .7=C
CMP CMP   BRA,BRB BRA-BRBの結果を状態値に反映
AND AND   BRA,BRB
DRA = BRA & BRB
OR OR   BRA,BRB
BRA = BRA | BRB
XOR XOR   BRA,BRB
BRA = BRA ^ BRB
NOT NOT   BRA,BRB
BRA = !BRB
INC INC   BRA

BRA = BRA + 1
DEC DEC   BRA

BRA = BRA - 1
MOVRM MOVRM   (DRA),BRB

(DRA) = BRB
MOVMR MOVMR   DRA,(BRB)

BRA = (DRB)
MUL MUL   BRA,BRB

BRB,BRA = BRA * BRB
DIV DIV   BRA,BRB

BRA = BRA / BRB
BRB = 余り

  • BRA, BRB は BR0 〜 BR15 です。
  • DRA, DRB は DR0 〜 DR7 です。
  • imm8 は2進数8桁の 即値 です。
  • (BRA)と(BRB)はレジスタ値を番地としたメモリを 示します。


仮想16桁レジスタ操作命令
命令名 書式 状態値 機能
C Z
MOVR MOVR   DRA,DRB

DRA=DRB
MOVI MOVR   DRA,imm16

DRA=imm16
ADD ADD   DRA,DRB DRA=DRA+DRB
SUB SUB   DRA,DRB DRA=DRA-DRB
ADDC ADDC   DRA,DRB DRA=DRA+DRB+C
SUBC SUBC   DRA,DRB DRA=DRA-DRB-C
SHU SHU   DRA,DRB
C=DRA .7, DRA .1:7=DRB .0:6, DRA .0=0
SHD SHD   DRA,DRB
C=DRA .0, DRA .0:6=DRB .1:7, DRA .7=0
ROU ROU   DRA,DRB
C=DRA .7, DRA .1:7=DRB .0:6, DRA .0=C
ROD ROD   DRA,DRB
C=DRA .0, DRA .0:6=DRB .1:7, DRA .7=C
CMP CMP   DRA,DRB DRA-DRBの結果を状態値に反映
AND AND   DRA,DRB
DRA = DRA & DRB
OR OR   DRA,DRB
DRA = DRA | DRB
XOR XOR   DRA,DRB
DRA = DRA ^ DRB
NOT NOT   DRA,DRB
DRA = !DRB
INC INC   DRA

DRA = DRA + 1
DEC DEC   DRA

DRA = DRA - 1
MOVRM MOVRM   (DRA),DRB

(DRA) = DRB
MOVMR MOVMR   DRA,(DRB)

DRA = (DRB)

  • DRA, DRB は DR0 〜 DR7 です。
  • imm16 は2進数16桁の 即値 です。
  • (DRA)と(DRB)はレジスタ値を番地としたメモリを 示します。



  • 2進数16桁の乗算    


2進数16桁の乗算

拡張レジスタだけを使った2進数16桁の乗算プログラ ムです。 結果は2進数32桁になります。

; ================================================
;    2進数16桁乗算
; ================================================
         ORG       0
         JMP       E0

         org       100H
E0:
         MOVI      DR0,1234H   ; 被乗数
         MOVI      DR1,5678H   ; 乗数 0
         MOVI      DR2,0       ; 乗数 1
         MOVI      DR3,1       ; 行程
         MOVI      DR4,0       ; 結果 0
         MOVI      DR5,0       ; 結果 1

         MOVR      DR6,DR0
X0:
         AND       DR0,DR3
         JMPZ      X1          ; 加算なし
         ADD       DR4,DR1
         ADDC      DR5,DR2
X1:
         SHU       DR1,DR1
         ROU       DR2,DR2     ; 乗数上桁移動
         SHU       DR3,DR3     ; 行程上桁移動
         JMPC      X2
         MOVR      DR0,DR6
         JMP       X0
X2:
         
         NOP
         NOP
END



CPU8A .MAC 抜粋
; ============================================================================
;        2進数8桁レジスタ 拡張命令
; ============================================================================
MBEB     EQU       10H
; ----------------------------------------------------------------------------
;    MOVR
; ----------------------------------------------------------------------------
MACRO MOVR _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IY
         MOVRM     IX,R0
ENDM
; ----------------------------------------------------------------------------
;    MOVI
; ----------------------------------------------------------------------------
MACRO MOVI _EBR,NUMBER
         MOVX      #0+MBEB
         MOVI      R0,NUMBER
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    ADD
; ----------------------------------------------------------------------------
MACRO ADD _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADD       R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    SUB
; ----------------------------------------------------------------------------
MACRO SUB _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         SUB       R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    ADDC
; ----------------------------------------------------------------------------
MACRO ADDC _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADDC      R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    SUBC
; ----------------------------------------------------------------------------
MACRO SUBC _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         SUBC      R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    SHU
; ----------------------------------------------------------------------------
MACRO SHU _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         SHU       R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    SHD
; ----------------------------------------------------------------------------
MACRO SHD _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         SHD       R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    ROU
; ----------------------------------------------------------------------------
MACRO ROU _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         ROU       R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    ROD
; ----------------------------------------------------------------------------
MACRO ROD _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         ROD       R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    CMP
; ----------------------------------------------------------------------------
MACRO CMP _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         CMP
ENDM

; ----------------------------------------------------------------------------
;    AND
; ----------------------------------------------------------------------------
MACRO AND _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         AND       R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    OR
; ----------------------------------------------------------------------------
MACRO OR _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         OR        R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    XOR
; ----------------------------------------------------------------------------
MACRO XOR _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         XOR       R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    NOT
; ----------------------------------------------------------------------------
MACRO NOT _EBR,_EBR
         MOVX      #0+MBEB
         MOVY      #1+MBEB
         MOVMR     R0,IX
         MOVMR     R1,IY
         NOT       R0,R1
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    INC
; ----------------------------------------------------------------------------
MACRO INC _EBR
         MOVX      #0+MBEB
         MOVMR     R0,IX
         INC       R0
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    DEC
; ----------------------------------------------------------------------------
MACRO DEC _EBR
         MOVX      #0+MBEB
         MOVMR     R0,IX
         DEC       R0
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    MOVRM
; ----------------------------------------------------------------------------
MACRO MOVRM (_ER),_EBR
         MOVX      #0*2+MBE
         MOVY      #1+MBEB
         MOVMR     R0,IX
         INC       IX
         MOVMR     R1,IX
         MOVRX     RP0
         MOVMR     R0,IY
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    MOVMR
; ----------------------------------------------------------------------------
MACRO MOVMR _EBR,(_ER)
         MOVX      #0+MBEB
         MOVY      #1*2+MBE
         MOVMR     R0,IY
         INC       IY
         MOVMR     R1,IY
         MOVRY     RP0
         MOVMR     R0,IY
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    MUL
;    WORK0    行程
;        1,2  加算
;        3,4  累積
; ----------------------------------------------------------------------------
MACRO MUL _EBR,_EBR

         MOVX      WORK
         MOVI      R0,1
         MOVRM     IX,R0   ; 行程初期化

         MOVX      WORK+1
         MOVY      #1+MBEB
         MOVMR     R0,IY
         MOVRM     IX,R0
         INC       IX
         XOR       R0,R0
         MOVRM     IX,R0   ; 加算に乗数を設置

         MOVX      WORK+3
         MOVRM     IX,R0
         INC       IX
         MOVRM     IX,R0   ; 累積を初期化

MULB_X0: MOVX      #0+MBEB
         MOVMR     R0,IX
         MOVX      WORK
         MOVMR     R1,IX
         AND       R0,R1
         JMPZ      MULB_X1 ; 加算なし

         MOVX      WORK+1
         MOVY      WORK+3
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADD       R0,R1
         MOVRM     IY,R0
         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADDC
         MOVRM     IY,R0   ; 累積

MULB_X1: MOVX      WORK+1
         MOVMR     R0,IX
         SHU       R0,R0
         MOVRM     IX,R0
         INC       IX
         MOVMR     R0,IX
         ROU
         MOVRM     IX,R0   ; 加算上移動

         MOVX      WORK
         MOVMR     R0,IX
         SHU       R0,R0
         MOVRM     IX,R0
         JMPC      MULB_X2 ; 終わり
         JMP       MULB_X0 ; 戻る

MULB_X2: MOVX      #0+MBEB
         MOVY      WORK+3
         MOVMR     R0,IY
         MOVRM     IX,R0
         MOVX      #1+MBEB
         INC       IY
         MOVMR     R0,IY
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    DIV
;    WORK0    行程
;        1,2  被除数移動
;        3    結果
; ----------------------------------------------------------------------------
MACRO DIV _EBR,_EBR
         MOVY      #1+MBEB

         MOVX      WORK
         MOVI      R0,1
         MOVRM     IX,R0   ; 行程初期化

         MOVX      WORK+3
         XOR       R0,R0
         MOVRM     IX,R0   ; 結果初期化

         MOVX      #0+MBEB
         MOVMR     R0,IX
         MOVX      WORK+1
         MOVRM     IX,R0
         INC       IX
         XOR       R0,R0
         MOVRM     IX,R0   ; 被除数設置

DIVB_X0:
         MOVX      WORK+1
         MOVMR     R0,IX
         SHU       R0,R0
         MOVRM     IX,R0
         INC       IX
         MOVMR     R0,IX
         ROU
         MOVRM     IX,R0   ; 被除数上桁移動

         MOVMR     R0,IX
         MOVMR     R1,IY
         CMP
         JMPC      DIVB_X1 ; 減算なし
         
         SUB       R0,R1
         MOVRM     IX,R0   ; 減算

         MOVX      WORK+3
         MOVMR     R0,IX
         SHU       R0,R0
         MOVI      R1,1
         OR        R0,R1
         MOVRM     IX,R0   ; 結果処理

         JMP       DIVB_X2 ; 次行程

         MOVX      WORK+1
         MOVMR     R0,IX
         JMP       DIVB_X0

DIVB_X1:
         MOVX      WORK+3
         MOVMR     R0,IX
         SHU       R0,R0
         MOVRM     IX,R0
DIVB_X2:
         MOVX      WORK
         MOVMR     R0,IX
         SHU       R0,R0
         MOVRM     IX,R0
         JMPC      DIVB_X3 ; 終了

         JMP       DIVB_X0 ; 戻る

DIVB_X3:
         MOVX      WORK+3
         MOVMR     R0,IX
         MOVX      #0+MBEB
         MOVRM     IX,R0

         MOVX      WORK+2
         MOVMR     R0,IX
         MOVX      #1+MBEB
         MOVRM     IX,R0
ENDM

; ============================================================================
;        2進数16桁レジスタ 拡張命令
; ============================================================================
MBE      EQU       MBEB+16
WORK     EQU       MBE+16
; ----------------------------------------------------------------------------
;    DEC
; ----------------------------------------------------------------------------
MACRO DEC _ER
         MOVX      #0*2+MBE
         MOVMR     R0,IX
         MOVI      R1,1
         SUB       R0,R1
         MOVRM     IX,R0
         INC       IX
         MOVMR     R0,IX
         MOVI      R1,0
         SUBC
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    INC
; ----------------------------------------------------------------------------
MACRO INC _ER
         MOVX      #0*2+MBE
         MOVMR     R0,IX
         MOVI      R1,1
         ADD       R0,R1
         MOVRM     IX,R0
         INC       IX
         MOVMR     R0,IX
         MOVI      R1,0
         ADDC
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    MOVMR
; ----------------------------------------------------------------------------
MACRO MOVMR _ER,(_ER)
         MOVX      #1*2+MBE
         MOVMR     R0,IX
         INC       IX
         MOVMR     R1,IX
         MOVRY     RP0
         MOVX      #0*2+MBE
         MOVMR     R0,IY
         MOVRM     IX,R0
         INC       IX
         INC       IY
         MOVMR     R0,IY
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    MOVRM
; ----------------------------------------------------------------------------
MACRO MOVRM (_ER),_ER
         MOVX      #0*2+MBE
         MOVMR     R0,IX
         INC       IX
         MOVMR     R1,IX
         MOVRX     RP0
         MOVY      #1*2+MBE
         MOVMR     R0,IY
         MOVRM     IX,R0
         INC       IX
         INC       IY
         MOVMR     R0,IY
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    NOT
; ----------------------------------------------------------------------------
MACRO NOT _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IX
         MOVMR     R1,IY
         NOT       R0,R1
         MOVRM     IX,R0
         INC       IX
         INC       IY

         LDSR
         MOVR      R2,R0

         MOVMR     R0,IX
         MOVMR     R1,IY
         NOT       R0,R1
         MOVRM     IX,R0

         LDSR
         AND       R0,R2
         PUSH      R0
         POP       SR
ENDM

; ----------------------------------------------------------------------------
;    XOR
; ----------------------------------------------------------------------------
MACRO XOR  _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IX
         MOVMR     R1,IY
         XOR       R0,R1
         MOVRM     IX,R0
         INC       IX
         INC       IY

         LDSR
         MOVR      R2,R0

         MOVMR     R0,IX
         MOVMR     R1,IY
         XOR       R0,R1
         MOVRM     IX,R0

         LDSR
         AND       R0,R2
         PUSH      R0
         POP       SR
ENDM

; ----------------------------------------------------------------------------
;    OR 
; ----------------------------------------------------------------------------
MACRO OR  _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IX
         MOVMR     R1,IY
         OR        R0,R1
         MOVRM     IX,R0
         INC       IX
         INC       IY

         LDSR
         MOVR      R2,R0

         MOVMR     R0,IX
         MOVMR     R1,IY
         OR        R0,R1
         MOVRM     IX,R0

         LDSR
         AND       R0,R2
         PUSH      R0
         POP       SR
ENDM

; ----------------------------------------------------------------------------
;    AND
; ----------------------------------------------------------------------------
MACRO AND _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IX
         MOVMR     R1,IY
         AND       R0,R1
         MOVRM     IX,R0
         INC       IX
         INC       IY

         LDSR
         MOVR      R2,R0

         MOVMR     R0,IX
         MOVMR     R1,IY
         AND       R0,R1
         MOVRM     IX,R0

         LDSR
         AND       R0,R2
         PUSH      R0
         POP       SR
ENDM

; ----------------------------------------------------------------------------
;    ROD
; ----------------------------------------------------------------------------
MACRO ROD _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IY
         ROD
         MOVRM     IX,R0
         INC       IX
         INC       IY
         MOVMR     R0,IY
         ROD
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    SHD
; ----------------------------------------------------------------------------
MACRO SHD _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IY
         SHD       R0,R0
         MOVRM     IX,R0
         INC       IX
         INC       IY
         MOVMR     R0,IY
         ROD
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    CMP
; ----------------------------------------------------------------------------
MACRO CMP _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IX
         MOVMR     R1,IY
         SUB       R0,R1
         INC       IX
         INC       IY

         LDSR
         MOVI      R1,80H
         OR        R0,R1
         MOVR      R2,R0

         MOVMR     R0,IX
         MOVMR     R1,IY
         SUBC

         LDSR
         AND       R0,R2
         PUSH      R0
         POP       SR
ENDM

; ----------------------------------------------------------------------------
;    ROU
; ----------------------------------------------------------------------------
MACRO ROU _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IY
         ROU
         MOVRM     IX,R0
         INC       IX
         INC       IY
         MOVMR     R0,IY
         ROU
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    SHU
; ----------------------------------------------------------------------------
MACRO SHU _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IY
         SHU       R0,R0
         MOVRM     IX,R0
         INC       IX
         INC       IY
         MOVMR     R0,IY
         ROU
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    SUBC
; ----------------------------------------------------------------------------
MACRO SUBC _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IX
         MOVMR     R1,IY
         SUBC
         MOVRM     IX,R0

         LDSR
         MOVI      R1,80H
         OR        R0,R1
         MOVR      R2,R0

         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVMR     R1,IY
         SUBC
         MOVRM     IX,R0

         LDSR
         AND       R0,R2
         PUSH      R0
         POP       SR
ENDM

; ----------------------------------------------------------------------------
;    SUB
; ----------------------------------------------------------------------------
MACRO SUB _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IX
         MOVMR     R1,IY
         SUB       R0,R1
         MOVRM     IX,R0

         LDSR
         MOVI      R1,80H
         OR        R0,R1
         MOVR      R2,R0

         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVMR     R1,IY
         SUBC
         MOVRM     IX,R0

         LDSR
         AND       R0,R2
         PUSH      R0
         POP       SR
ENDM

; ----------------------------------------------------------------------------
;    MOVR
; ----------------------------------------------------------------------------
MACRO MOVR _ER,_ER
         MOVX      #1*2+MBE
         MOVY      #0*2+MBE
         MOVMR     R0,IX
         MOVRM     IY,R0
         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVRM     IY,R0
ENDM

; ----------------------------------------------------------------------------
;    MOVI
; ----------------------------------------------------------------------------
MACRO MOVI _ER,NUMBER
         MOVX      #0*2+MBE
         MOVI      R0,#1&0FFH
         MOVRM     IX,R0
         INC       IX
         MOVI      R0,(#1>>8)&0FFH
         MOVRM     IX,R0
ENDM

; ----------------------------------------------------------------------------
;    ADD
; ----------------------------------------------------------------------------
MACRO ADD _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADD       R0,R1
         MOVRM     IX,R0

         LDSR
         MOVI      R1,80H
         OR        R0,R1
         MOVR      R2,R0

         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADDC
         MOVRM     IX,R0

         LDSR
         AND       R0,R2
         PUSH      R0
         POP       SR
ENDM

; ----------------------------------------------------------------------------
;    ADDC
; ----------------------------------------------------------------------------
MACRO ADDC _ER,_ER
         MOVX      #0*2+MBE
         MOVY      #1*2+MBE
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADDC
         MOVRM     IX,R0

         LDSR
         MOVI      R1,80H
         OR        R0,R1
         MOVR      R2,R0

         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADDC
         MOVRM     IX,R0

         LDSR
         AND       R0,R2
         PUSH      R0
         POP       SR
ENDM

; ----------------------------------------------------------------------------
;    MUL
;    行程   WORK 0 - 1
;    累積   WORK 2 - 5
;    加数   WORK 6 - 9
; ----------------------------------------------------------------------------
MACRO MUL _ER,_ER
         MOVX      WORK
         MOVI      R0,1
         MOVRM     IX,R0   ; No.0
         INC       IX
         XOR       R0,R0
         MOVRM     IX,R0   ; No.1 行程初期化

         MOVX      WORK+2
         MOVRM     IX,R0   ; No.0
         INC       IX
         MOVRM     IX,R0   ; No.1
         INC       IX
         MOVRM     IX,R0   ; No.2
         INC       IX
         MOVRM     IX,R0   ; No.3 累積初期化

         MOVX      #1*2+MBE
         MOVY      WORK+6
         MOVMR     R0,IX
         MOVRM     IY,R0   ; No.0
         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVRM     IY,R0   ; No.1
         INC       IY
         XOR       R0,R0
         MOVRM     IY,R0   ; No.2
         INC       IY
         MOVRM     IY,R0   ; No.3 乗数設置
MUL_X0:
         MOVX      WORK
         MOVY      #0*2+MBE
         MOVMR     R0,IX
         MOVMR     R1,IY
         AND       R0,R1
         JMPZ      MUL_X1
         JMP       MUL_X2  ; 加算
MUL_X1:
         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVMR     R1,IY
         AND       R0,R1
         JMPZ      MUL_X3  ; 行程増
MUL_X2:
         MOVX      WORK+2
         MOVY      WORK+6
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADD       R0,R1
         MOVRM     IX,R0   ; No.0
         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADDC      R0,R1
         MOVRM     IX,R0   ; No.1
         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADDC      R0,R1
         MOVRM     IX,R0   ; No.2
         INC       IX
         INC       IY
         MOVMR     R0,IX
         MOVMR     R1,IY
         ADDC      R0,R1
         MOVRM     IX,R0   ; NO.3 累積加算
MUL_X3:
         MOVX      WORK
         MOVMR     R0,IX
         SHU       R0,R0
         MOVRM     IX,R0   ; No.0
         INC       IX
         MOVMR     R0,IX
         ROU       R0,R0
         MOVRM     IX,R0   ; No.1 行程
         JMPC      MUL_X4  ; 終了
         JMP       MUL_X0  ; 戻る
MUL_X4:
         MOVX      #0*2+MBE
         MOVY      WORK+2
         MOVMR     R0,IY
         MOVRM     IX,R0   ; No.0
         INC       IX
         INC       IY
         MOVMR     R0,IY
         MOVRM     IX,R0   ; No.1
         
         MOVX      #1*2+MBE
         INC       IY
         MOVMR     R0,IY
         MOVRM     IX,R0   ; No.2
         INC       IX
         INC       IY
         MOVMR     R0,IY
         MOVRM     IX,R0   ; No.3
ENDM




先頭