请帮忙!我有一个汇编代码实现,在Microsoft Visual Studio中以整数的二进制表示形式计算“1”的数量。
我实际上可以编译没有错误!但是当我跑步时,我得到了一个未处理的例外:
**'lab2.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'lab2.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'lab2.exe' (Win32): Loaded 'C:\Windows\System32\msvcr120d.dll'. Cannot find or open the PDB file.
First-chance exception at 0x68A07310 (msvcr120d.dll) in lab2.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x68A07310 (msvcr120d.dll) in lab2.exe: 0xC0000005: Access violation writing location 0x00000000.
The program '[3356] lab2.exe' has exited with code 0 (0x0).**
我的代码在这里:(
__declspec(naked) unsigned int countOnes(unsigned int x) {
__asm{
PUSH EAX
PUSH EBX
PUSH ECX
PUSH EDX
XOR EAX, EAX
MOV EBX, [ESP + 20]
XOR ECX, ECX
MOV EDX, 1
FOR_LOOP:
CMP ECX, 8
JGE END_LOOP
AND EDX, EBX
CMP EDX, 1
JE COUNT
NEXT:
INC ECX
XOR EDX, EDX
SHL EDX, CL
JMP FOR_LOOP
COUNT:
INC EAX
JMP NEXT
END_LOOP:
ret
}
}