⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 浮点运算简介.htm

📁 利用FPGA实现浮点运算的verilog代码 希望能够给需要做这方面研究的同仁有所帮助
💻 HTM
📖 第 1 页 / 共 2 页
字号:
  <BR>option casemap :none&nbsp; ; case sensitive <BR>include c:\hd\hd.h 
  <BR>include c:\hd\mac.h <BR><BR>;;-------------- <BR>&nbsp; &nbsp;&nbsp;.DATA 
  <BR>num1&nbsp; &nbsp; dq&nbsp; &nbsp; &nbsp; 12345 <BR>num2&nbsp; &nbsp; 
  dq&nbsp; &nbsp; &nbsp; 98765 <BR>res&nbsp; &nbsp; dd&nbsp; &nbsp; &nbsp; 0 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; .DATA? <BR>buf&nbsp; &nbsp; db 200 dup(?) 
  <BR><BR>;;----------------------------------------- <BR>&nbsp; 
  &nbsp;&nbsp;.CODE <BR>__Start: <BR>&nbsp; &nbsp; &nbsp; &nbsp; finit&nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;初始化浮点部件 <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; fild&nbsp; &nbsp; num1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; ;装入num1 <BR>&nbsp; &nbsp; &nbsp; &nbsp; fild&nbsp; &nbsp; num2&nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;装入num2 <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  fmul&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  ;执行乘法 <BR>&nbsp; &nbsp; &nbsp; &nbsp; fist&nbsp; &nbsp; res&nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; ;存储 <BR>&nbsp; &nbsp; &nbsp; &nbsp; invoke&nbsp; 
  &nbsp;&nbsp;wsprintf,addr buf,CTEXT("the result is: %ld"),res&nbsp; &nbsp; 
  &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; invoke&nbsp; 
  &nbsp;&nbsp;StdOut,addr buf ;显示,注意是控制台显示,编译用/SUBSYSTEM:CONSOLE <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp;&nbsp;invoke&nbsp; 
  &nbsp;&nbsp;StdIn,addr buf,20 <BR>&nbsp; &nbsp; &nbsp; &nbsp; invoke&nbsp; 
  &nbsp;&nbsp;ExitProcess,0&nbsp; <BR>END&nbsp; &nbsp;&nbsp;__Start 
  <BR><BR>具体你要怎样运用指令,那就得看你自己所要进行的操作和要执行的算法了.注意在fpu内部寄存器总是以扩展精度数来表示数值的,因此进行整数运算最后要用fist来存储,这样才能得到正确的结果,这些转换是由fpu自动完成的. 
  <BR><BR>浮点指令系统分为五类:数据传送类、算术运算类、超越函数类、比较类、环境及系统控制类. 
  <BR>我并不想列出所有函数的参数以及用法,因为这会是劳动力的浪费.我打字用拼音的!:D)具体参考资料见文章最后,别的我就帮不上你了.&nbsp; 
  <BR><BR>1)数据传送类,主要包括 
  <BR>这类指令主要是从内存装入浮点寄存器堆数据,一般目的地址总是栈顶ST(0),用调试器你可以清除的看到这一点.注意带P结尾的操作,是在前面操作完成之后出栈,也就是原来ST(1)的内容现在成了ST(0)的内容,注意到这一点,你可以方便地设计出灵活多变的程序. 
  <BR>装入:&nbsp; &nbsp;&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; FLD&nbsp; 
  &nbsp;&nbsp;Push real onto stack <BR>&nbsp; &nbsp; &nbsp; &nbsp; FILD&nbsp; 
  &nbsp;&nbsp;Convert two's complement integer to real and push <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; FBLD&nbsp; &nbsp;&nbsp;Convert BCD to real and push to 
  stack <BR>存储:&nbsp; &nbsp;&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; FST&nbsp; 
  &nbsp;&nbsp;Store floating-point number from stack <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; FSTP&nbsp; &nbsp;&nbsp;Convert top of stack to integer <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; FIST&nbsp; &nbsp;&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FISTP&nbsp; &nbsp;&nbsp;Convert top of stack to integer <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FBSTP&nbsp; &nbsp;&nbsp;Store BCD to integer and pop stack 
  <BR>交换:&nbsp; &nbsp;&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; FXCH&nbsp; 
  &nbsp;&nbsp;Exchange top two stack elements <BR>常数装载:&nbsp; &nbsp;&nbsp; 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; FLD1&nbsp; &nbsp;&nbsp;装入常数1.0 <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; FLDZ&nbsp; &nbsp;&nbsp;装入常数0.0 <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; FLDPI&nbsp; &nbsp;&nbsp;装入常数pi (=3.1415926....精度足够,放心使用) <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; FLDL2E&nbsp; &nbsp;&nbsp;装入常数log(2)e <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FLDL2T&nbsp; &nbsp;&nbsp;装入常数log(2)10 <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; FLDLG2&nbsp; &nbsp;&nbsp;装入常数log(10)2 <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FLDLN2&nbsp; &nbsp;&nbsp;装入常数Log(e)2 
  <BR><BR>我逼并不想列出所有的浮点指令的详细格式,因为没有必要!很多资料都有这些指令格式的介绍,浮点指令均以F开头,LD表示Load,ILD表示整数的Load,BLD是二十进制数的Load,这样记起来就很容易了,很多指令功能都可以根据指令一眼看出来. 
  <BR><BR><BR>2)算术运算类 <BR>加法:&nbsp; &nbsp;&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FADD/FADDP&nbsp; &nbsp;&nbsp;Add/add and pop <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FIADD&nbsp; &nbsp;&nbsp;Integer add <BR>减法:&nbsp; &nbsp;&nbsp; <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; FSUB/FSUBP&nbsp; &nbsp;&nbsp;Subtract/subtract and pop 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; FSUBR/FSUBRP&nbsp; 
  &nbsp;&nbsp;Subtract/subtract and pop with reversed operands <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FISUB&nbsp; &nbsp;&nbsp;Integer subtract <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FISUBR&nbsp; &nbsp;&nbsp;Integer subtract/subtract with reversed 
  operands <BR>乘法:&nbsp; &nbsp;&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FMUL/FMULP&nbsp; &nbsp;&nbsp;Multiply/multiply and pop <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FIMUL&nbsp; &nbsp;&nbsp;Integer multiply <BR>除法:&nbsp; 
  &nbsp;&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; FDIV/FDIVP&nbsp; 
  &nbsp;&nbsp;Divide/divide and pop <BR>&nbsp; &nbsp; &nbsp; &nbsp; FIDIV&nbsp; 
  &nbsp;&nbsp;Integer divide <BR>&nbsp; &nbsp; &nbsp; &nbsp; FDIVR/FDIVRP&nbsp; 
  &nbsp;&nbsp;Divide/divide and pop with reversed operands <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FIDIVR&nbsp; &nbsp;&nbsp;integer divide with reversed operands 
  <BR>其他:&nbsp; &nbsp;&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; FABS&nbsp; 
  &nbsp;&nbsp;Calculate absolute value <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FCHS&nbsp; &nbsp;&nbsp;Change sign <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FRNDINT&nbsp; &nbsp;&nbsp;Round to integer <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FSQRT&nbsp; &nbsp;&nbsp;Calculate square root <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FSCALE&nbsp; &nbsp;&nbsp;Scale top of stack by power of 2 <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FXTRACT&nbsp; &nbsp;&nbsp;Separate exponent and mantissa 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; FPREM&nbsp; &nbsp;&nbsp;Calculate partial 
  remainder <BR>&nbsp; &nbsp; &nbsp; &nbsp; FPREM1&nbsp; &nbsp;&nbsp;Calculate 
  partial remainder in IEEE format 
  <BR><BR>如果指令后面未带操作数,其默认的操作数为ST(0)和ST(1),关于带R后缀的指令是正常操作数的顺序变反,比如fsub执行的是x-y,fsubr执行的就是y-x. 
  <BR><BR>3)超越函数类 <BR>三角函数&nbsp; &nbsp;&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FSIN&nbsp; &nbsp;&nbsp;Calculate sine <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FCOS&nbsp; &nbsp;&nbsp;Calculate cosine <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FSINCOS&nbsp; &nbsp;&nbsp;Calculate quick sine and cosine <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FPTAN&nbsp; &nbsp;&nbsp;Calculate partial tangent <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; FPATAN&nbsp; &nbsp;&nbsp;Calculate partial arctangent 
  <BR>Log类&nbsp; &nbsp;&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; FYL2X&nbsp; 
  &nbsp;&nbsp;Calculate y times log base 2 of x <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FYL2XP1&nbsp; &nbsp;&nbsp;Calculate y times log base 2 of (x+1) <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; F2XM1&nbsp; &nbsp;&nbsp;Calculate (2^x)-1 <BR><BR>4)比较类 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; FCOM&nbsp; &nbsp;&nbsp;Compare <BR>&nbsp; 
  &nbsp; &nbsp; &nbsp; FCOMP&nbsp; &nbsp;&nbsp;Compare and pop <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FICOM&nbsp; &nbsp;&nbsp;Integer compare <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; FTST&nbsp; &nbsp;&nbsp;Integer compare and pop <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; FUCOM&nbsp; &nbsp;&nbsp;Unordered compare <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; FUCOMP&nbsp; &nbsp;&nbsp;Unordered compare and pop <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FXAM&nbsp; &nbsp;&nbsp;Set condition code bits for value at top 
  of stack <BR>&nbsp; &nbsp; &nbsp; &nbsp; FSTSW&nbsp; &nbsp;&nbsp;Store status 
  word 
  <BR><BR>会根据结果设置,C0~C3,在上面并未就C0~C3进行具体介绍,C1是用来判断上溢或者下溢的,C0相当于EFLAGS里面的CF,作用也基本一致,C2相当于PF,C3相当于ZF,你可能会看到如下指令 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; FSTSW&nbsp; ax <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  SAHF <BR>&nbsp; &nbsp; &nbsp; &nbsp; JZ&nbsp; &nbsp; &nbsp; label 
  <BR>为什么如此呢,因为用如上指令将状态字存入EFLAGS,C0正好置于CF位,C3正好置于ZF位. <BR><BR>5)环境及系统控制类 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; FLDCW&nbsp; &nbsp;&nbsp;Load control word 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; FSTCW&nbsp; &nbsp;&nbsp;Store control word 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; FSTSW&nbsp; &nbsp;&nbsp;Store status word 
  <BR>&nbsp; &nbsp; &nbsp; &nbsp; FLDENV&nbsp; &nbsp;&nbsp;Load environment 
  block <BR>&nbsp; &nbsp; &nbsp; &nbsp; FSTENV&nbsp; &nbsp;&nbsp;Store 
  environment block <BR>&nbsp; &nbsp; &nbsp; &nbsp; FSAVE&nbsp; &nbsp;&nbsp;Save 
  coprocessor state <BR>&nbsp; &nbsp; &nbsp; &nbsp; FRSTOR&nbsp; 
  &nbsp;&nbsp;Restore coprocessor state <BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FINIT&nbsp; &nbsp;&nbsp;Initialize coprocessor <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FCLEX&nbsp; &nbsp;&nbsp;Clear exception flags <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
  FINCSTP&nbsp; &nbsp;&nbsp;Increment stack pointer <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; FDECSTP&nbsp; &nbsp;&nbsp;Decrement stack pointer <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FFREE&nbsp; &nbsp;&nbsp;Mark element as free <BR>&nbsp; &nbsp; 
  &nbsp; &nbsp; FNOP&nbsp; &nbsp;&nbsp;No operation <BR>&nbsp; &nbsp; &nbsp; 
  &nbsp; FWAIT&nbsp; &nbsp;&nbsp;Wait until floating-point instruction complete 
  <BR><BR>我实在不想罗嗦了,因为这些指令的格式以及用法在Masm32V7的help目录下面的fphelp.hlp文件中有详细的说明,当然也还有很多其他的指令格式列表,我之所以列出来是为了完整性.这里还有一个比较困难的问题就是浮点数的显示,windows没有现成的函数调用,wsprintf只能显示整数,但有好多库支持,比如LYB主页上的浮点开发包,当然等你搞熟了这些东西,也可以自己写. 
  <BR><BR>关于浮点程序的调试,建议使用Softice,因为Trw不支持浮点堆栈的显示,现在网上有一个fpu插件,可以部分解决问题,不过不够好用.一切看你自己的选择了. 
  </SPAN></BLOCKQUOTE>
<HR>

<DIV class=pediy align=center><!-- #BeginLibraryItem "/Library/copyright.lbi" CLASS="p9z" -->
<TABLE height=62 cellSpacing=0 cellPadding=0 width="96%" align=center 
  border=0><TBODY>
  <TR>
    <TD height=15>
      <HR width="99%" color=#b2b2b2 noShade SIZE=1>
    </TD></TR>
  <TR>
    <TD height=47>
      <TABLE cellSpacing=0 cellPadding=0 border=0>
        <TBODY>
        <TR>
          <TD width=2 bgColor=#cccccc></TD>
          <TD width=3></TD>
          <TD class=p9 vAlign=center height=30><FONT class=en 
            color=#333333><FONT color=#999999>&copy;2000-2004 <A 
            href="http://www.pediy.com/">http://www.pediy.com/</A>&nbsp; All 
            rights reserved.<BR><SPAN class=p9>By</SPAN></FONT></FONT><SPAN 
            class=p9><FONT face=Verdana><FONT class=en face=Verdana 
            color=#318aef> </FONT><FONT class=en color=#333333><FONT 
            face=Verdana color=#318aef>KanXue 
            Studio</FONT></FONT></FONT></SPAN><FONT class=en 
            color=#333333></FONT></TD></TR></TBODY></TABLE>
      <P> </P></TD></TR></TBODY></TABLE><SPAN class=p9><FONT size=2><SPAN 
class=p9><FONT 
size=2></FONT></SPAN></FONT></SPAN><!-- #EndLibraryItem --></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -