Created
March 4, 2018 20:22
-
-
Save tylerreisinger/bf71fd34da9a7428043b4ab70af790bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.586 | |
.model flat,stdcall | |
option casemap:none | |
include \masm32\include\windows.inc | |
include \masm32\include\gdi32.inc | |
include \masm32\include\user32.inc | |
include \masm32\include\kernel32.inc | |
include \masm32\include\shlwapi.inc | |
include \masm32\include\oleaut32.inc | |
include \masm32\include\ole32.inc | |
include \masm32\include\msvcrt.inc | |
includelib \masm32\lib\gdi32.lib | |
includelib \masm32\lib\user32.lib | |
includelib \masm32\lib\kernel32.lib | |
includelib \masm32\lib\shell32.lib | |
includelib \masm32\lib\oleaut32.lib | |
includelib \masm32\lib\ole32.lib | |
includelib \masm32\lib\shlwapi.lib | |
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD | |
textcpy proto :DWORD,:DWORD | |
control struct | |
Handle HWND ? | |
ID DWORD ? | |
Text BYTE 50 dup (?) | |
Class BYTE 25 dup (?) | |
control ends | |
.data | |
Text1 db "I will guess your word!",0 | |
Text2 db "Can you stump me?",0 | |
Text3 db "Directions:",0 | |
Text4 db "1. Think of an english word",0 | |
Text4a db "- Use singular nouns (not plural).",0 | |
Text5 db "2. Mix up the letters",0 | |
Text6 db "3. Enter the scrambled word in the box above",0 | |
Text7 db "4. Press the Un-scramble button",0 | |
PtrWord dd 60 dup (0) | |
Loc dd 0 | |
FontText db "Tahoma",0 | |
MBTitle db "Hi",0 | |
MBText db "Hi",0 | |
Bitmaptxt db "C:/Result.bmp",0 | |
WCName db "AsmWind",0 | |
WTitle db "Word Un-scrambler",0 | |
running DWORD 1 | |
ButtonClass db "Button",0 | |
BText db "Un-scramble",0 | |
TitleText db "Word Un-scrambler",0 | |
TBText db "Enter Scrambled Word",0 | |
TextBoxClass db "Edit",0 | |
LableClass db "Static",0 | |
ListClass db "ListBox",0 | |
BID db 1 | |
CtrName dword 5 dup (0) | |
FileH dd 0 | |
FileName db "Wordlist.lst",0 | |
FileSize dd 0 | |
TextSize dd 0 | |
CWord db 30 dup (0) | |
CorrectWord db 2000 dup (0) | |
Failedtxt db "Darn it! You win. I can't un-scramble that word. (Are you sure it's a word?)",0 | |
Titletxt db "Your word is...",0 | |
counter dd 0 | |
.data? | |
ReadIn db 2600000 dup (?) | |
rtn dd ? | |
TBuf db ? | |
hdc HDC ? | |
hInstance HINSTANCE ? | |
CommandLine LPSTR ? | |
Button1 control <> | |
TextBox1 control <> | |
.const | |
.code | |
_main proc | |
push 3 | |
call factoral | |
mov rtn,eax | |
push CommandLine | |
push SW_SHOWDEFAULT | |
push 0 | |
push hInstance | |
call WinMain | |
push 0 | |
push FileH | |
call CloseHandle | |
call ExitProcess | |
_main endp | |
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD | |
LOCAL wc:WNDCLASS | |
LOCAL msg:MSG | |
LOCAL hwnd:HWND | |
mov eax,CS_HREDRAW | |
or eax,CS_VREDRAW | |
mov wc.style,eax | |
mov wc.lpfnWndProc,offset WndProc | |
mov wc.cbClsExtra,0 | |
mov wc.cbWndExtra,0 | |
push hInst | |
pop wc.hInstance | |
mov wc.hbrBackground,COLOR_BTNFACE | |
mov wc.lpszMenuName,NULL | |
mov wc.lpszClassName,OFFSET WCName | |
push IDI_APPLICATION | |
push 0 | |
call LoadIcon | |
mov wc.hIcon,eax | |
push IDC_ARROW | |
push 0 | |
call LoadCursor | |
mov wc.hCursor,eax | |
lea eax,wc | |
push eax | |
call RegisterClass | |
push 0 | |
push hInst | |
push 0 | |
push 0 | |
push 600 ;y size | |
push 625 ;x size | |
push CW_USEDEFAULT ;initial y position | |
push CW_USEDEFAULT ;initial x position | |
push WS_OVERLAPPEDWINDOW ;Window style | |
lea eax,WTitle | |
push eax ;Window Title | |
lea eax,WCName | |
push eax ;Class name | |
push 0 | |
call CreateWindowEx | |
mov hwnd,eax | |
push SW_SHOWNORMAL | |
push hwnd | |
call ShowWindow | |
push hwnd | |
call UpdateWindow | |
;Button1 | |
push 0 | |
push hInst | |
lea eax,BID | |
push [eax] | |
mov eax,[eax] | |
mov CtrName[1],eax | |
push hwnd | |
push 20 | |
push 100 | |
push 200 | |
push 260 | |
mov eax,WS_CHILD | |
or eax,WS_VISIBLE | |
push eax | |
lea eax,BText | |
push eax | |
lea eax,ButtonClass | |
push eax | |
push 0 | |
call CreateWindowEx | |
mov Button1.Handle,eax | |
lea eax,BID | |
mov eax,[eax] | |
mov Button1.ID,eax | |
push edi | |
push esi | |
lea eax,BText | |
mov esi,eax | |
lea eax,Button1.Text | |
mov edi,eax | |
@@: | |
mov al,[esi] | |
inc esi | |
mov [edi],al | |
inc edi | |
cmp al,0 | |
jnz @B | |
pop esi | |
pop edi | |
lea eax,Button1.Class | |
push eax | |
lea eax,ButtonClass | |
push eax | |
call textcpy | |
push 0 | |
push hInst | |
push 2 | |
push hwnd | |
push 20 | |
push 200 | |
push 200 | |
push 50 | |
mov eax,WS_CHILD | |
or eax,WS_VISIBLE | |
or eax,WS_BORDER | |
push eax | |
lea eax,TBText | |
push eax | |
lea eax,TextBoxClass | |
push eax | |
push 0 | |
call CreateWindowEx | |
mov TextBox1.Handle,eax | |
mov TextBox1.ID,2 | |
lea eax,TextBox1.Class | |
push eax | |
lea eax,TextBoxClass | |
push eax | |
call textcpy | |
lea eax,TextBox1.Text | |
push eax | |
lea eax,TBText | |
push eax | |
call textcpy | |
;Open file | |
push 0 | |
push FILE_ATTRIBUTE_NORMAL | |
push OPEN_EXISTING | |
push 0 | |
push 0 | |
mov eax,GENERIC_READ | |
or eax,GENERIC_WRITE | |
push eax | |
lea eax,FileName | |
push eax | |
call CreateFile | |
mov FileH,eax | |
push 0 | |
push FileH | |
call GetFileSize | |
mov FileSize,eax | |
push 0 | |
lea eax,TBuf | |
push eax | |
push FileSize | |
lea eax,ReadIn | |
push eax | |
push FileH | |
call ReadFile | |
lea eax,ReadIn | |
lmain: | |
mov ecx,running | |
cmp ecx,0 | |
jz exit | |
push 0 | |
push 0 | |
push 0 | |
lea eax,msg | |
push eax | |
call GetMessage | |
cmp eax,0 | |
jz exit | |
lea eax,msg | |
push eax | |
call TranslateMessage | |
lea eax,msg | |
push eax | |
call DispatchMessage | |
jmp short lmain | |
exit: | |
mov eax,msg.wParam | |
ret | |
WinMain endp | |
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM | |
LOCAL ptrcnt:DWORD | |
LOCAL ps:PAINTSTRUCT | |
LOCAL tpos:RECT | |
LOCAL lgfont:LOGFONT | |
LOCAL hfont:HFONT | |
mov eax,uMsg | |
cmp eax,WM_DESTROY | |
jz MDESTROY | |
cmp eax,WM_COMMAND | |
jz MCOMMAND | |
cmp eax,WM_PAINT | |
jz MPAINT | |
mdef: | |
push lParam | |
push wParam | |
push uMsg | |
push hWnd | |
call DefWindowProc | |
ret | |
MPAINT: | |
mov tpos.left,0 | |
mov tpos.top,20 | |
mov tpos.right,425 | |
mov tpos.bottom,100 | |
mov lgfont.lfHeight, 30 | |
mov lgfont.lfWidth, 0 | |
mov lgfont.lfEscapement, 0 | |
mov lgfont.lfOrientation, 0 | |
mov lgfont.lfWeight, 0 | |
mov lgfont.lfItalic, 0 | |
mov lgfont.lfUnderline, 0 | |
mov lgfont.lfStrikeOut, 0 | |
mov lgfont.lfCharSet, 0 | |
mov lgfont.lfOutPrecision, 0 | |
mov lgfont.lfClipPrecision, 0 | |
mov lgfont.lfQuality, 0 | |
push hWnd | |
call GetDC | |
mov hdc,eax | |
lea eax,ps | |
push eax | |
push hWnd | |
call BeginPaint | |
mov hdc,eax | |
lea eax,lgfont | |
push eax | |
call CreateFontIndirect | |
mov hfont,eax | |
push eax | |
push hdc | |
call SelectObject | |
push DT_CENTER | |
lea eax,tpos | |
push eax | |
push -1 | |
lea eax,TitleText | |
push eax | |
push hdc | |
call DrawText | |
mov tpos.left,0 | |
mov tpos.top,80 | |
mov tpos.right,425 | |
mov tpos.bottom,100 | |
mov lgfont.lfHeight, 18 | |
mov lgfont.lfWidth, 0 | |
mov lgfont.lfEscapement, 0 | |
mov lgfont.lfOrientation, 0 | |
mov lgfont.lfWeight, 0 | |
mov lgfont.lfItalic, 0 | |
mov lgfont.lfUnderline, 0 | |
mov lgfont.lfStrikeOut, 0 | |
mov lgfont.lfCharSet, 0 | |
mov lgfont.lfOutPrecision, 0 | |
mov lgfont.lfClipPrecision, 0 | |
mov lgfont.lfQuality, 0 | |
lea eax,lgfont | |
push eax | |
call CreateFontIndirect | |
mov hfont,eax | |
push eax | |
push hdc | |
call SelectObject | |
push DT_CENTER | |
lea eax,tpos | |
push eax | |
push -1 | |
lea eax,Text1 | |
push eax | |
push hdc | |
call DrawText | |
mov tpos.left,0 | |
mov tpos.top,100 | |
mov tpos.right,425 | |
mov tpos.bottom,120 | |
push DT_CENTER | |
lea eax,tpos | |
push eax | |
push -1 | |
lea eax,Text2 | |
push eax | |
push hdc | |
call DrawText | |
mov tpos.left,50 | |
mov tpos.top,230 | |
mov tpos.right,300 | |
mov tpos.bottom,250 | |
push DT_LEFT | |
lea eax,tpos | |
push eax | |
push -1 | |
lea eax,Text3 | |
push eax | |
push hdc | |
call DrawText | |
mov lgfont.lfHeight, 15 | |
mov lgfont.lfWidth, 0 | |
mov lgfont.lfEscapement, 0 | |
mov lgfont.lfOrientation, 0 | |
mov lgfont.lfWeight, 0 | |
mov lgfont.lfItalic, 0 | |
mov lgfont.lfUnderline, 0 | |
mov lgfont.lfStrikeOut, 0 | |
mov lgfont.lfCharSet, 0 | |
mov lgfont.lfOutPrecision, 0 | |
mov lgfont.lfClipPrecision, 0 | |
mov lgfont.lfQuality, 0 | |
lea eax,lgfont | |
push eax | |
call CreateFontIndirect | |
mov hfont,eax | |
push eax | |
push hdc | |
call SelectObject | |
mov tpos.left,70 | |
mov tpos.top,250 | |
mov tpos.right,300 | |
mov tpos.bottom,270 | |
push DT_LEFT | |
lea eax,tpos | |
push eax | |
push -1 | |
lea eax,Text4 | |
push eax | |
push hdc | |
call DrawText | |
mov lgfont.lfHeight, 15 | |
mov lgfont.lfWidth, 0 | |
mov lgfont.lfEscapement, 0 | |
mov lgfont.lfOrientation, 0 | |
mov lgfont.lfWeight, 0 | |
mov lgfont.lfItalic, 1 | |
mov lgfont.lfUnderline, 0 | |
mov lgfont.lfStrikeOut, 0 | |
mov lgfont.lfCharSet, 0 | |
mov lgfont.lfOutPrecision, 0 | |
mov lgfont.lfClipPrecision, 0 | |
mov lgfont.lfQuality, 0 | |
lea eax,lgfont | |
push eax | |
call CreateFontIndirect | |
mov hfont,eax | |
push eax | |
push hdc | |
call SelectObject | |
mov tpos.left,80 | |
mov tpos.top,270 | |
mov tpos.right,300 | |
mov tpos.bottom,290 | |
push DT_LEFT | |
lea eax,tpos | |
push eax | |
push -1 | |
lea eax,Text4a | |
push eax | |
push hdc | |
call DrawText | |
mov lgfont.lfHeight, 15 | |
mov lgfont.lfWidth, 0 | |
mov lgfont.lfEscapement, 0 | |
mov lgfont.lfOrientation, 0 | |
mov lgfont.lfWeight, 0 | |
mov lgfont.lfItalic, 0 | |
mov lgfont.lfUnderline, 0 | |
mov lgfont.lfStrikeOut, 0 | |
mov lgfont.lfCharSet, 0 | |
mov lgfont.lfOutPrecision, 0 | |
mov lgfont.lfClipPrecision, 0 | |
mov lgfont.lfQuality, 0 | |
lea eax,lgfont | |
push eax | |
call CreateFontIndirect | |
mov hfont,eax | |
push eax | |
push hdc | |
call SelectObject | |
mov tpos.left,70 | |
mov tpos.top,290 | |
mov tpos.right,300 | |
mov tpos.bottom,310 | |
push DT_LEFT | |
lea eax,tpos | |
push eax | |
push -1 | |
lea eax,Text5 | |
push eax | |
push hdc | |
call DrawText | |
mov tpos.left,70 | |
mov tpos.top,310 | |
mov tpos.right,350 | |
mov tpos.bottom,330 | |
push DT_LEFT | |
lea eax,tpos | |
push eax | |
push -1 | |
lea eax,Text6 | |
push eax | |
push hdc | |
call DrawText | |
push 50 | |
push 50 | |
lea eax,ps | |
push eax | |
push hWnd | |
call EndPaint | |
push hdc | |
call ReleaseDC | |
ret | |
MCOMMAND: | |
mov eax,wParam | |
mov ebx,Button1.ID | |
cmp ax,bx | |
jz But1 | |
jnz EndMes | |
But1: | |
lea eax,TextBox1.Text | |
push eax | |
push 50 | |
push WM_GETTEXT | |
push TextBox1.Handle | |
call SendMessage | |
mov TextSize,eax | |
call compairwords | |
mov ebx,PtrWord | |
mov ecx,counter | |
cmp ecx,0 | |
jz wordnotfound | |
@@: | |
push esi | |
push edi | |
mov esi,PtrWord[0] | |
lea eax,CorrectWord[0] | |
mov edi,eax | |
mov ptrcnt,0 | |
mov ebx,0 | |
@@: | |
mov dl,10 | |
cmp [esi],dl | |
jz nextword | |
mov dl,0 | |
cmp [esi],dl | |
jz @F | |
mov dl,[esi] | |
inc esi | |
mov [edi],dl | |
inc edi | |
inc ebx | |
jmp @B | |
pop edi | |
pop esi | |
jmp @F | |
nextword: | |
dec ecx | |
cmp ecx,0 | |
jz @F | |
mov al,0Dh | |
mov [edi],al | |
inc edi | |
mov al,0Ah | |
mov [edi],al | |
inc edi | |
inc ptrcnt | |
push ebx | |
mov ebx,ptrcnt | |
mov esi,PtrWord[ebx*4] | |
pop ebx | |
jmp @B | |
wordnotfound: | |
lea eax,CorrectWord | |
push eax | |
lea eax,Failedtxt | |
push eax | |
call textcpy | |
@@: | |
push MB_OK | |
lea eax,Titletxt | |
push eax | |
lea eax,CorrectWord | |
push eax | |
push hWnd | |
call MessageBoxA | |
push edi | |
push ecx | |
lea eax,CorrectWord | |
mov edi,eax | |
mov ecx,0 | |
mov al,0 | |
@@: | |
mov [edi],al | |
inc ecx | |
inc edi | |
cmp ecx,1999 | |
jnz @B | |
pop ecx | |
pop edi | |
ecommand: | |
ret | |
MDESTROY: | |
push 0 | |
call PostQuitMessage | |
mov running,0 | |
ret | |
EndMes: | |
xor eax,eax | |
ret | |
WndProc endp | |
factoral proc num:DWORD | |
push ecx | |
mov ecx,num | |
mov eax,1 | |
lstart: | |
cmp ecx,0 | |
jz lend | |
mul ecx | |
dec ecx | |
jmp lstart | |
lend: | |
pop ecx | |
ret | |
factoral endp | |
textcpy proc sor:DWORD, dest:DWORD | |
push edi | |
push esi | |
mov esi,sor | |
mov edi,dest | |
@@: | |
mov al,[esi] | |
inc esi | |
mov [edi],al | |
inc edi | |
cmp al,0 | |
jnz @B | |
pop esi | |
pop edi | |
ret | |
textcpy endp | |
compairwords proc | |
LOCAL Curptr:DWORD | |
lea eax,ReadIn | |
mov Curptr,eax | |
push edx | |
push ecx | |
push ebx | |
push edi | |
push esi | |
mov ecx,0 | |
lea eax,ReadIn | |
mov esi,eax | |
lea ebx,CWord | |
mov edi,ebx | |
mov counter,0 | |
Start: | |
mov al,[esi] | |
cmp al,10 | |
jz @F | |
cmp al,0 | |
jz @F | |
inc esi | |
mov [edi],al | |
inc edi | |
inc cl | |
jmp Start | |
@@: | |
push edi ; edi - Address of word from file | |
push esi ; esi - Address of TextBox word | |
push ecx ; ecx - Word from file length | |
push edx ; edx - TextBox word length | |
push ebx ; bh - TextBox word counter bl - word from file counter | |
cmp ecx,TextSize | |
jnz exit | |
mov edi,ebx | |
lea eax,TextBox1.Text | |
mov esi,eax | |
mov edx,TextSize | |
mov ebx,0101h | |
cmpstr: | |
mov al,[esi] | |
cmp al,[edi] | |
jz eql | |
jnz noteql | |
eql: | |
cmp bh,dl | |
mov eax,1 | |
jz Wrdcor | |
mov al,1 | |
mov [edi],al | |
mov bl,1 | |
lea eax,CWord | |
mov edi,eax | |
inc esi | |
inc bh | |
jmp cmpstr | |
noteql: | |
cmp bl,cl | |
jz exit | |
inc bl | |
inc edi | |
jmp cmpstr | |
BFin: | |
pop ebx | |
pop edx | |
pop ecx | |
pop esi | |
pop edi | |
jmp Fin | |
Wrdcor: | |
mov eax,counter | |
mov esi,Curptr | |
mov PtrWord[eax*4],esi | |
inc counter | |
exit: | |
pop ebx | |
pop edx | |
pop ecx | |
pop esi | |
pop edi | |
mov al,0 | |
mov [edi],al | |
@@: | |
cmp ecx,0 | |
jz @F | |
dec ecx | |
dec edi | |
mov [edi],al | |
jmp @B | |
@@: | |
inc esi | |
mov eax,[esi] | |
cmp eax,0 | |
jz Fin | |
mov edi,ebx | |
mov ecx,0 | |
mov Curptr,esi | |
jmp Start | |
Fin: | |
mov eax,counter | |
pop esi | |
pop edi | |
pop ebx | |
pop ecx | |
pop edx | |
ret | |
compairwords endp | |
end _main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment