用汇编语言实现:以十进制形式输出双精度整型数
2015-06-24 12:54
531 查看
题目:以十进制形式输出双精度整型数(正数)(EDX:EAX双精度保存在两个寄存器中)
题解:
1.ans = (EDX * 2 ^ 32 + EAX)
2.每次对ans模10,除10
3.EDX = q1 * 10 + r1 , 2 ^ 32 = q2 * 10 + r2 , EAX = q3 * 10 + r3
4.ans = q1 * q2 * 100 + 10 * q1 * r2 + 10 * q2 * r1 + q3 * 10 + r1 * r2 + r3
5.ans / 10 = q1 * q2 * 10 + q1 * r2 + q2 * r1 + q3 + (r1 * r2 + r3) / 10
6.ans % 10 = (r1 * r2 + r3) % 10
7重复操作,直到EAX,EDX都为0时停止
总结:
1.考试前开始想这个题目的,但是没有想出来。突然觉得,每次我没有想出来一个编程问题,都是心思没有全都放在
想题上面的时候!比如想和谁谁谁比赛啦,争什么面子啦,对待知识不够纯粹,导致占用了大脑的一部分空间!
2.想到舍友yyz总说:相信这个题没有错,相信自己能够把题做出来,就可以攻无不克,战无不胜了!
3.然后就是写代码出了一些小bug,又是无脑的输出中间结果,其实错误很明显,直接静态查错,几下就全改出来了,
以后再碰到小程序错误,要改成先静态查错,再总观全局,最后输出中间结果。
4.对于这个想题思路上就是,类比法,对于10进制数以2进制形式输出的方法会了以后,可以类比到这个题目上来看。
类比是一种很好的模仿解题方法
题解:
1.ans = (EDX * 2 ^ 32 + EAX)
2.每次对ans模10,除10
3.EDX = q1 * 10 + r1 , 2 ^ 32 = q2 * 10 + r2 , EAX = q3 * 10 + r3
4.ans = q1 * q2 * 100 + 10 * q1 * r2 + 10 * q2 * r1 + q3 * 10 + r1 * r2 + r3
5.ans / 10 = q1 * q2 * 10 + q1 * r2 + q2 * r1 + q3 + (r1 * r2 + r3) / 10
6.ans % 10 = (r1 * r2 + r3) % 10
7重复操作,直到EAX,EDX都为0时停止
总结:
1.考试前开始想这个题目的,但是没有想出来。突然觉得,每次我没有想出来一个编程问题,都是心思没有全都放在
想题上面的时候!比如想和谁谁谁比赛啦,争什么面子啦,对待知识不够纯粹,导致占用了大脑的一部分空间!
2.想到舍友yyz总说:相信这个题没有错,相信自己能够把题做出来,就可以攻无不克,战无不胜了!
3.然后就是写代码出了一些小bug,又是无脑的输出中间结果,其实错误很明显,直接静态查错,几下就全改出来了,
以后再碰到小程序错误,要改成先静态查错,再总观全局,最后输出中间结果。
4.对于这个想题思路上就是,类比法,对于10进制数以2进制形式输出的方法会了以后,可以类比到这个题目上来看。
类比是一种很好的模仿解题方法
.data var byte 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ind dword 0 ans byte 65 dup(0) _low dword 0 _high dword 0 eax_quotient dword 0 eax_remainder dword 0 edx_quotient dword 0 edx_remainder dword 0 const_quotient dword 429496729 const_remainder dword 6 cur dword 10 .code main PROC comment ## ;first : read edx ;second : read eax call ReadHex mov edx,eax call ReadHex call display main ENDP display Proc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; ; ; function:display edx:eax in dec ; ; receives:EDX:EAX ; ; return:nothing ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov _low, eax mov _high, edx ;save eax£¬edx in memery do_64: mov edx, 0 mov eax, _high div cur mov [edx_remainder], edx ;save edx's remainder mov [edx_quotient], eax ;save edx's quotient mov edx, 0 mov eax, _low div cur mov [eax_remainder], edx ;save eax's remainder mov [eax_quotient], eax ;save eax's quotient ;call DumpRegs mov eax, const_remainder mul [edx_remainder] add eax, [eax_remainder] ;r = remainder1 * remainder2 + remainder3 cdq div cur ;r / 10 inc ind mov ebx, ind mov [ans + ebx], dl ;save r % 10 mov [_low], eax ;save r / 10 mov [_high], 0 ;init _high jmp go_on continue: jmp do_64 go_on: mov eax, 4294967290 mul [edx_quotient] ;10 * quotient2 * quotient1 add [_low], eax ;add it adc [_high], edx ;add it mov eax, const_quotient ;quotient1 * remainder2 mul edx_remainder add [_low], eax ;add it adc [_high], edx ;add it mov eax, const_remainder ;quotient2 * remainder1 mul edx_quotient add [_low], eax ;add it adc [_high], edx ;add it mov eax, eax_quotient ;quotient3 add [_low], eax ;add it adc [_high], 0 ;add it cmp _low, 0 jz second jmp continue second: cmp _high, 0 jnz continue mov ecx, ind write_it: movzx eax, [ans + ecx] call WriteDec loop write_it call Crlf ret display endp end main
相关文章推荐
- OC-多个自定义对象的归档与解归档
- Shell编程中if的语法和常见判断用法
- 利用rating-input PreviewWidget来对事物进行评价及打分
- Android实战简易教程-第二十一枪(GridView动态添加Item)
- GRE征兆类词汇
- ENode框架Conference案例分析系列之 - 架构设计
- [置顶] python局域网alive ip侦听
- 链表的基本操作与文件操作--期末大作业代码部分
- 解决Android Studio 和 Android SDK Manager 无法在线更新的问题.
- 小白逛公园
- python局域网alive ip侦听
- csharp: using wininet.dll
- 勾兑应收余额大于明细处理
- Android之MediaStore使用的点点滴滴
- CSS控制checkbox样式
- TCP/IP详解学习笔记(14)-TCP连接的未来和性能(未写完)
- JavaScript 给表格排序
- DFX可服务性可靠性安全性测试知识
- TCP/IP详解学习笔记(13)-TCP坚持定时器,TCP保活定时器
- python hook监听事件