MASM x86加两个整数 [英] MASM x86 Adding two ints

查看:62
本文介绍了MASM x86加两个整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的程序,该程序需要用户输入3个整数并进行以下数学运算:

I am writing a simple program that takes 3 ints from the user and does the following math:

  • 前2个数字之和
  • 第二个和第三个数字的差异
  • 所有三个数字的乘积
  • 商(整数)以及第一个和第三个数字的余数

应该向用户显示计算结果.例如,如果用户输入10、9和8,则应该在第一个计算中显示:

There should be output to the user showing the calculation. For example, if the user enters 10, 9, and 8, it should show for the first calculation:

10 + 9 = 19

10 + 9 = 19

此刻,我正在尝试求和.我能够计算出它,但是在添加它们之后,我似乎无意中覆盖了number_1和number_2以等于它们的总和,所以我的输出是:

I'm trying to do the sum at the moment. I was able to calculate it, but I seem to be inadvertently overwriting number_1 and number_2 to equal the sum after I add them, so my output is:

19 + 19 = 19

19 + 19 = 19

有人可以帮我解决我在这里做错的事情吗?这是我上礼拜的第一周,所以如果答案很明显,还是很抱歉……

Can anyone help me with what I'm doing wrong here? This is my first week doing assembly so I'm sorry if the answer is super obvious or something...

; Sum of first two numbers
mov     eax, number_1
mov     ebx, number_2
add     eax, ebx
mov     sum, eax

; Print results
mov     edx, OFFSET number_1
call    WriteDec
mov     edx, OFFSET op_plus
call    WriteString
mov     edx, OFFSET number_2
call    WriteDec
mov     edx, OFFSET op_equ
call    WriteString
mov     edx, OFFSET sum
call    WriteDec

问题似乎在于教科书作者的WriteDec例程,该例程位于我们的教授为我们提供和使用的库中.

The issue seems to lie with the textbook author's WriteDec routine that is in a library our professor has us include and use.

推荐答案

由于该库的WriteDec例程似乎仅从EAX中提取,因此每次尝试写入数字之前都需要额外一行.

Due to the library's WriteDec routine appearing to only pull from EAX, it requires an extra line before each attempt to write the numbers.

mov eax, (variable-name)
move edx, OFFSET (variable-name)

这已经解决了问题.

这篇关于MASM x86加两个整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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