问题
I am writing a simple program that takes 3 ints from the user and does the following math:
- Sum of the first 2 numbers
- Difference of the second and third numbers
- Product of all three numbers
- Quotient (integer) and remainder of first and third numbers
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
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
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
Edit: The issue seems to lie with the textbook author's WriteDec routine that is in a library our professor has us include and use.
回答1:
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)
This has solved the issue.
来源:https://stackoverflow.com/questions/22926143/masm-x86-adding-two-ints