汇编炮弹弹道计算实验
发布时间
阅读量:
阅读量
文章目录
- 一、先使用c语言编写
- 二、翻译为汇编语言
1.编写一个汇编程序,完成如下要求:
(1)程序包含必要的数据定义语句,保存中间运算结果。
(2)程序通过键盘炮弹的初速度与炮弹与地平线的夹角,输入值的类型为浮点数。
(3)程序输出炮弹能够达到的最高高度和最远记录,格式为:
The maximum height is 高度 meters and the farthest record is 距离 meters
(4)由于正弦与余弦函数的计算是会被重复使用的代码,因此需要用过程来实现,实验要求用汇编语言实现
[下载汇编INCLUDE floatio.inc包
()
一、先使用c语言编写
#include<stdio.h>
#include<math.h>
//最高高度和最远记录
float getsin(float x){
float sum,a,b; //sum代表和,a为分子,b为分母
char s;
s=1;
sum=0;
a=x; //分子赋初值
b=1; //分母赋初值
for(int i=1;a/b>=1e-6;i++) //精确到0.000001
{
sum=sum+s*a/b; //累加一项
a=a*x*x; //求下一项分子 x的3, 5, 7次方
b=b*2*i*(2*i+1); //求下一项分母 1*2*3,1*2*3*4*5,1*2*3*4*5*6*7
s*=-1;
}
printf("sin%f=%f\n",x,sum);
return sum;
}
float getcos(float x){
float sum,a,b; //sum代表和,a为分子,b为分母
char s;
s=1;
sum=0;
a=1; //分子赋初值
b=1; //分母赋初值
for(int i=1;a/b>=1e-6;i++) //精确到0.000001
{
sum=sum+s*a/b; //累加一项
a=a*x*x; //求下一项分子 x的2, 4, 6次方
b=b*i*2*(2*i-1); //求下一项分母 1*2,1*2*3*4,1*2*3*4*5*6
s*=-1;
}
printf("cos%f=%f\n",x,sum);
return sum;
}
float getT(float v,float x){
float t,g=9.8;
t=v*x/g;
printf("t:%f",t);
return t;
}
float getH(float t){
float H,g=9.8;
H=g*t*t/2;
return H;
}
float getC(float t,float x,float v){
return t*x*2*v;
}
void main()
{
float x,t,v,h,c;
printf("发射角度\nx取0-π/2(约等于1.5707963)\nX=");
scanf("%f",&x);//角度
printf("发射速度\V=");
scanf("%f",&v);//速度
float sumsin=getsin(x);//sin
float sumcos=getcos(x);//cos
t=getT(v,sumsin);//上升到最高所要时间
h=getH(t); //最高
c=getC(t,sumcos,v);//最远
printf("高%f",h);
printf("远%f",c);
}
二、翻译为汇编语言
INCLUDE Irvine32.inc
INCLUDE macros.inc
INCLUDE floatio.inc
.data
cyy118 real8 ? ;输入角度 输入0.523599
cyy1182 real8 ? ;输入初速度 输入10.0
jiaodu real8 1.5707963 ;通过 cos角度= sin(π/2-角度) ,带入求sin函数中求cos
jiao real8 180.0
fenzi real8 0.0 ;分子
fenmu real8 1.0 ;分母 初始化分母
sum real8 0.0 ;和
fan1 real8 1.0 ;乘-1
fan2 real8 -1.0 ;乘-1 ;cyy118
jie real8 1.0 ;阶乘 变量
guding1 real8 1.0 ;固定为1,为阶乘变量增加服务
guding2 real8 2.0 ;固定为2,为分母变量服务
sin real8 0.0 ;正弦值 0.5
cos real8 0.0 ;余弦值 0.866025
tt real8 0.0 ;到达最高所需时间 0.510204
gg real8 9.8 ;重力加速度
cc real8 0.0 ;最远距离 8.836995
hh real8 0.0 ;最高距离 1.275511
.code
getfenmu proc
fld jie
fld guding2
fmul ;st0 = jie
fld guding1
fadd ;st0 = st0 + 1
fld jie
fmul ;st0 = st0 * jie
fld guding2 ;cyy118
fmul ;st0 = st0
fld fenmu
fmul ;st0 = fenmu * st0
fstp fenmu ;fenmu = st0
ret
getfenmu endp
sinandcos proc
mov ecx,8
L1: ;求sin
fld fan1 ;-1*分子
fld fenzi ;st0,st1
fmul ;st0 = fan1 * fenzi
fld fenmu
fdiv ;st0 = st0 / fenmu
fld sum
fadd ;st0 = st0 + sum
fstp sum ;去浮点数ST(0)到sum,执行出栈操作 sum = st0 Null
fld fenzi
fld cyy118
fmul ;st0 = fenzi * cyy118
fld cyy118
fmul ;st0 = st0 * cyy118
fstp fenzi ;fenzi = st0 Null
call getfenmu ;获得分母
fld jie ;cyy118
fld guding1
fadd ;st0 = jie + guding1
fstp jie ;jie = st0 NUll
fld fan1
fld fan2
fmul ;fan1 = fan1 * -1
fstp fan1
loop L1
ret ;cyy118
sinandcos endp
main PROC
mWrite "angle x=(0-90): "
call ReadFloat
fstp cyy118
mWrite "speed V= "
call ReadFloat
fstp cyy1182
fld cyy118
fld jiao
fdiv
fldpi
fmul
fstp cyy118
fld cyy118
fstp fenzi ;初始化分子 去浮点数ST(0)到dst,执行出栈操作
call sinandcos ;获得sin
fld sum
mWrite "sinx=" ;cyy118
call WriteFloat
fstp sin
call ShowFPUStack ;cyy118
fld jiaodu
fld cyy118
fsub
fstp cyy118
fld guding1
fst fenmu
fst jie ;cyy118
fstp fan1
fld cos
fstp sum
fld cyy118
fstp fenzi
call sinandcos ;获得cos
fld sum
mWrite "cosx="
call WriteFloat
fstp cos
call ShowFPUStack
fld sin
fld cyy1182
fmul ;cyy118
fld gg
fdiv ;st0 = st0 / gg
mWrite "T="
call WriteFloat
fstp tt
call ShowFPUStack ;cyy118
fld gg
fld tt
fmul ;st0 = gg * tt
fld tt
fmul ;st0 = st0 * tt
fld guding2
fdiv ;st0 = st0 / 2
mWrite "The maximum height is"
call WriteFloat
fstp hh
call ShowFPUStack ;cyy118
fld tt
fld cos
fmul
fld guding2
fmul
fld cyy1182
fmul
mWrite "the farthest record is:" ;cyy118
call WriteFloat
fstp cc
call ShowFPUStack
main endp ;cyy118
END main
全部评论 (0)
还没有任何评论哟~
