从 ASM 中的文件读取浮点数
我一直在解决 The Binary Auditor 中的 c++ 和 asm 问题。我完成了 C++ 的内容没有问题,但是汇编给我带来了一些麻烦。我在 Windows 7 上使用 masm32。
第一个汇编问题本质上要求您计算存储在文本文件中的一系列浮点值的平均值,每行一个值。到目前为止,我已经能够从文件中读取数据并将其作为一系列字符存储在数组中。
所以,我的问题是,要从数组中提取浮点值,我需要物理地查看每个字节,检测换行符和“.”,然后构造浮点数吗?有没有更简单的方法?!
谢谢
I've been working through the c++ and asm problems from The Binary Auditor. I got through the c++ stuff no problem, but the assembly is giving me a bit of trouble. I'm using masm32 on Windows 7.
The first assembly problem essentially asks you to calculate the average of a series of float values which are stored in a text file, one value per line. So far, I've been able to read in the data from the file and store it in an array as a series of characters.
So, my question is, to extract the float values from the array will I need to physically look at each byte, detect newline characters and '.'s and then construct the floats? Is there an easier way?!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按你说的做。我认为这可以通过一次完成:从文件中读取一个字节一个字节,并立即构造一个数字后的浮点数。
如果允许使用 CRT 库,您还可以调用 fscanf() 或其他方法将字符串转换为双精度,但我认为这里的目标是在汇编程序中执行此操作,因此请按上述操作。
Do it as you said. I think it can be done in a single pass: Read byte after byte from your file and construct the float immediately digit after digit.
If you are allowed to use CRT library, you can also call fscanf() or something to convert string to double, but I think the goal here is to do it in assembler, so do it as was said.