在两个 32 位寄存器中存储 64 位十进制(ASSEMBLY - NASM) [英] Storing a 64 bit decimal in two 32 bit registers (ASSEMBLY - NASM)

查看:73
本文介绍了在两个 32 位寄存器中存储 64 位十进制(ASSEMBLY - NASM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我的任务是从键盘读取最大64 位十进制数,并将该数字存储在两个 32 位寄存器(EDX:EAX).对于阅读,我必须使用一个名为 mio_readchar(它来自 mio 库)的函数,它从键盘读取一个字符,并将其存储在 AL.

So, my task is to read from the keyboard a max 64 bit decimal number, and to store that number in two 32 bit registers (EDX:EAX). For reading, I have to use a function called mio_readchar (it's from the mio library), which reads a character from the keyboard, and stores it in AL.

我不知道这是否是一项简单的任务,但我无法解决.如果你们能帮助我解决这个有趣的问题,我将不胜感激.谢谢大家!:D

I don't know whether this is an easy task or not, but I couldn't solve it. I would appreciate, if you guys could help me in solving this interesting problem. Thank you all in advance! :D

推荐答案

将其分解为更小(更简单)的部分:

Break it into smaller (simpler) pieces:

  • 将当前结果设置为零

  • Set the current result to zero

从键盘获取字符,检查字符是否有效(例如'0'到'9'而不是像'A'这样的疯狂的东西),然后从中减去'0'(这样你就可以从0 到 9)

Get character from keyboard, check if character is valid (e.g. '0' to '9' and not something crazy like 'A'), then subtract '0' from it (so that you get a number from 0 to 9)

检查是否可以将当前结果乘以 10 而不会导致溢出;然后将当前结果乘以 10

Check if you can multiply the current result by 10 without causing an overflow; then multiply the current result by 10

检查是否可以将新数字添加到当前结果中而不会导致溢出;然后将新数字添加到当前结果

Check if you can add the new digit to the current result without causing an overflow; then add the new digit to the current result

跳回第二步(获取下一个字符)

Jump back to the second step (get the next character)

注意:是什么导致此循环停止(输入键?),以及在各种错误情况下会发生什么,您需要弄清楚.

这篇关于在两个 32 位寄存器中存储 64 位十进制(ASSEMBLY - NASM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