assembly - 打印方三角数不是预期值
问题描述
所以,我想打印一个正方形三角形数字,你可以在 这里看到。
这是我写的代码:
global main
extern printf
section .data
format db "%u ", 0
section .text
main:
mov ecx, 8
square_triangular:
xor edx, edx
mov eax, 0
call print ; just print zero in early
mov ebx, 1
mov eax, ebx
jecxz .done
.loop:
call print
imul eax, 34
sub eax, edx
add eax, 2
mov edi, eax
add edx, 1
sub edx, 1
xchg ebx, edx
mov ebx, edi
mov eax, eax ; store in eax
loop .loop
.done:
ret
print:
pushad
push eax
push format
call printf
add esp, 8
popad
ret
结果正确值是迭代自0 - 7
但在迭代时8
不是正确值。
0 1 36 1225 41616 1413721 48024900 1631432881 3881085504
^
|
here (this is wrong)
如果可能的话,你可以帮我解决这个问题吗?
解决方案
imul eax, 34
执行 32 位乘法,结果溢出
推荐阅读
- python - Python找不到导入模块搜索的文件
- javascript - 我怎样才能把这个常规的 JavaScript 函数变成 React.js 可以读取的东西
- mysql - MySQL query for remove items from database, but keep 1 single row per day
- arrays - Why is there a large performance impact when looping over an array with 240 or more elements?
- android - 如何以编程方式设置按钮样式资源?
- activemq - Artemis vs Activemq 5 message store
- mysql - How to combine some similar pattern data in one column of mysql, to get the count?
- python - How to change Representation of Many to Many related object in Django Rest Framework
- json - How can I decode a nested array of multiple types?
- java - Spring Security - 如何动态更改用户角色?