I have small app, which should show a simple Fractal.
Here is the ASM_CODE, i'm creating dll here.
format PE GUI 4.0 DLL
entry DllMain
include 'include\win32a.inc'
section '.text' code readable executable
proc AssemblerDraw bmp
mov ebx, [bmp]
mov [imgPtr], ebx
mov ecx, 10000000
sss:
mov [licznik1], ecx
ccall generateLetters
ccall transformation
ccall paintPixel
mov ecx, [licznik1]
loop sss
ret
endp
proc DllMain hinstDLL, fdwReason, lpvReserved
mov eax, TRUE
ret
endp
proc Random
finit
fild [losM]
fild [losA]
fild [los]
fmulp
fild [losB]
faddp
fprem
fist [los]
mov eax, [los]
mov edx, 0 =
mov ecx, 100
div ecx
mov eax, edx
ret
endp
proc generateLetters
ccall Random
cmp eax, 54
jge spr2
mov [a], -0.67
mov [b], -0.02
mov [c], 0.0
mov [d], -0.18
mov [e], 0.81
mov [f], 10.0
ret
spr2:
cmp eax, 74
jge spr3
mov [a], 0.4
mov [b], 0.4
mov [c], 0.0
mov [d], -0.1
mov [e], 0.4
mov [f], 0.0
ret
spr3:
cmp eax, 94
jge spr4
mov [a], -0.4
mov [b], -0.4
mov [c], 0.0
mov [d], -0.1
mov [e], 0.4
mov [f], 0.0
ret
spr4:
mov [a], -0.1
mov [b], 0.0
mov [c], 0.0
mov [d], 0.44
mov [e], 0.44
mov [f], -2.0
ret
endp
proc paintPixel
finit
fldz
fld [y]
fsubp
fld [f60]
faddp
fld [f70]
fdivp
fld [frozmiar]
fmulp
fist [inty]
fld [x]
fld [f30]
faddp
fld [f60]
fdivp
fld [frozmiar]
fmulp
fist [intx]
mov eax, 2000
mul [inty]
add eax, [intx]
mov ecx, 3
mul ecx
mov ebx, [imgPtr]
cmp eax, 2000*2000*3
jae koniecpaint
mov byte [ebx+eax], 0
inc eax
mov byte [ebx+eax], 0
inc eax
mov byte [ebx+eax], 0
koniecpaint:
ret
endp
proc transformation
finit
fld [a]
fld [x]
fmulp
fld [b]
fld [y]
fmulp
faddp
fld [c]
faddp
fld [d]
fld [x]
fmulp
fld [e]
fld [y]
fmulp
faddp
fld [f]
faddp
fstp [y]
fstp [x]
ret
endp
section '.idata' import data readable writeable
library msvcrt,'MSVCRT.DLL',\
kernel32,'KERNEL32.DLL'
import msvcrt,\
getch,'_getch',\
putchar,'putchar',\
puts,'puts',\
printf,'printf',\
scanf,'scanf'
section '.data' data readable writeable
los dd 0
losA dd 13100233
losB dd 11040857
losM dd 9999991
a dd ?
b dd ?
c dd ?
d dd ?
e dd ?
f dd ?
x dq 0.1
y dq 0.1
f10 dq 10.0
f70 dq 70.0
f30 dq 30.0
f60 dq 60.0
frozmiar dq 2000.0
intx dd ?
inty dd ?
imgPtr dd ?
licznik1 dd ?
section '.edata' export data readable
export 'P3_ASM.dll',\
AssemblerDraw, 'assemblerDraw',\
paintPixel, 'paintPixel',\
Random, 'random'
data fixups
end data
there is C++:
#include <windows.h>
#include <iostream>
typedef int(__stdcall *f_assemblerDraw)();
typedef int(__stdcall *f_random)();
typedef int(__stdcall *f_paintPixel)();
int main()
{
HINSTANCE hGetProcIDDLL = LoadLibrary ("C:\\DOS\\fasm\\P3_ASM.DLL");
if (!hGetProcIDDLL) {
std::cout << "could not load the dynamic library" << std::endl;
return EXIT_FAILURE;
}
// resolve function address here
f_assemblerDraw assemblerDraw = (f_assemblerDraw)GetProcAddress(hGetProcIDDLL, "assemblerDraw");
if (!assemblerDraw) {
std::cout << "could not locate the function" << std::endl;
return EXIT_FAILURE;
}
f_random random = (f_random)GetProcAddress(hGetProcIDDLL, "random");
if (!random) {
std::cout << "could not locate the function" << std::endl;
return EXIT_FAILURE;
}
f_paintPixel paintPixel = (f_paintPixel)GetProcAddress(hGetProcIDDLL, "paintPixel");
if (!paintPixel) {
std::cout << "could not locate the function" << std::endl;
return EXIT_FAILURE;
}
assemblerDraw();
return EXIT_SUCCESS;
}
When I run the app i've got the following(in Visual Studio):
Access Violation in address 0x00A6F3EC
Or it should be maked in other way?