我正在编写一个汇编程序,可以生成所有可能的毕达哥拉斯三元组,我的问题是在运行一段时间后我得到了这个错误:
“Project.exe中0x00403484处的未处理异常:0xC0000005:访问冲突写入位置0x00190000。”
当我点击错误时,它会将我带到我的三重程序 (mov A,eax)
我想知道是否有人可以帮我解决这个问题我不知道为什么可以在前7次写入它,但是第8次出现错误。
TITLE Program 3 Pythagorean Triples (main.asm)
INCLUDE Irvine32.inc
.data
myMessage BYTE "Here is a list of all possible Pythagorean Triples: ",0dh,0ah,0
myX BYTE " x: ",0
myY BYTE " y: ",0
myZ BYTE " z: ",0
myU DWORD ?
myV DWORD ?
mytempX DWORD ?
mytempY DWORD ?
mytempZ DWORD ?
.code
main PROC
mov edx, OFFSET myMessage
call WriteString
mov myU, 2
dowh1: mov eax, myU
and eax, 1
jnz else1
mov myV, 1
jmp dowh2
else1: mov myV, 2
dowh2: call gcd
cmp eax, 1
jne else2
mov eax, myU
mov ebx, myV
call triple
jmp enddo2
else2: add myV, 2
mov eax, myV
cmp eax, myU
jb dowh2
enddo2: add myU, 1
mov eax, myU
cmp eax, 10
jb dowh1
exit
main ENDP
GCD程序
gcd PROC A:DWORD, B:DWORD
mov eax, myU
mov A, eax
mov ebx, myV
mov B, ebx
while1: mov ebx, B
cmp ebx, 0
jna endwh1
mov eax, A
mov edx, 0
div B
xchg edx, B
mov A, edx
jmp while1
endwh1: mov eax, A
ret
exit
gcd ENDP
三重程序
triple PROC U:DWORD, V:DWORD
mov eax, myU
mov U, eax
mov ebx, myV
mov V, ebx
mov eax, U
mul U
mov mytempX, eax
mov eax, V
mul V
sub mytempX, eax
mov eax, U
mov ecx, V
mul ecx
add eax, eax
mov mytempY, eax
mov eax, U
mul U
mov mytempZ, eax
mov eax, V
mul V
add mytempZ, eax
mov eax, mytempX
cmp eax, mytempY
jna ENDIF1
mov eax, mytempX
xchg eax, mytempY
mov mytempX, eax
endif1: mov edx, OFFSET myX
call WriteString
mov eax, mytempX
call WriteInt
mov edx, OFFSET myY
call WriteString
mov eax, mytempY
call WriteInt
mov edx, OFFSET myZ
call WriteString
mov eax, mytempZ
call WriteInt
call CRLF
ret
exit
triple ENDP
END main
输出
Here is a list of all possible Pythagorean Triples:
x: +3 y: +4 z: +5
x: +5 y: +12 z: +13
x: +8 y: +15 z: +17
x: +20 y: +21 z: +29
x: +12 y: +35 z: +37
x: +28 y: +45 z: +53
x: +16 y: +63 z: +65
PS。我希望我做的一切都是正确的,这是我第一次在这里发帖。