<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>pamiętnik programisty &#187; asm</title>
	<atom:link href="http://piotr.doniec.eu/devlog/tag/asm/feed/" rel="self" type="application/rss+xml" />
	<link>http://piotr.doniec.eu/devlog</link>
	<description></description>
	<lastBuildDate>Sun, 25 Jul 2010 12:54:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Tworzenie okienka w asm</title>
		<link>http://piotr.doniec.eu/devlog/2009/09/tworzenie-okienka-w-asm/</link>
		<comments>http://piotr.doniec.eu/devlog/2009/09/tworzenie-okienka-w-asm/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 12:08:45 +0000</pubDate>
		<dc:creator>pejotr</dc:creator>
				<category><![CDATA[Programowanie]]></category>
		<category><![CDATA[asm]]></category>
		<category><![CDATA[winapi]]></category>

		<guid isPermaLink="false">http://piotr.doniec.eu/devlog/?p=244</guid>
		<description><![CDATA[Wiadomo że stworzenie okienka przy wykorzystaniu języka C i WinAPI nie jest zadaniem trudnym. Nawet w dokumentacji od MS można znaleźć gotowy przykład. Jest to natomiast zadanie bardzo żmudne i z reguły z pełnym zrozumieniem pól i dopuszczalnych wartości dla wymaganych struktur robi się to tylko raz. Potem albo się kopiuje gotowy standardowy kod wprowadzając]]></description>
			<content:encoded><![CDATA[<p>Wiadomo że stworzenie okienka przy wykorzystaniu języka C i WinAPI nie jest zadaniem trudnym. Nawet w dokumentacji od MS można znaleźć gotowy przykład. Jest to natomiast zadanie bardzo żmudne i z reguły z pełnym zrozumieniem pól i dopuszczalnych wartości dla wymaganych struktur robi się to tylko raz. Potem albo się kopiuje gotowy standardowy kod wprowadzając tylko pewne czasami zmiany odbiegającego od typowego zastosowania, albo przyjmuje że &#8222;się umie&#8221; i &#8222;zna fundament&#8221; i przesiada na WindowsForms. Ale można pójść w drugą stronę, stworzyć okienko w assmeblerze i tym samym uzyskać miano rycerza hardcoru.<span id="more-244"></span></p>
<p>Może dziwić ale zbudowanie okna korzystając z języka maszynowego nie jest trudno. Objętość programu jest zbliżona do tego utworzonego standardowo z wykorzystaniem C. Ponadto korzystając z kompilatora dostarczonego przez Microsoft (MASM) istnieje możliwość bardzo łatwego dostępu do funkcji API systemu Windows. Ponad to kompilator dostarcza wiele ułatwiających życie makr.</p>
<div class="codecolorer-container asm mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br /></div></td><td><div class="asm codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">386</span><br />
<span style="color: #000000; font-weight: bold;">.model</span> <span style="color: #000000; font-weight: bold;">flat</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">stdcall</span><br />
<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000000; font-weight: bold;">casemap</span><span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">none</span><br />
<span style="color: #000000; font-weight: bold;">include</span> &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">c</span><span style="color: #339933;">:</span>\masm32\<span style="color: #000000; font-weight: bold;">include</span>\windows<span style="color: #339933;">.</span><span style="color: #00007f; font-weight: bold;">inc</span><br />
<span style="color: #000000; font-weight: bold;">include</span> &nbsp;<span style="color: #000000; font-weight: bold;">c</span><span style="color: #339933;">:</span>\masm32\<span style="color: #000000; font-weight: bold;">include</span>\user32<span style="color: #339933;">.</span><span style="color: #00007f; font-weight: bold;">inc</span><br />
<span style="color: #000000; font-weight: bold;">includelib</span>&nbsp; <span style="color: #000000; font-weight: bold;">c</span><span style="color: #339933;">:</span>\masm32\lib\user32<span style="color: #339933;">.</span>lib<br />
<span style="color: #000000; font-weight: bold;">include</span> &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">c</span><span style="color: #339933;">:</span>\masm32\<span style="color: #000000; font-weight: bold;">include</span>\kernel32<span style="color: #339933;">.</span><span style="color: #00007f; font-weight: bold;">inc</span><br />
<span style="color: #000000; font-weight: bold;">includelib</span>&nbsp; <span style="color: #000000; font-weight: bold;">c</span><span style="color: #339933;">:</span>\masm32\lib\kernel32<span style="color: #339933;">.</span>lib<br />
<br />
WinMain <span style="color: #000000; font-weight: bold;">proto</span> <span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">DWORD</span><span style="color: #339933;">,:</span><span style="color: #000000; font-weight: bold;">DWORD</span><span style="color: #339933;">,:</span><span style="color: #000000; font-weight: bold;">DWORD</span><span style="color: #339933;">,:</span><span style="color: #000000; font-weight: bold;">DWORD</span><br />
<br />
<span style="color: #000000; font-weight: bold;">.data</span> <span style="color: #666666; font-style: italic;">; zainicjalizowanie zmienne</span><br />
&nbsp; &nbsp;ClassName <span style="color: #000000; font-weight: bold;">db</span> <span style="color: #7f007f;">&quot;SimpleWinClass&quot;</span><span style="color: #339933;">,</span>0<br />
&nbsp; &nbsp;AppName <span style="color: #000000; font-weight: bold;">db</span> <span style="color: #7f007f;">&quot;Our first Window&quot;</span><span style="color: #339933;">,</span>0<br />
<span style="color: #000000; font-weight: bold;">.data</span>?&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">; niezainicjalizowane zmienne</span><br />
&nbsp; &nbsp;hInstance HINSTANCE ?<br />
&nbsp; &nbsp;CommandLine LPSTR ?<br />
<span style="color: #000000; font-weight: bold;">.code</span><br />
&nbsp; &nbsp;start<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">invoke</span> GetModuleHandle<span style="color: #339933;">,</span>NULL<br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> hInstance<span style="color: #339933;">,</span><span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">invoke</span> WinMain<span style="color: #339933;">,</span>hInstance<span style="color: #339933;">,</span>NULL<span style="color: #339933;">,</span>CommandLine<span style="color: #339933;">,</span>SW_SHOWDEFAULT<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">invoke</span> ExitProcess<span style="color: #339933;">,</span>0<br />
&nbsp; &nbsp; &nbsp; <br />
WinMain <span style="color: #000000; font-weight: bold;">proc</span> hInst<span style="color: #339933;">:</span>HINSTANCE<span style="color: #339933;">,</span>hPrevInst<span style="color: #339933;">:</span>HINSTANCE<span style="color: #339933;">,</span>CmdLine<span style="color: #339933;">:</span>LPSTR<span style="color: #339933;">,</span>CmdShow<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">DWORD</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">LOCAL</span> wc<span style="color: #339933;">:</span>WNDCLASSEX<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">LOCAL</span> msg<span style="color: #339933;">:</span>MSG<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">LOCAL</span> hwnd<span style="color: #339933;">:</span>HWND<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>cbSize<span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">SIZEOF</span> WNDCLASSEX<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>style<span style="color: #339933;">,</span>CS_HREDRAW <span style="color: #00007f; font-weight: bold;">or</span> CS_VREDRAW<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>lpfnWndProc<span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">OFFSET</span> WndProc<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>cbClsExtra<span style="color: #339933;">,</span>NULL<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>cbWndExtra<span style="color: #339933;">,</span>NULL<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">push</span> hInstance<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">pop</span> wc<span style="color: #339933;">.</span>hInstance<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>hbrBackground<span style="color: #339933;">,</span>COLOR_WINDOW<span style="color: #339933;">+</span>1<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>lpszMenuName<span style="color: #339933;">,</span>NULL<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>lpszClassName<span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">OFFSET</span> ClassName<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">invoke</span> LoadIcon<span style="color: #339933;">,</span>NULL<span style="color: #339933;">,</span>IDI_APPLICATION<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>hIcon<span style="color: #339933;">,</span><span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>hIconSm<span style="color: #339933;">,</span><span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">invoke</span> LoadCursor<span style="color: #339933;">,</span>NULL<span style="color: #339933;">,</span>IDC_ARROW<br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> wc<span style="color: #339933;">.</span>hCursor<span style="color: #339933;">,</span><span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">invoke</span> RegisterClassEx<span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">addr</span> wc <br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">invoke</span> CreateWindowEx<span style="color: #339933;">,</span>NULL<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">ADDR</span> ClassName<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">ADDR</span> AppName<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_OVERLAPPEDWINDOW<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hInst<span style="color: #339933;">,</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL <br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> hwnd<span style="color: #339933;">,</span><span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">invoke</span> ShowWindow<span style="color: #339933;">,</span>hwnd<span style="color: #339933;">,</span>CmdShow<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">invoke</span> UpdateWindow<span style="color: #339933;">,</span>hwnd &nbsp; &nbsp;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">WHILE</span> TRUE<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">invoke</span> GetMessage<span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">ADDR</span> msg<span style="color: #339933;">,</span>NULL<span style="color: #339933;">,</span>0<span style="color: #339933;">,</span>0<br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">BREAK</span> <span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">IF</span><span style="color: #009900; font-weight: bold;">&#40;</span>!<span style="color: #00007f;">eax</span><span style="color: #009900; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">invoke</span> TranslateMessage<span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">ADDR</span> msg<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">invoke</span> DispatchMessage<span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">ADDR</span> msg<br />
&nbsp; &nbsp; <span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">ENDW</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span>msg<span style="color: #339933;">.</span>wParam &nbsp; <br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">ret</span><br />
<br />
WinMain <span style="color: #000000; font-weight: bold;">endp</span><br />
<br />
<br />
WndProc <span style="color: #000000; font-weight: bold;">proc</span> hWnd<span style="color: #339933;">:</span>HWND<span style="color: #339933;">,</span>uMsg<span style="color: #339933;">:</span>UINT<span style="color: #339933;">,</span>wParam<span style="color: #339933;">:</span>WPARAM<span style="color: #339933;">,</span>lParam<span style="color: #339933;">:</span>LPARAM<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">IF</span> uMsg==WM_DESTROY<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">invoke</span> PostQuitMessage<span style="color: #339933;">,</span>NULL<br />
&nbsp; &nbsp;<span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">ELSE</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">invoke</span> DefWindowProc<span style="color: #339933;">,</span>hWnd<span style="color: #339933;">,</span>uMsg<span style="color: #339933;">,</span>wParam<span style="color: #339933;">,</span>lParam<br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">ret</span><br />
&nbsp; &nbsp;<span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">ENDIF</span><br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">xor</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp;<span style="color: #00007f; font-weight: bold;">ret</span><br />
<br />
WndProc <span style="color: #000000; font-weight: bold;">endp</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">end</span> start</div></td></tr></tbody></table></div>
<p>Nie ma co wiele tłumaczyć. Kod jaki jest interpretowany przez MASM wygląda już niemalże jak język wysokiego poziomu(niektórzy mówią że C to język niskiego poziomu, ale to dlatego że nie umieli znaleźć określenia dla Javy, C# itp.) Bardzo fajnym makrem jest <code>invoke</code> uruchamiające zadaną procedurę i umożliwiające podanie listy argumentów poprzez rozdzielenie przecinkiem. Bardzo przyjemna alternatywa dla push&#8217;owania w odwrotnej kolejności.<br />
Jedyny wniosek jaki można wysnuć to to że jeżeli ktoś umie programować z wykorzystaniem WinAPI w C, to i bez problemu zastosuje go w assemblerze. Oczywiście nie ma obowiązku korzystania z MASM, do API można się także dostać korzystać z innych assemblerów np. NASM ( polacam zapoznanie się z nasmx).</p>
]]></content:encoded>
			<wfw:commentRss>http://piotr.doniec.eu/devlog/2009/09/tworzenie-okienka-w-asm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
