匯編程序的圖:
這幾天在學習匯編語言的圖形操作,於是想起以前用C#畫過個小八卦圖
半徑R自己給……
Graphics g = e.Graphics;
Brush fillWhiteBrush = Brushes.White;
Brush fillBlackBrush = Brushes.Black;
g.FillPie(fillWhiteBrush, 0, 0, r, r, -90, -180);//左半圓
g.FillPie(fillBlackBrush, 0, 0, r, r, 90, -180);//右半圓
g.FillEllipse(fillWhiteBrush, r/4, 0, r / 2, r / 2);//上中型圓
g.FillEllipse(fillBlackBrush, r / 4, r / 2, r / 2, r / 2);//下中型圓
g.FillEllipse(fillBlackBrush, 9*r/20, r/5, r / 20, r / 20);//左小圓
g.FillEllipse(fillWhiteBrush, 9 * r / 20, 7*r/10, r / 20, r / 20);//右小圓
win32匯編的實現中需要調用GDI的API函數來實現……
包括:畫筆(CreatePen)、畫刷(GetStockObject)、坐標定位(MoveToEx)、畫直線(LineTo)、畫橢圓(Ellipse)、畫扇形(Pie)……
注釋已經很清楚了,我就不廢話了……
繪圖核心源碼:
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;畫太極八卦
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_PaintTaiJi proc
LOCAL hBrush:HBRUSH;黑色筆刷
LOCAL wBrush:HBRUSH;白色筆刷
LOCAL hPen:HPEN;白色畫筆
;LOCAL lpPoint:LPPOINT
invoke Ellipse,hDc, 0,0,200,200;大圓
invoke GetStockObject,BLACK_BRUSH;
mov hBrush,eax;獲取黑色筆刷並保存起來
invoke GetStockObject,DC_BRUSH;
mov wBrush,eax;獲取白色筆刷並保存起來
invoke SelectObject,hDc,hBrush;選擇黑色筆刷
invoke Pie,hDc,0,0,200,200,100,0,100,200;左半個扇形
invoke Ellipse,hDc, 50,100,150,200;右半小扇形
invoke SelectObject,hDc,wBrush;選擇白色筆刷
invoke Pie,hDc,50,0,150,100,100,0,100,100;左半小扇形
invoke Ellipse,hDc, 95,145,105,155;上小圓
;將畫上小圓留下的黑色線條擦去
invoke MoveToEx,hDc,100,1,0;起始坐標移動到(100,1)處
;將白色(RGB值為:255 255 255)填充到eax
xor eax,eax
mov ah,255
mov al,255
shl eax,8
mov al,255;
invoke CreatePen,PS_SOLID,2,eax;
mov hPen,eax;
invoke SelectObject,hDc,hPen;
invoke LineTo,hDc,99,99;
;
invoke SelectObject,hDc,hBrush;選擇黑色筆刷
invoke Ellipse,hDc, 95,45,105,55;上小圓
ret
_PaintTaiJi endp
整個源碼:
匯編整個程序代碼(在RadASM調試通過)
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定義
;
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;include MyFirstApp.inc
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include Gdi32.inc
includelib Gdi32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 數據段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?;模塊句柄
hWinMain dd ?;窗口句柄
stPs PAINTSTRUCT <>;
stRect RECT <>;
hDc dd ?;
.const
szClassName db 'MyTaiJi',0;類名
szCaptionMain db '匯編畫八卦程序',0;窗口標題
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代碼段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 窗口過程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcWinMain proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
mov eax,uMsg
;********************************************************************
.if eax == WM_PAINT
invoke BeginPaint,hWnd,addr stPs
mov hDc,eax
invoke GetClientRect,hWnd,addr stRect
call _PaintTaiJi;
invoke EndPaint,hWnd,addr stPs
;********************************************************************
.elseif eax == WM_CLOSE
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
;********************************************************************
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
;********************************************************************
xor eax,eax
ret
_ProcWinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;構建窗口
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain proc
local @stWndClass:WNDCLASSEX
local @stMsg:MSG
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
;********************************************************************
; 注冊窗口類
;********************************************************************
invoke LoadCursor,0,IDC_ARROW
mov @stWndClass.hCursor,eax
push hInstance
pop @stWndClass.hInstance
mov @stWndClass.cbSize,sizeof WNDCLASSEX
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW
mov @stWndClass.lpfnWndProc,offset _ProcWinMain
mov @stWndClass.hbrBackground,COLOR_WINDOW + 1
mov @stWndClass.lpszClassName,offset szClassName
invoke RegisterClassEx,addr @stWndClass
;********************************************************************
; 建立並顯示窗口
;********************************************************************
invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
offset szClassName,offset szCaptionMain,\
WS_OVERLAPPEDWINDOW,\
100,100,600,400,\
NULL,NULL,hInstance,NULL
mov hWinMain,eax
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
invoke UpdateWindow,hWinMain
;********************************************************************
; 消息循環
;********************************************************************
.while TRUE
invoke GetMessage,addr @stMsg,NULL,0,0
.break .if eax == 0
invoke TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endw
ret
_WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;畫太極八卦
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_PaintTaiJi proc
LOCAL hBrush:HBRUSH;黑色筆刷
LOCAL wBrush:HBRUSH;白色筆刷
LOCAL hPen:HPEN;白色畫筆
;LOCAL lpPoint:LPPOINT
invoke Ellipse,hDc, 0,0,200,200;大圓
invoke GetStockObject,BLACK_BRUSH;
mov hBrush,eax;獲取黑色筆刷並保存起來
invoke GetStockObject,DC_BRUSH;
mov wBrush,eax;獲取白色筆刷並保存起來
invoke SelectObject,hDc,hBrush;選擇黑色筆刷
invoke Pie,hDc,0,0,200,200,100,0,100,200;左半個扇形
invoke Ellipse,hDc, 50,100,150,200;右半小扇形
invoke SelectObject,hDc,wBrush;選擇白色筆刷
invoke Pie,hDc,50,0,150,100,100,0,100,100;左半小扇形
invoke Ellipse,hDc, 95,145,105,155;上小圓
;將畫上小圓留下的黑色線條擦去
invoke MoveToEx,hDc,100,1,0;起始坐標移動到(100,1)處
;將白色(RGB值為:255 255 255)填充到eax
xor eax,eax
mov ah,255
mov al,255
shl eax,8
mov al,255;
invoke CreatePen,PS_SOLID,2,eax;
mov hPen,eax;
invoke SelectObject,hDc,hPen;
invoke LineTo,hDc,99,99;
;
invoke SelectObject,hDc,hBrush;選擇黑色筆刷
invoke Ellipse,hDc, 95,45,105,55;上小圓
ret
_PaintTaiJi endp
;程序入口
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
call _WinMain
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start