Skip to content

Instantly share code, notes, and snippets.

@shotarok
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shotarok/4fb46422ddd1b3f95b94 to your computer and use it in GitHub Desktop.
Save shotarok/4fb46422ddd1b3f95b94 to your computer and use it in GitHub Desktop.
Arith.gcc
LDC 8 ; now
LDC 3 ; A
LDC 5 ; B
LDC 13 ; M
LDF LCGs
AP 4
LDC 3 ; A
LDC 5 ; B
LDC 13 ; M
LDF LCGs
AP 4
LDC 3 ; A
LDC 5 ; B
LDC 13 ; M
LDF LCGs
AP 4
RTN
LCGs:
LD 0 0 ; load now from env
LD 0 1 ; load A from env
MUL
LD 0 2 ; load B from env
ADD
LD 0 3 ; load M from env
LDF mod
AP 2
RTN
mod:
LD 0 0 ; mod fucntion
LD 0 0
LD 0 1
DIV
LD 0 1
MUL
SUB
RTN
; 線形合同法 Linear congruential generators(LCGs)
;; next = LCGs(now, A, B, M){ return (A * now + B) mod M; }
LDC 10 ; a
LDC 3 ; b
LDF 6 ; load mod
AP 2 ; call mod(a, b)
DBUG
RTN
LD 0 0 ; mod fucntion
LD 0 0
LD 0 1
DIV
LD 0 1
MUL
SUB
RTN
@shotarok
Copy link
Author

mod の ラベル付きバーションはこちら

LDC 7 ; a = 7
LDC 5 ; b = 5
LDF mod
AP 2
DBUG
RTN
mod:
LD 0 0 ; mod fucntion
LD 0 0
LD 0 1
DIV
LD 0 1
MUL
SUB
RTN

これを レポジトリにある deref.cpp を使えばコンパイルできる

g++ deref.cpp -o deref
./deref < labeled.gcc > unlabeled.gcc

@shotarok
Copy link
Author

deref.cpp は現在のバージョンだと、先頭にコメントをつけると行数がずれる

@shotarok
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment