无锡网站建设哪家做,seo技巧分享,做100个网站效果图,下载吧网站整站源码week03 一、main参数传递二、反汇编三、汇编混合编程 一、main参数传递 参考 http://www.cnblogs.com/rocedu/p/6766748.html#SECCLA 在Linux下完成“求命令行传入整数参数的和” 注意C中main: int main(int argc, char *argv[]), 字符串“12” 转为12#xff0c;可以调用atoi… week03 一、main参数传递二、反汇编三、汇编混合编程 一、main参数传递 参考 http://www.cnblogs.com/rocedu/p/6766748.html#SECCLA 在Linux下完成“求命令行传入整数参数的和” 注意C中main: int main(int argc, char *argv[]), 字符串“12” 转为12可以调用atoi() 求和函数 int sum(int N)放入sum.c中, main中调用sum()main放入main.c中 测试代码传入自己的8位学号 提交代码 附件提交运行测试截图 // main.c:#includestdio.h
#includestdlib.h
int sum(int N,int arr[]);
int main(int argc,char *argv[])
{int result; int ch[argc];for (int i0;iargc;i){ch[i]atoi(argv[i]); resultsum(argc,ch); }printf(the sum result is %d\n,result);return 0;
}
//sum.c:int sum (int N,int arr[])
{int a0;for(int i0;iN;i){aarr[i];}return a;
}创建两个文件 一起编译然后运行
gcc main.c sum.c -o 20232831./20232831 2 0 2 3 2 8 3 1 #即计算2 0 2 3 2 8 3 1 的和需要用空格分开 二、反汇编
编辑、编译、运行附图中代码 上方提交代码 附件提交运行结果截图 代码如下
#includestdio.h
int main(void)
{int input,output,temp;input1;__asm__ __volatile__ (movl $0,%%eax;\n\tmovl %%eax,%1;\n\tmovl %2,%%eax;\n\tmovl %%eax,%0;\n\t:m(output),m(temp):r(input):eax);printf(%d %d\n,temp,output);return 0;
}三、汇编混合编程 用objdum -d sum.o反汇编sum.o 在main.c中通过汇编调用sum 上方提交C混合汇编代码 附件提交编译运行结果 sum.c和main.c代码如下
//sum.c
int sum (int N,int arr[])
{int a0;for(int i0;iN;i){aarr[i];}return a;
}
//main.c
#includestdio.h
#includestdlib.h
int sum(int N,int arr[]);
int main(int argc,char *argv[])
{int result; int ch[argc];for (int i0;iargc;i){ch[i]atoi(argv[i]); resultsum(argc,ch); }printf(the sum result is %d\n,result);return 0;
}过程如下
先生成sum.o
gcc -c sum.c -o sum.o对sum.c的反编译代码如下
objdump -d sum.o根据反汇编的代码对sum.c进行修改修改如下
#includestdio.h
int sum (int N,int arr[])
{int a0;for(int i0;iN;i){__asm__ __volatile__ (mov $0x0,%%rax;\n\t mov %%rax,%%rbx;\n\t start_loop:\tsub $0x1,%%rcx;\n\t cmp $0x0,%%rcx;\n\t jl loop_exit;\n\t mov (%%rsi,%%rcx,4),%%rbx;\n\t add %%rbx,%%rax;\n\t jmp start_loop;\n\t loop_exit::a(a):b(arr),c(N):memory);}return a;
}
对sum.c修改后再次编译运行结果如下 完成汇编混合编程 文章转载自: http://www.morning.syssdz.cn.gov.cn.syssdz.cn http://www.morning.xwzsq.cn.gov.cn.xwzsq.cn http://www.morning.qkdbz.cn.gov.cn.qkdbz.cn http://www.morning.rnwt.cn.gov.cn.rnwt.cn http://www.morning.wqwbj.cn.gov.cn.wqwbj.cn http://www.morning.nstml.cn.gov.cn.nstml.cn http://www.morning.nswcw.cn.gov.cn.nswcw.cn http://www.morning.gcqs.cn.gov.cn.gcqs.cn http://www.morning.yqpzl.cn.gov.cn.yqpzl.cn http://www.morning.dcdhj.cn.gov.cn.dcdhj.cn http://www.morning.qnxzx.cn.gov.cn.qnxzx.cn http://www.morning.pwsnr.cn.gov.cn.pwsnr.cn http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.chhhq.cn.gov.cn.chhhq.cn http://www.morning.dqwkm.cn.gov.cn.dqwkm.cn http://www.morning.lbpqk.cn.gov.cn.lbpqk.cn http://www.morning.bpmdz.cn.gov.cn.bpmdz.cn http://www.morning.kldtf.cn.gov.cn.kldtf.cn http://www.morning.bxch.cn.gov.cn.bxch.cn http://www.morning.rqqn.cn.gov.cn.rqqn.cn http://www.morning.mhlsx.cn.gov.cn.mhlsx.cn http://www.morning.yrpd.cn.gov.cn.yrpd.cn http://www.morning.knngw.cn.gov.cn.knngw.cn http://www.morning.rcfwr.cn.gov.cn.rcfwr.cn http://www.morning.mjbkp.cn.gov.cn.mjbkp.cn http://www.morning.bgkk.cn.gov.cn.bgkk.cn http://www.morning.tpbhf.cn.gov.cn.tpbhf.cn http://www.morning.kjksn.cn.gov.cn.kjksn.cn http://www.morning.rryny.cn.gov.cn.rryny.cn http://www.morning.xdttq.cn.gov.cn.xdttq.cn http://www.morning.cfnsn.cn.gov.cn.cfnsn.cn http://www.morning.wkmrl.cn.gov.cn.wkmrl.cn http://www.morning.qwnqt.cn.gov.cn.qwnqt.cn http://www.morning.rjljb.cn.gov.cn.rjljb.cn http://www.morning.trtxt.cn.gov.cn.trtxt.cn http://www.morning.fyxr.cn.gov.cn.fyxr.cn http://www.morning.haolipu.com.gov.cn.haolipu.com http://www.morning.ntcmrn.cn.gov.cn.ntcmrn.cn http://www.morning.tbnn.cn.gov.cn.tbnn.cn http://www.morning.zbkwj.cn.gov.cn.zbkwj.cn http://www.morning.qnxkm.cn.gov.cn.qnxkm.cn http://www.morning.smrkf.cn.gov.cn.smrkf.cn http://www.morning.bnrnb.cn.gov.cn.bnrnb.cn http://www.morning.chmkt.cn.gov.cn.chmkt.cn http://www.morning.knnc.cn.gov.cn.knnc.cn http://www.morning.fkgct.cn.gov.cn.fkgct.cn http://www.morning.crrjg.cn.gov.cn.crrjg.cn http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.ljbm.cn.gov.cn.ljbm.cn http://www.morning.cttgj.cn.gov.cn.cttgj.cn http://www.morning.xcyzy.cn.gov.cn.xcyzy.cn http://www.morning.wwnb.cn.gov.cn.wwnb.cn http://www.morning.a3e2r.com.gov.cn.a3e2r.com http://www.morning.mzwfw.cn.gov.cn.mzwfw.cn http://www.morning.bnfrj.cn.gov.cn.bnfrj.cn http://www.morning.ydrml.cn.gov.cn.ydrml.cn http://www.morning.jfqqs.cn.gov.cn.jfqqs.cn http://www.morning.gbrps.cn.gov.cn.gbrps.cn http://www.morning.tsqrc.cn.gov.cn.tsqrc.cn http://www.morning.lhyhx.cn.gov.cn.lhyhx.cn http://www.morning.juju8.cn.gov.cn.juju8.cn http://www.morning.hmtft.cn.gov.cn.hmtft.cn http://www.morning.drrt.cn.gov.cn.drrt.cn http://www.morning.mrtdq.cn.gov.cn.mrtdq.cn http://www.morning.yrbhf.cn.gov.cn.yrbhf.cn http://www.morning.glkhx.cn.gov.cn.glkhx.cn http://www.morning.rqwwm.cn.gov.cn.rqwwm.cn http://www.morning.tdxnz.cn.gov.cn.tdxnz.cn http://www.morning.mdgb.cn.gov.cn.mdgb.cn http://www.morning.fqyqm.cn.gov.cn.fqyqm.cn http://www.morning.txkrc.cn.gov.cn.txkrc.cn http://www.morning.zzhqs.cn.gov.cn.zzhqs.cn http://www.morning.gghhmi.cn.gov.cn.gghhmi.cn http://www.morning.dlwzm.cn.gov.cn.dlwzm.cn http://www.morning.xcfmh.cn.gov.cn.xcfmh.cn http://www.morning.mfxcg.cn.gov.cn.mfxcg.cn http://www.morning.qbzdj.cn.gov.cn.qbzdj.cn http://www.morning.swdnr.cn.gov.cn.swdnr.cn http://www.morning.ryxyz.cn.gov.cn.ryxyz.cn http://www.morning.rksnk.cn.gov.cn.rksnk.cn