斐波那契用于SIC / XE组装

时间:2015-10-22 23:22:54

标签: assembly

有人可以帮助解释以下代码。我试图在以下SIC / XE程序中添加注释,解释该程序如何计算前20个数字的斐波那契序列,从3开始。

FIB     START  0
First   LDT    #3       ;start at number 3
        LDS    #20      ;calculate up to 20
        +JSUB  RDREC        ;call read subroutine
        +JSUB  WRREC        ;call write subroutine
LENGTH  RESW   1
.
. SUBROUTINE RDREC
.
RDREC   CLEAR  A        ;set A to zero
LOOP1   TD     INPUT        ;Test input device
        JEQ    LOOP1        ;Loop if device is busy
        RD     INPUT        ;read one byte into register A
        COMPR  A,T      ;Test for end
        JLT    LOOP1        ;jump to loop until end
        COMPR  A,S      ;
        JGT    LOOP1
        STA    LENGTH
        RSUB
INPUT   BYTE   X'F1'
.
.SUBROUTINE WDREC
.
WRREC   LDX    #0
        LDS    #1
        LDA    #0
        LDT    LENGTH
LOOP2   TD     OUTPUT
        JEQ    LOOP2
        WD     OUTPUT
        ADDR   S,A
        STA    VALUE1
        STS    VALUE2
        LDA    VALUE2
        LDS    VALUE1
        TIXR   T 
        JLT    LOOP2
OUTPUT  BYTE   X'05'
VALUE1  RESW   1
VALUE2  RESW   1
        END    FIRST

0 个答案:

没有答案