0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

H27年春期 基本情報技術者 午後問12 解説

Last updated at Posted at 2016-03-26
MAIN    START
        LD     GR1,N          ; GR1 ← n
        LAD    GR0,F          ; GR0 ← F(n)のアドレス
        CALL   FACT
        RET
N       DC     5
F       DS     1
      
FACT    START
        RPUSH
        LD     GR0,=1
        SUBL   GR1,=1
        JPL    NEXT
        JUMP   FIN
NEXT    LD     GR2,=1
LP      LAD    GR2,1,GR2
        CALL   MULT
        SUBL   GR1,=1
        JNZ    LP
FIN     RPOP
        RET

MULT    START            ; シフトによる乗算(GR0=GR0xGR2)
        RPUSH
        LD     GR1,GR0   ; 被乗数を GR1 に保持
        LD     GR0,=0    ; 乗算結果の初期化

        LD     GR3,=15
        LD     GR2,GR2
LP2     JZE    FIN2
        JPL    CONT
        LD     GR4,GR1
        SLL    GR4,0,GR3
        ADDL   GR0,GR4
CONT    LAD    GR3,-1,GR3
        SLL    GR2,1
        JUMP   LP2
FIN2    RPOP
        RET
        END

n=5
GR0=F(5)=5!=120=0x78

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?