求LC-2K汇编语言(Assembly Language)的算组合数C(n,r)的代码.已经写出,但步骤太多,望高手帮优化一要求使用遗传算法:your assembly-language program will followthis logic closely.int combination(int n,int r){if (r

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 23:04:31
求LC-2K汇编语言(AssemblyLanguage)的算组合数C(n,r)的代码.已经写出,但步骤太多,望高手帮优化一要求使用遗传算法:yourassembly-languageprogramwi

求LC-2K汇编语言(Assembly Language)的算组合数C(n,r)的代码.已经写出,但步骤太多,望高手帮优化一要求使用遗传算法:your assembly-language program will followthis logic closely.int combination(int n,int r){if (r
求LC-2K汇编语言(Assembly Language)的算组合数C(n,r)的代码.已经写出,但步骤太多,望高手帮优化一
要求使用遗传算法:
your assembly-language program will follow
this logic closely.
int combination(int n,int r)
{
if (r==0 || n==r) {
return(1);
} else {
return(combination(n-1,r) + combination(n-1,r-1));
}
}
LC-2K汇编代码如下:
lw 0 1 n
lw 0 2 r
lw 0 6 combAd
jalr 6 7
halt
comb lw 0 6 num1
sw 5 7 stack
add 5 6 5
sw 5 1 stack
add 5 6 5
sw 5 2 stack
add 5 6 5
sw 5 4 stack
add 5 6 5
beq 2 0 rat
beq 1 2 rat
lw 0 6 neg1
add 1 6 1
lw 0 6 combAd
jalr 6 7
add 0 3 4
lw 0 6 neg1
add 2 6 2
lw 0 6 combAd
jalr 6 7
add 4 3 3
beq 0 0 ret
rat add 0 6 3
ret lw 0 6 neg1
add 5 6 5
lw 5 4 stack
add 5 6 5
lw 5 2 stack
add 5 6 5
lw 5 1 stack
add 5 6 5
lw 5 7 stack
jalr 7 6
n .fill 7
r .fill 4
num1 .fill 1
neg1 .fill -1
combAd .fill comb

求LC-2K汇编语言(Assembly Language)的算组合数C(n,r)的代码.已经写出,但步骤太多,望高手帮优化一要求使用遗传算法:your assembly-language program will followthis logic closely.int combination(int n,int r){if (r
我是丁老师,a.k.a.Robert Dick.
Hopefully you can optimize the code all by yourself.You know,this is a very important procedure for a coder to optimize the code to work well.
Good luck!