Skip to content

Commit

Permalink
build: v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestThePoet committed Mar 20, 2024
1 parent 4d67eb1 commit 447697a
Show file tree
Hide file tree
Showing 15 changed files with 4,037 additions and 106 deletions.

Large diffs are not rendered by default.

184 changes: 92 additions & 92 deletions docs/assets/index-21550645.js → docs/assets/index-74a2c48c.js

Large diffs are not rendered by default.

40 changes: 30 additions & 10 deletions docs/demos.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{
"name": "随机数生成器",
"irUrl": "demos/rand_sort/rand.ir",
"remark": "输入种子和正整数n,生成n个[0,32768)内的随机数。本虚拟机对全局变量的支持使得编写随机数生成器成为可能,许多示例都以这个随机数生成器为基础"
"remark": "输入种子和正整数n,生成n个[0,32768)内的随机数。本虚拟机对全局变量的支持使得编写随机数生成器成为可能。"
},
{
"name": "快速排序",
Expand Down Expand Up @@ -101,26 +101,46 @@
"name": "最小公倍数(LCM)",
"irUrl": "demos/arithmetic/lcm.ir",
"remark": "输入a和b,基于欧几里得GCD算法计算lcm(a,b)"
},
{
"name": "扩展欧几里得算法(EGCD)",
"irUrl": "demos/arithmetic/egcd.ir",
"remark": "输入a和b(a≥b>0),输出(d,X,Y)使得d=gcd(a,b)且Xa+Yb=d"
},
{
"name": "32位无符号整数的完整乘法结果",
"irUrl": "demos/arithmetic/mul_uint32.ir",
"remark": "输入32位有符号整数a和b,以32位无符号整数的形式解释它们并计算a*b,将64位结果的高32位和低32位以有符号数的形式解释并输出"
},
{
"name": "朴素算法素性检验",
"irUrl": "demos/arithmetic/naive-is-prime.ir",
"remark": "输入正整数w,使用朴素算法判断w是否是素数。如果w是素数,输出1;如果w是合数,输出0。"
},
{
"name": "Miller-Rabin素性检验",
"irUrl": "demos/arithmetic/miller-rabin.ir",
"remark": "输入正整数w,使用基于Miller-Rabin素性检验的算法判断w是否*可能*是素数。如果w可能是素数,输出1;如果w是合数,输出0。当w为素数且值达到5.5亿左右时,此算法对比朴素算法开始显示出执行步数上的优势;当w为合数时,此算法几乎总是非常快。"
}
]
},
{
"groupName": "游戏",
"groupName": "信息安全专区❤️",
"demos": [
{
"name": "猜数游戏",
"irUrl": "demos/games/guess_game.ir",
"remark": "输入一个随机数种子,然后猜测在[0,32768)内生成的数字。猜小了会输出-1,猜大了会输出1。猜对了会输出什么"
"name": "栈溢出攻击",
"irUrl": "demos/cyber_security/stack_overflow.ir",
"remark": "在这个虚拟机上也能进行栈溢出攻击吗"
}
]
},
{
"groupName": "信息安全专区❤️",
"groupName": "游戏",
"demos": [
{
"name": "栈溢出攻击",
"irUrl": "demos/cyber_security/stack_overflow.ir",
"remark": "在这个虚拟机上也能进行栈溢出攻击吗"
"name": "猜数游戏",
"irUrl": "demos/games/guess_game.ir",
"remark": "输入一个随机数种子,然后猜测在[0,32768)内生成的数字。猜小了会输出-1,猜大了会输出1。猜对了会输出什么"
}
]
},
Expand All @@ -135,7 +155,7 @@
{
"name": "Benchmark",
"irUrl": "demos/boring/benchmark.ir",
"remark": "性能测试,让虚拟机跑一会"
"remark": "性能测试,让虚拟机忙起来!"
}
]
}
Expand Down
52 changes: 52 additions & 0 deletions docs/demos/arithmetic/egcd.cmm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Calculates (d,X,Y) with d=gcd(a,b) and Xa+Yb=d
*/

