Пишу математическую софтину и столкнулась с проблемой. Надо написать функцию проверки простоты числа на ассемблере. Она написана уже на VB, но думаю на асме будет намного быстрей работать. Итак, всё сделала, но функция всегда возвращает 0, хотя для простого числа должна возвращать 1. Может ли кто что посоветовать? Нет опыта в отладке asm-кода. VB: Option Explicit Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal ptrMC As Long, ByVal P1 As Long, ByVal P2 As Long, ByVal P3 As Long, ByVal P4 As Long) As Long Private BinCode() As Byte Private ptrBinCode As Long Private Path As String Private Function LoadBinCode() As Boolean On Error GoTo ErrOccured LoadBinCode = True Dim FF As Integer FF = FreeFile Open Path & "isprime.bin" For Binary Access Read Lock Write As #FF ReDim BinCode(LOF(FF) - 1) Get #FF, , BinCode Close #FF ptrBinCode = VarPtr(BinCode(0)) Exit Function ErrOccured: LoadBinCode = False End Function Sub Main() Path = Replace$(Trim$(App.Path) & "\", "\\", "\") If LoadBinCode Then MsgBox "BinCode was loaded!" Else MsgBox "BinCode loading failed!", vbCritical Dim Num As Integer Dim S As Long S = 32 '31 MsgBox CallWindowProc(ptrBinCode, VarPtr(S), 0, 0, 0) Erase BinCode End Sub Asm: [BITS 32] push ebp mov ebp,esp push ebx push ecx push edx push edi push esi mov esi,[ebp+8] cmp esi,1 ja not0or1 xor eax,eax jmp done not0or1: cmp esi,2 jne not2 mov eax,1 jmp done not2: test esi,1 jne notEven xor eax,eax jmp done notEven: cmp esi,7 ja not3or5or7 mov eax,1 jmp done not3or5or7: mov edi,primes mainLoop: cmp esi,[edi] jae notYet mov eax,1 jmp done notYet: mov eax,[edi + 8] mul esi mov eax,edx mul dword [edi + 4] add edi,12 cmp eax,esi jne mainLoop xor eax,eax done: pop esi pop edi pop edx pop ecx pop ebx mov esp,ebp pop ebp ret SECTION .data primes: dd 9,3,0x55555556,25,5,0x33333334,49,7,0x24924925,121,11,0x1745d175,169,13,0x13b13b14,289,17,0xf0f0f10,361,19,0xd79435f,529,23,0xb21642d,841,29,0x8d3dcb1,961,31,0x8421085 dd 1369,37,0x6eb3e46,1681,41,0x63e7064,1849,43,0x5f417d1,2209,47,0x572620b,2809,53,0x4d4873f,3481,59,0x456c798,3721,61,0x4325c54,4489,67,0x3d22636,5041,71,0x39b0ad2,5329,73,0x381c0e1 dd 6241,79,0x33d91d3,6889,83,0x3159722,7921,89,0x2e05c0c,9409,97,0x2a3a0fe,10201,101,0x288df0d,10609,103,0x27c4598,11449,107,0x2647c6a,11881,109,0x2593f6a,12769,113,0x243f6f1,16129,127,0x2040811 dd 17161,131,0x1f4465a,18769,137,0x1de5d6f,19321,139,0x1d77b66,22201,149,0x1b7d6c4,22801,151,0x1b20365,24649,157,0x1a16d40,26569,163,0x1920fb5,27889,167,0x1886e60,29929,173,0x17ad221,32041,179,0x16e1f77 dd 32761,181,0x16a13ce,36481,191,0x1571ed4,37249,193,0x1539095,38809,197,0x14cab89,39601,199,0x149539f,44521,211,0x13698e0,49729,223,0x125e228,51529,227,0x120b471,52441,229,0x11e2ef4,54289,233,0x1194539 dd 57121,239,0x112358f,58081,241,0x10fef02,63001,251,0x1051980,66049,257,0xff0100,69169,263,0xf92fb3,72361,269,0xf3a0d6,73441,271,0xf1d48c,76729,277,0xec9792,78961,281,0xe93966,80089,283,0xe79373 dd 85849,293,0xdfac20,94249,307,0xd578ea,96721,311,0xd2ba09,97969,313,0xd16155,100489,317,0xcebcf9,109561,331,0xc5fe75,113569,337,0xc27807,120409,347,0xbcdd54,121801,349,0xbbc841,124609,353,0xb9a787 dd 128881,359,0xb68d32,134689,367,0xb2927d,139129,373,0xafb322,143641,379,0xaceb10,146689,383,0xab1cbe,151321,389,0xa87918,157609,397,0xa513fe,160801,401,0xa36e72,167281,409,0xa03c17,175561,419,0x9c6917 dd 177241,421,0x9baadf,185761,431,0x980e42,187489,433,0x975a76,192721,439,0x9548e5,196249,443,0x93efd2,201601,449,0x91f5bd,208849,457,0x8f67a2,212521,461,0x8e2918,214369,463,0x8d8be4,218089,467,0x8c5585 dd 229441,479,0x88d181,237169,487,0x869223,241081,491,0x85797c,249001,499,0x8355ad,253009,503,0x824a4f,259081,509,0x80c122,271441,521,0x7dc9f4,273529,523,0x7d4ecf,292681,541,0x79237e,299209,547,0x77cf54 dd 310249,557,0x75a8ad,316969,563,0x7467ad,323761,569,0x732d71,326041,571,0x72c62b,332929,577,0x7194a2,344569,587,0x6fa54a,351649,593,0x6e841a,358801,599,0x6d68b6,361201,601,0x6d0b81,368449,607,0x6bf791 dd 375769,613,0x6ae908,380689,617,0x6a379a,383161,619,0x69dfbe,398161,631,0x67dc4d,410881,641,0x663d81,413449,643,0x65ec18,418609,647,0x654ac9,426409,653,0x645c86,434281,659,0x63729a,436921,661,0x632592 dd 452929,673,0x616100,458329,677,0x60cdb6,466489,683,0x5ff402,477481,691,0x5ed79f,491401,701,0x5d7d43,502681,709,0x5c6f36,516961,719,0x5b2619,528529,727,0x5a2554,537289,733,0x59686d,546121,739,0x58ae98 dd 552049,743,0x583460,564001,751,0x5743d6,573049,757,0x5692c5,579121,761,0x561e47,591361,769,0x5538ee,597529,773,0x54c808,619369,787,0x5345f0,635209,797,0x523a76,654481,809,0x510238,657721,811,0x50cf13 dd 674041,821,0x4fd31a,677329,823,0x4fa171,683929,827,0x4f3ed7,687241,829,0x4f0de6,703921,839,0x4e1caf,727609,853,0x4cd47c,734449,857,0x4c78af,737881,859,0x4c4b1a,744769,863,0x4bf094,769129,877,0x4aba3d dd 776161,881,0x4a6361,779689,883,0x4a383f,786769,887,0x49e290,822649,907,0x48417c,829921,911,0x47f044,844561,919,0x474ff3,863041,929,0x468b70,877969,937,0x45f140,885481,941,0x45a523,896809,947,0x45342d dd 908209,953,0x44c4a3,935089,967,0x43c5c3,942841,971,0x437e4a,954529,977,0x43142e,966289,983,0x42ab5d,982081,991,0x422196,994009,997,0x41bbb3,1018081,1009,0x40f392,1026169,1013,0x40b1ea,1038361,1019,0x405065 dd 1042441,1021,0x403025,1062961,1031,0x3f90c3,1067089,1033,0x3f7142,1079521,1039,0x3f1378,1100401,1049,0x3e7989,1104601,1051,0x3e5b1a,1125721,1061,0x3dc4a6,1129969,1063,0x3da6e5,1142761,1069,0x3d4e50,1181569,1087,0x3c4a6c dd 1190281,1091,0x3c11d6,1194649,1093,0x3bf5b2,1203409,1097,0x3bbdba,1216609,1103,0x3b6a89,1229881,1109,0x3b183d,1247689,1117,0x3aabe4,1261129,1123,0x3a5ba4,1274641,1129,0x3a0c3f,1324801,1151,0x38f036,1329409,1153,0x38d6ed dd 1352569,1163,0x3859d0,1371241,1171,0x37f742,1394761,1181,0x377df1,1408969,1187,0x373623,1423249,1193,0x36ef0d,1442401,1201,0x369160,1471369,1213,0x36072d,1481089,1217,0x35d9b8,1495729,1223,0x359616,1510441,1229,0x35531d dd 1515361,1231,0x353cef,1530169,1237,0x34fad4,1560001,1249,0x347885,1585081,1259,0x340dd4,1630729,1277,0x3351fe,1635841,1279,0x333d73,1646089,1283,0x33148e,1661521,1289,0x32d7af,1666681,1291,0x32c386,1682209,1297,0x328767 dd 1692601,1301,0x325fa2,1697809,1303,0x324bd7,1708249,1307,0x32246f,1739761,1319,0x3
Ответить
|