flat assembler
Message board for the users of flat assembler.
Index
> Main > Getting started "this way" Goto page 1, 2 Next |
Author |
|
HaHaAnonymous 07 Nov 2013, 14:06
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 19:10; edited 1 time in total |
|||
07 Nov 2013, 14:06 |
|
schlukhash 07 Nov 2013, 15:29
It is a good way to start, Thanks!
"Haha, that will surely help you!" processing signals |
|||
07 Nov 2013, 15:29 |
|
schlukhash 08 Nov 2013, 16:31
Jeez what a day, completely worn out cant do nothing with it yet..
|
|||
08 Nov 2013, 16:31 |
|
cod3b453 08 Nov 2013, 17:52
You will want to look at Intel 's Developer Manual Volumes 1 and 2(A/B) and AMD Programmer's Manual Volumes 3 and 4. Another useful quick reference can be found here: http://ref.x86asm.net/.
The macro syntax is specific to FASM - you can see examples in the includes subdirectory or look/ask around this forum. |
|||
08 Nov 2013, 17:52 |
|
shutdownall 08 Nov 2013, 18:56
schlukhash wrote:
I am new to SIMD and would be greatly looking forward to read some tutorials here about it and about mathematics background. A very warm welcome ! |
|||
08 Nov 2013, 18:56 |
|
Tomasz Grysztar 08 Nov 2013, 19:28
schlukhash wrote: Also is there an instruction chart i can print and store somewhere? I think it is the best one that was ever posted here. |
|||
08 Nov 2013, 19:28 |
|
tthsqe 09 Nov 2013, 08:30
Quote: SIMD + math That's my kind of thing! If you want to look into the simd instructions, I would suggest fractal image generation (mandelbrot, julia sets, ect.). I have posted several fractal generators throughout the board, and the best one so far is at http://board.flatassembler.net/topic.php?t=15436 |
|||
09 Nov 2013, 08:30 |
|
schlukhash 10 Nov 2013, 15:13
@ cod3b453/Tomasz Grysztar Thanks! to the printer it goes.
@ shutdownall, Given I have some free time next weekend ill be happy to oblige. Think it will be simple to get along with it. For audio I usually move 4 32bit words around, been learning something about double words from tthsqe's example. @ tthsqe, Those are some nice fractals. One of the best ive seen in years! Seems the ASM has no trouble what so ever crunching those numbers With the example i get lost trying to find out how gui implementations work. Are there some examples around on how to load a bitmap, or create a mouse clickable area "button"? |
|||
10 Nov 2013, 15:13 |
|
shutdownall 10 Nov 2013, 21:05
schlukhash wrote: Are there some examples around on how to load a bitmap, or create a mouse clickable area "button"? Download the examples in flatassemblers example section: http://www.flatassembler.net/examples.php I had many ideas from examples. You can compile the fasm/examples installed with FASM too very easy (just load, compile and execute). |
|||
10 Nov 2013, 21:05 |
|
tthsqe 10 Nov 2013, 21:32
schlukhash,
I don't think the standard fasm examples include something about bitmaps. It does take a while to learn the windowz api functions, and I have converged on the following method. This example draws an animated ellipse (the GUI specific code is after the Start label): Code: format PE GUI 5.0 entry Start include 'win32axp.inc' DIB_RGB_COLORS = 0 section '.code' code readable executable align 16 SquaredDistanceEstimate: ; plotting F(x,y)=0 ; given x at xmm0 and y at xmm1 (double precision), this should return F(x,y)^2/(gradF(x,y).gradF(x,y)) in xmm0 (single precision) ; for F(x,y) = x^2+a y^2-1, this is (x^2+a y^2-1)^2/((2x)^2+(2a y)^2) mulsd xmm0,xmm0 mulsd xmm1,xmm1 mulsd xmm1,[a] movsd xmm2,xmm1 mulsd xmm2,[a] addsd xmm1,xmm0 addsd xmm2,xmm0 subsd xmm1,[.const_1] mulsd xmm1,xmm1 mulsd xmm2,[.const_4] cvtsd2ss xmm0,xmm1 cvtsd2ss xmm1,xmm2 rcpss xmm1,xmm1 mulss xmm0,xmm1 ret align 8 .const_1: dq 1.0 .const_4: dq 4.0 align 16 ConvertToGrey: ; given # at xmm0, convert to color in eax ; min(255,1.5*255/(1+#)) mov eax,3*128 mov ecx,255 cvtsi2ss xmm1,eax rcpss xmm0,xmm0 mulss xmm1,xmm0 cvtss2si eax,xmm1 cmp eax,ecx cmova eax,ecx mov ecx,0x00010101 imul ecx ret ; these are the size of the plotted region and the width of the line align 8 scale dq 2.0 width dq 1.0 DrawBitmap: push ebp mov ebp,esp sub esp,8*8 virtual at ebp-8*8 xmin dq ? xmax dq ? xstep dq ? ymin dq ? ymax dq ? ystep dq ? fac dd ? end virtual ; a = 2 + sin(t/500) invoke GetTickCount mov dword[esp-4],eax fild dword[esp-4] mov dword[esp-4],500 fild dword[esp-4] fdivp st1,st0 fsin fld1 fadd st1,st0 faddp st1,st0 fstp qword[a] ; find the window fild [Bitmap.x] fild [Bitmap.y] fdivp st1,st0 fsqrt fld [scale] fld st0 fmul st0,st2 fst [xmax] fchs fstp [xmin] fdivrp st1,st0 fst [ymax] fchs fstp [ymin] ; find the pixel fac fild [Bitmap.x] fild [Bitmap.y] fmulp st1,st0 fld [xmax] fld [xmin] fsubp st1,st0 fld [ymax] fld [ymin] fsubp st1,st0 fmulp st1,st0 fld [width] fmulp st1,st0 fdivp st1,st0 fstp [fac] ; find xstep and ystep fld [xmax] fld [xmin] fsubp st1,st0 fild [Bitmap.x] fdivp st1,st0 fstp [xstep] fld [ymax] fld [ymin] fsubp st1,st0 fild [Bitmap.y] fdivp st1,st0 fstp [ystep] ; fill the bitmap mov ebx,[ppvBits] mov esi,[Bitmap.y] .l1: mov edi,[Bitmap.x] .l2: movsd xmm0,[xmax] movsd xmm1,[ymax] cvtsi2sd xmm2,edi cvtsi2sd xmm3,esi mulsd xmm2,[xstep] mulsd xmm3,[ystep] subsd xmm0,xmm2 ; x subsd xmm1,xmm3 ; y call SquaredDistanceEstimate mulss xmm0,[fac] call ConvertToGrey mov [ebx],eax add ebx,4 sub edi,1 jnz .l2 sub esi,1 jnz .l1 mov esp,ebp pop ebp ret ;;;;;;;;;;;;;;;;;;;; this is all standard stuff to open the window ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Start: invoke GetModuleHandle,0 mov [wc.hInstance],eax mov [hInstance],eax invoke LoadIcon,0,IDI_APPLICATION mov [wc.hIcon],eax invoke LoadCursor,0,IDC_ARROW mov [wc.hCursor],eax invoke RegisterClass,wc test eax,eax jz Error invoke CreateWindowEx,0,MainWindowClass,MainWindowTitle,WS_VISIBLE+WS_OVERLAPPEDWINDOW,100,100,600,600,NULL,NULL,[wc.hInstance],NULL mov [hMainWindow],eax test eax,eax jz Error .MsgLoop: invoke PeekMessage,msg,NULL,0,0,PM_REMOVE cmp [msg.message],WM_QUIT je .EndLoop invoke TranslateMessage,msg invoke DispatchMessage,msg add byte[PaintTimer],8 jnz .MsgLoop call Paint invoke Sleep,20 jmp .MsgLoop .EndLoop: invoke ExitProcess,[msg.wParam] Error: invoke MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK invoke ExitProcess,0 proc WindowProc hwnd,wmsg,wparam,lparam push esi edi ebx cmp [wmsg],WM_CREATE je .wmcreate cmp [wmsg],WM_PAINT je .wmpaint cmp [wmsg],WM_SIZE je .wmsize cmp [wmsg],WM_DESTROY je .wm_destroy .defwndproc: invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] jmp .return .wmcreate: .wmsize: invoke GetClientRect,[hwnd],rect mov eax,[rect.right] test eax,eax jz .returnz mov eax,[rect.right] mov ecx,[rect.bottom] mov [Bitmap.x],eax mov [Bitmap.y],ecx mov ecx,[hBitmap] test ecx,ecx jz .wmpaint_newbm jmp .wmpaint_redobm .wmpaint: invoke GetClientRect,[hMainWindow],rect mov eax,[rect.right] mov ecx,[hBitmap] test eax,eax jz .returnz test ecx,ecx jz .wmpaint_newbm .wmpaint_ok: call Paint jmp .returnz .wmpaint_redobm: invoke DeleteObject,[hBitmap] .wmpaint_newbm: mov [bmiheader.biSize],sizeof.BITMAPINFOHEADER mov eax,[Bitmap.x] mov [bmiheader.biWidth],eax mov eax,[Bitmap.y] neg eax mov [bmiheader.biHeight],eax mov [bmiheader.biPlanes],1 mov [bmiheader.biBitCount],32 mov [bmiheader.biCompression],BI_RGB mov eax,[Bitmap.x] imul eax,[Bitmap.y] lea eax,[4*eax+16] mov [bmiheader.biSizeImage],eax mov [bmiheader.biXPelsPerMeter],0 mov [bmiheader.biYPelsPerMeter],0 mov [bmiheader.biClrUsed],0 mov [bmiheader.biClrImportant],0 invoke CreateDIBSection,0,bmiheader,DIB_RGB_COLORS,ppvBits,0,0 mov [hBitmap],eax jmp .wmpaint_ok .wm_destroy: invoke PostQuitMessage,0 .returnz: xor eax,eax .return: pop ebx edi esi ret endp Paint: cmp [hBitmap],0 je .Done invoke InvalidateRect,[hMainWindow],rect,FALSE invoke BeginPaint,[hMainWindow],ps mov [hdc],eax invoke CreateCompatibleDC,eax test eax,eax jz Error mov [hMemDC],eax call DrawBitmap invoke SelectObject,[hMemDC],[hBitmap] invoke BitBlt,[hdc],0,0,[rect.right],[rect.bottom],[hMemDC],0,0,SRCCOPY invoke DeleteDC,[hMemDC] invoke EndPaint,[hMainWindow],ps .Done: ret section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ gdi32,'GDI32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' include 'api\gdi32.inc' section '.data' data readable writeable align 4 wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,MainWindowClass align 1 MainWindowTitle db 'plot', 0 MainWindowClass db 'plot32', 0 _error TCHAR 'Startup failed.',0 align 8 a dq 2.0 align 4 hMainWindow dd ? hStatusWindow dd ? hMainMenu dd ? hInstance dd ? ppvBits dd ? hMemDC dd ? hdc dd ? hBitmap dd ? Bitmap.x dd ? Bitmap.y dd ? TickCount dd ? bmiheader BITMAPINFOHEADER ps PAINTSTRUCT rc RECT rect RECT msg MSG align 1 PaintTimer db ? |
|||
10 Nov 2013, 21:32 |
|
schlukhash 13 Nov 2013, 13:14
An intermediate thanks for this! Have to find the time to pick it apart for a bit. So ill get back at it as soon as possible.
|
|||
13 Nov 2013, 13:14 |
|
tthsqe 13 Nov 2013, 15:46
Oops, apparently I wrote that example before I learned about the red zone.
Code: mov dword[esp-4],eax fild dword[esp-4] mov dword[esp-4],500 fild dword[esp-4] Maybe this is not safe. Hopefully someone who knows better can comment... Code: push eax fild dword[esp] push 500 fild dword[esp] pop eax pop eax |
|||
13 Nov 2013, 15:46 |
|
baldr 14 Nov 2013, 15:26
tthsqe wrote: Maybe this is not safe. Code: push eax fild dword[esp] mov dword[esp], 500 fild dword[esp] pop eax As a rule of thumb, better be safe than sorry. P.S. Your (new) indenting style is quite interesting (not tab-friendly though), it worth some research. |
|||
14 Nov 2013, 15:26 |
|
Alessio 15 Nov 2013, 08:35
Hi tthsqe,
I've some questions rearding you code. Why you add 16 on bmiheader.biSizeImage ? it is related to lea opcode ? Why you use hMainWindow in wmpaint ? You can use hwnd instead. Can this code be easily adapted to plot curves ? Any hint ? Thank you. |
|||
15 Nov 2013, 08:35 |
|
tthsqe 15 Nov 2013, 08:55
Quote: Why you add 16 on bmiheader.biSizeImage ? it is related to lea opcode ? While only 4*[Bitmap.x]*[Bitmap.y] bytes are taken up by the pixels, I leave an extra 16 bytes because I might be using simd instructions to fill in the array and it might go over a little bit as a matter of convenience. You never know what could happen if you write past your allotted space. Quote: Why you use hMainWindow in wmpaint ? You can use hwnd instead. I guess so - I could try to correct this issue. Quote: Can this code be easily adapted to plot curves ? Any hint ? yup, you need to change SquaredDistanceEstimate. x is in xmm0, and y is in xmm1 (scalar doubles). The squared distance estimate should be returned in xmm0 (scalar single). if you are plotting f(x,y) = 0 then Code: SquaredDistanceEstimate = f(x,y)^2 / (fx(x,y)^2+fy(x,y)^2) where fx and fy are the partial derivatives. This formula will not work well for curves with singularities, so maybe an epsilon should be added in to the denominator. |
|||
15 Nov 2013, 08:55 |
|
schlukhash 25 Nov 2013, 15:30
Ok.. Back at it, As you see my asm budget is very limited
Got a bit confused about the double logarithm on what seems to be an empty register? But im not at all familiar with the ret command. Is this the same as a loop written like this? Code: movaps xmm1,train addps xmm1,F1 movaps xmm2,xmm1 cmpps xmm1,MEM,5 andps xmm1,train subps xmm2,xmm1 movaps train,xmm2 Edit: Not that I am confused about "what I presume to be processing the circle" well a little But more the moving nothing to multiply with nothing. Which should be something multpilied by [A]. |
|||
25 Nov 2013, 15:30 |
|
tthsqe 26 Nov 2013, 11:45
I don't know what you are talking about with the double log, though, I do have some comments on the code you posted:
Code: if !(a + b < c) a = b else a = a + b end if ; the subraction introduces an unnecessary loss of precision movaps xmm1,a addps xmm1,b movaps xmm2,xmm1 cmpnltps xmm1,c andps xmm1,a subps xmm2,xmm1 movaps a,xmm2 ; better solution movaps xmm0,a addps xmm0,b cmpltps xmm0,c andps xmm0,a addps xmm0,b movaps a,xmm0 |
|||
26 Nov 2013, 11:45 |
|
schlukhash 26 Nov 2013, 15:13
In your code you say.
Code: mulsd xmm0,xmm0 //but this register seems to be empty mulsd xmm1,xmm1 // as well as this one mulsd xmm1,[a] // Atleast i dont find where these numbers come from movsd xmm2,xmm1 mulsd xmm2,[a] But.. Noted, would be cmpleps then. A=(A+1)-(A>=B)&A |
|||
26 Nov 2013, 15:13 |
|
edfed 26 Nov 2013, 18:31
schlukhash wrote: Hello all! You will not be platform independant if you code in assembler. i am interrested in vst also, can you post an example of vst synth to see how it looks like? All the best to you too |
|||
26 Nov 2013, 18:31 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.