int mod(int mod_x, int mod_y)
{
return mod_x - mod_y * (mod_x / mod_y);
}

int egcd(int egcd_out[3], int egcd_a, int egcd_b)
{
if (mod(egcd_a, egcd_b) == 0)
{
egcd_out[0] = egcd_b;
egcd_out[1] = 0;
egcd_out[2] = 1;
}
else
{
int egcd_q = egcd_a / egcd_b;
int egcd_r = egcd_a - egcd_q * egcd_b;
int egcd_dxy[3];

egcd(egcd_dxy, egcd_b, egcd_r);

egcd_out[0] = egcd_dxy[0];
egcd_out[1] = egcd_dxy[2];
egcd_out[2] = egcd_dxy[1] - egcd_dxy[2] * egcd_q;
}

return 0;
}

int main()
{
int a = read();
int b = read();
int dxy[3];

if (!(a >= b && b > 0))
{
return 1;
}

egcd(dxy, a, b);

write(dxy[0]);
write(dxy[1]);
write(dxy[2]);

return 0;
}
114 changes: 114 additions & 0 deletions docs/demos/arithmetic/egcd.ir
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
FUNCTION mod :
PARAM var0
PARAM var1
var2 := var0 / var1
var3 := var1 * var2
var4 := var0 - var3
RETURN var4
FUNCTION egcd :
PARAM var5
PARAM var6
PARAM var7
ARG var7
ARG var6
var8 := CALL mod
IF var8 == #0 GOTO label0
var9 := #0
GOTO label1
LABEL label0 :
var9 := #1
LABEL label1 :
IF var9 != #0 GOTO label2
var16 := var6 / var7
var18 := var16 * var7
var17 := var6 - var18
DEC var19 12
ARG var17
ARG var7
ARG &var19
CALL egcd
var20 := #4 * #0
var21 := var5 + var20
var22 := #4 * #0
var23 := &var19 + var22
*var21 := *var23
var24 := #4 * #1
var25 := var5 + var24
var26 := #4 * #2
var27 := &var19 + var26
*var25 := *var27
var28 := #4 * #2
var29 := var5 + var28
var30 := #4 * #1
var31 := &var19 + var30
var32 := #4 * #2
var33 := &var19 + var32
var34 := *var33 * var16
var35 := *var31 - var34
*var29 := var35
GOTO label3
LABEL label2 :
var10 := #4 * #0
var11 := var5 + var10
*var11 := var7
var12 := #4 * #1
var13 := var5 + var12
*var13 := #0
var14 := #4 * #2
var15 := var5 + var14
*var15 := #1
LABEL label3 :
RETURN #0
FUNCTION main :
READ var37
var36 := var37
READ var39
var38 := var39
DEC var40 12
IF var36 >= var38 GOTO label4
var41 := #0
GOTO label5
LABEL label4 :
var41 := #1
LABEL label5 :
IF var38 > #0 GOTO label6
var42 := #0
GOTO label7
LABEL label6 :
var42 := #1
LABEL label7 :
IF var41 != #0 GOTO label9
LABEL label10 :
var43 := #0
GOTO label11
LABEL label9 :
IF var42 != #0 GOTO label8
GOTO label10
LABEL label8 :
var43 := #1
LABEL label11 :
IF var43 != #0 GOTO label12
var44 := #1
GOTO label13
LABEL label12 :
var44 := #0
LABEL label13 :
IF var44 != #0 GOTO label14
GOTO label15
LABEL label14 :
RETURN #1
LABEL label15 :
ARG var38
ARG var36
ARG &var40
CALL egcd
var45 := #4 * #0
var46 := &var40 + var45
WRITE *var46
var47 := #4 * #1
var48 := &var40 + var47
WRITE *var48
var49 := #4 * #2
var50 := &var40 + var49
WRITE *var50
RETURN #0
Loading

0 comments on commit 447697a

Please sign in to comment.