用汇编语言实现:以十进制形式输出双精度整型数

题目:以十进制形式输出双精度整型数(正数)(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进制形式输出的方法会了以后,可以类比到这个题目上来看。

类比是一种很好的模仿解题方法

.datavar byte 1, 4, 9, 16, 25, 36, 49, 64, 81, 100ind dword 0ans byte 65 dup(0)_low dword 0_high dword 0eax_quotient dword 0eax_remainder dword 0edx_quotient dword 0edx_remainder dword 0const_quotient dword 429496729const_remainder dword 6cur dword 10.codemain PROCcomment ##;first : read edx;second : read eax call ReadHexmov edx,eaxcall ReadHexcall displaymain ENDPdisplay Proc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;function:display edx:eax in dec;;receives:EDX:EAX;;return:nothing;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mov _low, eaxmov _high, edx ;save eax£¬edx in memerydo_64:mov edx, 0mov eax, _highdiv curmov [edx_remainder], edx;save edx's remaindermov [edx_quotient], eax;save edx's quotientmov edx, 0mov eax, _lowdiv curmov [eax_remainder], edx;save eax's remaindermov [eax_quotient], eax;save eax's quotient;call DumpRegsmov eax, const_remaindermul [edx_remainder]add eax, [eax_remainder];r = remainder1 * remainder2 + remainder3cdqdiv cur;r / 10inc indmov ebx, indmov [ans + ebx], dl;save r % 10mov [_low], eax;save r / 10mov [_high], 0;init _highjmp go_oncontinue:jmp do_64go_on:mov eax, 4294967290mul [edx_quotient];10 * quotient2 * quotient1add [_low], eax;add itadc [_high], edx;add itmov eax, const_quotient;quotient1 * remainder2mul edx_remainderadd [_low], eax;add itadc [_high], edx;add itmov eax, const_remainder ;quotient2 * remainder1mul edx_quotientadd [_low], eax;add itadc [_high], edx;add itmov eax, eax_quotient;quotient3add [_low], eax;add itadc [_high], 0;add itcmp _low, 0jz secondjmp continuesecond: cmp _high, 0jnz continuemov ecx, indwrite_it:movzx eax, [ans + ecx]call WriteDecloop write_itcall Crlfretdisplay endpend main

你可以选择这样的“三心二意”:信心恒心决心;创意乐意。

用汇编语言实现:以十进制形式输出双精度整型数

相关文章:

你感兴趣的文章:

标签云: