Re: example in nasm
From: Ro (inp_out_at_sim.tim)
Date: 11/07/04
- Next message: KiLVaiDeN: "Re: [OT] Paging Frank K. (was: 'Re: [OT] Why Bush?')"
- Previous message: Ro : "*The* definition of assembly langauge (Did you have read this?)"
- In reply to: Ro : "Re: example in nasm"
- Next in thread: Ro : "Re: example in nasm"
- Reply: Ro : "Re: example in nasm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 07 Nov 2004 09:07:51 GMT
On Sat, 06 Nov 2004 10:52:02 GMT, Ro <inp_out@sim.tim> wrote:
>/* 0 b, 4 Ra, 8 @MousePos
>RND_RTimer:
>{< b
> << @MousePos=[k+8]
here there is an error because @MousePos==[esp+8] not [ebp+8]
anyway I think it doesn't is right
> *GetTickCount();
> a<<=16;
> b=@MousePos; ax=bx;
> < a | RND_lineare() | > b
> a^=b; ax|=1; /* Dispari allora non funziona
> >> @MousePos
> > b
> ret 4
>}
>
better this :)
/* 0b, 4 Ra, 8 @MousePos
/* 0FFFF_FFFFh F=1111
RND_RTimer_a:
{< b
<< @MousePos=[s+8]
/*-----------------------
b=@MousePos; a=@MousePos;
a>>=4; b&=0Fh; a&=0F0h; b|=a;
*GetTickCount();
a<<=8; a|=b; a&=0FFFFh;
>> @MousePos
> b
ret 4
}
A message with a full assembly windows program doesn't seems very long
-----------------------------------------
/* con a6
/* nasm -f obj prog.asm
/* alink -oPE prog.obj dlg.res
section .text use32
section .data use32
section .const use32
section .text
section .data
%macro str 2+
[section .data]
align 4, db 0
%1 db %2
dd 0
__SECT__
%endmacro
%define NL 13, 10
%define STDIN -10
%define STDOUT -11
%define IDI_ICON 100
%define IDR_MENU 2000
%define IDM_RANDOM 2001
%define IDM_MAX_RANDOM 2002
%define IDM_RANGE_RANDOM 2003
%define IDM_GAUSS 2004
%define IDM_LINEARE 2007
%define IDM_LINEARE1 2008
%define IDM_EXIT 2005
%define IDM_HELP_ABOUT 2006
%define IDC_ARROW 07f00h
IDCANCEL equ 2h ;
== ReadFile, WriteFile, GetStdHandle, ExitProcess == kernel32.dll
== GetModuleHandleA, GetTickCount == kernel32.dll
== DialogBoxParamA, EndDialog, MessageBoxA, SetDlgItemTextA ==
user32.dll
== LoadIconA, LoadCursorA, RegisterClassA, LoadMenuA, ShowWindow ==
user32.dll
== CreateWindowExA, DestroyWindow, PostQuitMessage, UpdateWindow ==
user32.dll
== TranslateMessage, DispatchMessageA, GetMessageA ==
user32.dll
== DefWindowProcA, ReleaseDC == user32.dll
== SendMessageA, GetDlgItemTextA, LoadBitmapA, BeginPaint ==
user32.dll
== GetClientRect, EndPaint, GetDC, FillRect, RedrawWindow ==
user32.dll
== CreateCompatibleDC, SelectObject, BitBlt, DeleteDC, SetPixel ==
gdi32.dll
WM_INITDIALOG equ 0110h; WM_COMMAND equ 0111h;
WM_PAINT equ 0fh;
WM_DESTROY equ 2h; WM_CLOSE equ 10h;
WM_NCPAINT equ 085h ;
WM_ERASEBKGND equ 14h; WM_CTLCOLOREDIT equ 133h;
WM_MOUSEMOVE equ 200h; WM_NCMOUSEMOVE equ 0A0h;
MB_OK equ 0; MB_SYSTEMMODAL equ 01000h;
EM_SETSEL equ 0b1h; SRCCOPY equ 0cc0020h;
SW_SHOW equ 5h
RDW_INVALIDATE equ 01h; RDW_INTERNALPAINT equ 02h;
RDW_ERASE equ 04h
WS_EX_CLIENTEDGE equ 200h; WS_OVERLAPPEDWINDOW equ 0cf0000h;
WS_VISIBLE equ 10000000h
FirstMessage dd 0, 0, 0, 0, 0, 0, 0
struc rect1
Left resd 1 | Top resd 1 | Right resd 1
Bottom resd 1 | Stw resd 1 | Sth resd 1
endstruc
%macro rect1_fill 7
[section .data]
%1 dd %2|dd %3|dd %4|dd %5|dd %6|dd %7
__SECT__
%endm
struc WindowClass
style resd 1|lpfnWndProc resd 1|cbClsExtra resd 1| cbWndExtra resd 1
hInstance resd 1| hIcon resd 1|hCursor resd 1|hbrBackground resd 1
lpszMenuName resd 1| lpszClassName resd 1
endstruc
%macro window_fill 11
[section .data]
%1 | dd %2|dd %3|dd %4|dd %5|dd %6|dd %7|dd %8|dd %9|dd %10|dd %11
__SECT__
%endm
window_fill wstr,3,MainWindowProc,0,0,0,0,0,6,0,WindowClassName
db, WindowClassName='Anything', WindowCaption='Base App';
dd, WindowHandle=0, MenuHandle=0, WindowX=50, WindowY=50,
WindowW=500, WindowH=350;
section .text
..start:
{pushad
[wstr+ hInstance] = *GetModuleHandleA(0);
[wstr+ hIcon] = *LoadIconA( D[wstr+hInstance] , IDI_ICON);
[wstr+ hCursor] = *LoadCursorA( 0, IDC_ARROW);
*RegisterClassA(wstr);
*MenuHandle = *LoadMenuA( D[wstr+hInstance], IDR_MENU );
*WindowHandle = *CreateWindowExA( WS_EX_CLIENTEDGE, WindowClassName,
WindowCaption, _ WS_OVERLAPPEDWINDOW || WS_VISIBLE _ ,
D*WindowX, D*WindowY, D*WindowW, D*WindowH,
0, D*MenuHandle, D[wstr+hInstance], 0);
/* 12 argomenti
*ShowWindow( D*WindowHandle, SW_SHOW);
*UpdateWindow( D*WindowHandle );
RND_RandomizeTimer(); #.L1
.While:
{*TranslateMessage(FirstMessage);
*DispatchMessageA(FirstMessage);
.L1: *GetMessageA(FirstMessage, 0, 0, 0);
a#.While
}
popad
*ExitProcess(0);
}
[section .data]
base dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
seed dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
seed0 dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
index dd 0, 0
index1 dd 0, 0
buffer times 512 db 0
__SECT__
/* void MainWindowProc(Adr, msg, wpar, lpar)
/* 0 k, 4 Ra, 8 P_Adr, 12 P_msg, 16 P_wpar, 20 P_lpar
MainWindowProc:
{< k
k = s;
<< @Adressee=[k+8], @Message=[k+12], @wParam=[k+16], @lParam=[k+20]
/*---------------------------------------
D @Message == WM_CLOSE !#.Else_If0
{*DestroyWindow( D @Adressee ); a=1; ##.fine; }
.Else_If0: D @Message == WM_DESTROY !#.Else_If1
{*PostQuitMessage(0); a=1; ##.fine; }
.Else_If1: D @Message == WM_COMMAND #.cont
##.Else
.errore:
str .j00, "Errore";
str .j01, "Devi aspettare che si inizializzino tutti i buffer
per i seeds casuali", NL,\
"Muovi il mouse sopra questa finestra!"
*MessageBoxA( 0, .j01, .j00, _ MB_OK || MB_SYSTEMMODAL _ );
a=1; ##.fine
.cont:
{ D @wParam == IDM_EXIT !#.Else_If2
{*SendMessageA( D @Adressee, WM_CLOSE, 0, 0); a=1; ##.fine}
.Else_If2: D @wParam == IDM_RANDOM !#.Else_If3
{D*index<=63 #.errore; Random(); a=1; ##.fine }
.Else_If3: D @wParam == IDM_MAX_RANDOM !#.Else_If4
{Clear();Test_random_a(RND_GaussMl, 50000);a=1; ##.fine }
.Else_If4: D @wParam == IDM_RANGE_RANDOM !#.Else_If5
{Clear();Test_random_a(RND_RangeRandom,200000);
a=1; ##.fine }
.Else_If5: D @wParam == IDM_GAUSS !#.Else_If5a
{Clear(); Test_random_a(RND_Gauss, 50000);
a=1; ##.fine }
.Else_If5a: D @wParam == IDM_LINEARE !#.Else_If5b
{Clear(); Test_random_a(RND_RangeLineare, 200000);
a=1; ##.fine }
.Else_If5b: D @wParam == IDM_LINEARE1 !#.Else_If6
{D*index<=63 #.errore;
Clear(); Test_random_a(RND_RangeMLineare, 200000);
a=1; ##.fine }
.Else_If6: D @wParam == IDM_HELP_ABOUT !#.End_Ifn
/* ...
{ str .InfoTitle, NL,\
" RND DLL Demo. (Betov).", NL,NL,\
" Original Algo from G. Adam Stanislav.", NL,NL,\
" Demonstrates SpAsm DLLs programming. ", NL,NL,\
" If you are in need of Random Routines", NL,\
" inside your Applications, and you have", NL,\
" no particular reason having them DLLed,", NL,\
" Copy / paste, instead.", NL,NL
str .titolo, "Informazione"
*MessageBoxA( 0, .InfoTitle, .titolo, _ MB_OK || MB_SYSTEMMODAL _ );
a=1; ##.fine;
}
.End_Ifn:
a=0; ##.fine;
}
.Else:
{
D*index<=63 #.v0| ##.vai
.v0: D @Message == WM_MOUSEMOVE #.fai
D @Message == WM_NCMOUSEMOVE #.fai; ##.vai
.fai: {< j
RND_RTimer_a( D @lParam );
j= *index; [base+2*j]=ax;
j&1 | jne .k0 | W [base + 2*j]|=1 /* il
numero deve essere dispari
.k0: ++D*index;
D*index==64 #.l12 | ##.l0
.l12:
{str .tit, "SetRand Base + Seeds ";
str .In, "Completato Premi OK"
*MessageBoxA( 0, .In, .tit, _ MB_OK || MB_SYSTEMMODAL _ );
j=0;
.l1:
{a=[seed + 4*j] /* Copia seed in seed0
[seed0+ 4*j]=a
++j | j<16#.l1
}
< r, b, i
b=buffer; j=0;
.l3: utoa(b, D[base+4*j]); /* Scive
la stringa dei seed in buffer
b+=a; B*b='#'; ++j; ++b;
a = b; a-=buffer; a>=490#.e0
j<32#.l3
.e0: *MessageBoxA( 0, buffer, .tit, _ MB_OK || MB_SYSTEMMODAL _ );
> r, b, i
}
.l0:
> j
}
.vai:
*DefWindowProcA( D @Adressee, D @Message, D @wParam, D @lParam);
}
.fine:
>> @Adressee, @Message, @wParam, @lParam
s = k
> k;
ret 16
}
Random:
str .titolo, "Numero Casuale" ;
RND_Random();
utoaz( .titolo, a );
ret
Random1:
str .titolo, "Numero Casuale" ;
RND_Multilinear();
utoaz( .titolo, a );
ret
str DecString, " in decimale"
/* uso: str titolo, "Numero " ; utoaz(titolo, D*num);
/* utoaz( a < char* Title, unsigned n)
/* 0 a, 4 Ra, 8 1P_Title, 12 1P_n
utoaz:
{< a
<< @Title=[s+8], @n=[s+12]
/*--------------------*/
a=@n; utoa(DecString, a);
a=@Title;
*MessageBoxA( 0, D DecString, a, _ MB_OK || MB_SYSTEMMODAL _ );
>> @Title, @n
> a
ret 8
}
/* utoa(char* string, unsigned n)
/* 0 k, 4 j, 8 i, 12 r, 16 b, 20 Ra, 24 1P_string, 28 1P_n
utoa:
{< b, r, i, j, k
<< @string=[s+24], @n=[s+28]
/*--------------------*/
i=@string; b=10; a=@n; j=i; k=0;
.utoaz_l:
{r ^= r
div b /* a= (r:a)/b r= (r:a)%b
rl+='0'; *j=rl; ++j; ++k
a#.utoaz_l
}
B*j=0; --j | #.vai
.utoaz_f:
{al=*i; ah=*j;
*j=al; *i=ah;
++i | --j;
.vai:
i<j #.utoaz_f
}
a=k;
.utoaz_z:
>> @string, @n
> b, r, i, j, k
ret 8
}
dd, hdc=0, X=0, Y=0, Color=0
rect1_fill RECT, 0,0,0,0,0,0
MaxRandom:
*GetClientRect( D*WindowHandle, RECT );
*hdc = *GetDC( D*WindowHandle );
c = 100000
.L0: { < c
*X = RND_MaxRandom(D[RECT+ Right ]);
*Y = RND_MaxRandom(D[RECT+ Bottom]);
*Color = RND_MaxRandom(0FFFFFFh);
*SetPixel( D*hdc, D*X, D*Y, D*Color);
> c
loop .L0
}
*ReleaseDC(D*WindowHandle, D*hdc);
ret
/* void Test_random(D@func, D@Points)
/* 0 k, 4Ra, 8 D@func, 12D@points (k)
Test_random_a:
{< k
k = s;
< c, b
<< @func=[k+8], @Points=[k+12]
*GetClientRect( D*WindowHandle, RECT);
*hdc = *GetDC( D*WindowHandle);
c=@Points
.L0: { < c
*X = D @func( 0, D[RECT+ Right ]);
*Y = D @func( 0, D[RECT+ Bottom]);
*Color = D @func( 0, D 0FFFFFFh);
*SetPixel( D*hdc, D*X, D*Y, D*Color);
> c
loop .L0
}
*ReleaseDC(D*WindowHandle, D*hdc);
>> @func, @Points
> c, b
s = k
> k;
ret 8
}
Clear:
*GetClientRect(D*WindowHandle, RECT );
*hdc = *GetDC( D*WindowHandle );
*FillRect( D*hdc, RECT, 0 );
ret
[section .data]
RandomPass dd 0; Rand dd 062278134h; Rb dd 0011101b
__SECT__
RND_Random:
< c, r
a=*Rand; c=*Rb;
(a,c)>>=1; ch++=0; cl>>= 1;
dl =cl; dl>>=2; dl&= 1;
ch^=dl; ch<<=6; cl|=ch;
*Rb=cl
B*RandomPass ^= 1
B*RandomPass == 1 !#.Else
{bswap a; #.End_If }
.Else:
B[RandomPass+1]^= 1
B[RandomPass+1]== 1 !#.End_If
ror eax, cl
.End_If:
*Rand=a
> c, r
ret
/_______________________________________________________
/* 0 r, 4 c, 8 Ra, 12 @Max
RND_MaxRandom:
< c, r
<< @Max=[s+12]
a=*Rand; c=*Rb;
(a,c)>>=1; ch++=0; cl>>= 1;
dl =cl; dl>>=2; dl&= 1;
ch^=dl; ch<<=6; cl|=ch;
*Rb=cl;
B*RandomPass ^= 1;
B*RandomPass == 1 !#.Else
{bswap a; #.End_If }
.Else:
B[RandomPass+1]^=1
B[RandomPass+1]== 1 !#.End_If
ror eax, cl
.End_If:
*Rand=a; c=@Max; r=0 | div c | a=r
>> @Max
> c, r
ret 4
/_____________________________________________________
/* 0 r, 4 c, 8 Ra, 12 @Min, 16 @Max
RND_RangeRandom:
< c, r
<< @Min=[s+12], @Max=[s+16]
a=*Rand; c=*Rb;
(a,c)>>=1; ch++=0; cl>>= 1;
dl =cl; dl>>=2; dl&= 1;
ch^=dl; ch<<=6; cl|=ch;
*Rb=cl;
B*RandomPass ^= 1;
B*RandomPass == 1 !#.Else
{bswap a; #.End_If }
.Else:
B[RandomPass+1]^=1
B[RandomPass+1]== 1 !#.End_If
ror eax, cl
.End_If:
*Rand=a; c=@Max; r=0; c-=@Min;
c#.nz | ++c;
.nz: div c; a=r; a+=@Min;
>> @Min, @Max
> c, r
ret 8
/* uint RND_lineare()
/* dd, .base=31415821, .seed=123;
RND_lineare:
< r
dd, .base=31415821, .seed=123;
/---------------
a = *.base;
mul D*.seed
++a;
*.seed=a;
> r
ret
/* 0 r, 4 c, 8 Ra, 12 @Min, 16 @Max
RND_RangeLineare:
< c, r
<< @Min=[s+12], @Max=[s+16]
RND_lineare();
c=@Max; c-=@Min;
c#.co|++c;
.co: r=0; div c
a=r; a+=@Min;
>> @Min, @Max
> c, r
ret 8
/* uint RND_MultiL(base, seed, seed0)
/* 0 b, 4 r, 8 c, 12 Ra, 16@Base, 20@Seed, 24@Seed0
RND_MultiL:
< c, r, b
<< @Base=[s+16], @Seed=[s+20], @Seed0=[s+24]
dd, .libero=0;
r=@Base; c=@Seed;
b=*r; a=*c; mul b; ++a;
r=@Seed0; r=*r; *c=a;
a == r !#.con
{RND_lineare(); a^=b;
a&1 | !=#.l0 | ++a;
.l0: r=@Base; *r=a; /* cambia base ma dispari
RND_lineare(); r=@Seed0; *r^=a; /* cambia seed0
a=@Seed; *a =r; a=r; /* cambia seed=seed0 e lo
ritorna
++D*.libero;
/* D*.libero < 20 !#.jj
/* {str .titolo, "Cambio di base " ; utoaz(.titolo, a);}
.jj:
}
.con:
>> @Base, @Seed, @Seed0
> c, r, b
ret 12
RND_Multilinear:
< b, c, r
a=*index1
b= &[base+ 4*a]; c= &[seed+ 4*a]; r= &[seed0+ 4*a];
RND_MultiL(b, c, r);
a>>=1; bl=ah; b&=0Fh; *index1=b;
bswap a;
> b, c, r
ret
/* 0 r, 4 c, 8 Ra, 12 @Min, 16 @Max
RND_RangeMLineare:
< c, r
<< @Min=[s+12], @Max=[s+16]
RND_Multilinear();
c=@Max; c-=@Min;
c#.co|++c;
.co: r=0; div c
a=r; a+=@Min;
>> @Min, @Max
> c, r
ret 8
/____________________________________________________
RND_RandomizeTimer:
pushad
*GetTickCount()
*Rand=al; D*Rand <<= 8
*Rand=ah; D*Rand <<= 8
*Rand=al; D*Rand <<= 8
*Rand=al; D*Rand ^= 062278134h
popad
ret
/* 0 b, 4 Ra, 8 @MousePos
RND_RTimer:
{ *GetTickCount();
a&=0FFFFh;
ret
}
/* 0b, 4 Ra, 8 @MousePos
/* 0FFFF_FFFFh F=1111
RND_RTimer_a:
{< b
<< @MousePos=[s+8]
/*-----------------------
b=@MousePos; a=@MousePos;
a>>=4; b&=0Fh; a&=0F0h; b|=a;
*GetTickCount();
a<<=8; a|=b; a&=0FFFFh;
>> @MousePos
> b
ret 4
}
/____________________________________________________
/* s' 0 k, 4 Ra, 8 @Min, 12 @Max (per k)
/* s 0 r, 4 c, 8 b, 12 k, 16 Ra, 20 @Min, 24 @Max
RND_Gauss:
< k
k = s;
< c, r, b
<< @Min=[k+8], @Max=[k+12]
RND_RangeRandom( D @Min, D @Max );
<a|RND_RangeRandom( D @Min, D @Max)|>b;
a+=b; a>>=1;
>> @Min, @Max
> c, r, b
s = k
> k
ret 8
/* s' 0 k, 4 Ra, 8 @Min, 12 @Max (per k)
/* s 0 r, 4 c, 8 b, 12 k, 16 Ra, 20 @Min, 24 @Max
RND_GaussMl:
< k
k = s;
< c, r, b
<< @Min=[k+8], @Max=[k+12]
RND_RangeMLineare( D @Min, D @Max );
<a|RND_RangeMLineare( D @Min, D @Max)|>b;
a+=b; a>>=1;
>> @Min, @Max
> c, r, b
s = k
> k
ret 8
- Next message: KiLVaiDeN: "Re: [OT] Paging Frank K. (was: 'Re: [OT] Why Bush?')"
- Previous message: Ro : "*The* definition of assembly langauge (Did you have read this?)"
- In reply to: Ro : "Re: example in nasm"
- Next in thread: Ro : "Re: example in nasm"
- Reply: Ro : "Re: example in nasm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|