flat assembler
Message board for the users of flat assembler.
Index
> Windows > Windows 32 Program Issue (Easy) Goto page 1, 2 Next |
Author |
|
AsmGuru62 06 Mar 2012, 03:30
Is that thing compiles?!...
I wrote a small console program as an example: Code: ; --------------------------------------------------------------------------- ; FILE: Conio.Asm ; DATE: March 5, 2012 ; --------------------------------------------------------------------------- format PE CONSOLE 4.0 entry start include 'Win32A.Inc' ; --------------------------------------------------------------------------- section '.data' data readable writeable nChars dd 0 invite db '--- COMMAND: ',0 strExit db 'EXIT',0Dh,0Ah,0 response rb 32 ; --------------------------------------------------------------------------- section '.code' code readable executable ; --------------------------------------------------------------------------- ; PROGRAM ENTRY POINT ; --------------------------------------------------------------------------- align 32 start: ; ; Load into EBX a handle to screen buffer ; invoke GetStdHandle, STD_OUTPUT_HANDLE mov ebx, eax ; ; Prompt user to enter a command using LIGHT GREEN color ; .ask_again: invoke SetConsoleTextAttribute, ebx, 0Ah invoke WriteConsole, ebx, invite, 13, nChars, 0 ; ; Now, wait for a user to type in a string and hit ENTER ; invoke SetConsoleTextAttribute, ebx, 0Fh invoke GetStdHandle, STD_INPUT_HANDLE mov edi, response invoke ReadConsole, eax, edi, 32, nChars, 0 ; ; Terminate entered text with zero byte ; mov eax, [nChars] mov byte [edi + eax], 0 ; ; Check if command entered is "EXIT". ; If not -- ask again! ; invoke lstrcmpi, response, strExit test eax, eax jnz .ask_again ; ; "EXIT" entered, so stop monkeying around! ; invoke ExitProcess, 0 ; --------------------------------------------------------------------------- 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' |
|||
06 Mar 2012, 03:30 |
|
drewtoby 06 Mar 2012, 15:35
That is where I was heading with the program, thanks! I may use that as a code to build upon.
As for my small code, why does it not wait for an entry and then state what was entered? How can I fix that? |
|||
06 Mar 2012, 15:35 |
|
Enko 06 Mar 2012, 16:23
Quote:
This way you don't generate an executable but a binary file with file extention .exe To run on windows you should generate a Portable Executable file format like ASMGuru did. |
|||
06 Mar 2012, 16:23 |
|
drewtoby 06 Mar 2012, 17:21
Okay, I will compile it that way. Is that the only issue? Or did I just write in psuedo-code?
If I did write in psuedo-code, what would be the best way to correct my coding for writing other codes? And thanks for the responses so far! |
|||
06 Mar 2012, 17:21 |
|
AsmGuru62 06 Mar 2012, 17:37
@drewtoby: when you say "other codes" -- that is too wide a definition.
You see, the programming is kind of precise science - especially in Assembler language. So, what exactly do you mean by "other codes"? Win API provides a way to create TWO types of EXE files: 1. Console application (which has a form I posted) 2. Window (GUI based) application. Example of which you can see in an archive provided with FASM - it is in folder called EXAMPLES and the name of it is a TEMPLATE if I remember correctly. |
|||
06 Mar 2012, 17:37 |
|
drewtoby 06 Mar 2012, 22:47
I mean the needed codes that it will take to not have the console application crash from a lack of info, even if it does compile.
I tryed playing around with your posted code, and, as usual, I can get it to compile but not run (with my changes). I always get an "app crash" error when run in windows. But your code, as posted, runs just fine =) ----------------------------------------------------------------------------------------------- I guess I am just asking how can I make a program that will not crash when I run it. ----------------------------------------------------------------------------------------------- p.s.-I will check out the GUI application too, thanks. |
|||
06 Mar 2012, 22:47 |
|
typedef 07 Mar 2012, 01:29
drewtoby wrote:
Don't beat yourself down we all came from there |
|||
07 Mar 2012, 01:29 |
|
drewtoby 07 Mar 2012, 02:22
Okay, thanks for your kind words I'll keep trying and will post again soon, I am sure!!!!
|
|||
07 Mar 2012, 02:22 |
|
AsmGuru62 07 Mar 2012, 15:09
Can you post the 'crashing' code?
|
|||
07 Mar 2012, 15:09 |
|
drewtoby 08 Mar 2012, 01:48
Code: format PE CONSOLE 4.0 include 'E:/fasmw16940/INCLUDE/Win32A.Inc' ;---------------------------------------------------------------------- section '.data' data readable writeable filename db 'test.txt',0 RichEditDLL db 'riched20.DLL', 0 hRichEditDLL dd ? vv dd ? Input dd 0 welcome db 'Welcome. Please input letters to be written to test.txt ' ,0 response rb 32 ;----------------------------------------------------------------------- section '.code' code readable executable Start: invoke GetStdHandle, STD_OUTPUT_HANDLE ;calls libaries invoke LoadLibrary, RichEditDLL mov [hRichEditDLL],eax invoke GetModuleHandle,0 mov [vv],eax align 32 invoke SetConsoleTextAttribute, ebx, 0Ah invoke WriteConsole, ebx, welcome, 13, Input, 0 ; ; Now, wait for a user to type in a string and hit ENTER ; invoke SetConsoleTextAttribute, ebx, 0Fh invoke GetStdHandle, STD_INPUT_HANDLE mov edi, response invoke ReadConsole, ecx, edi, 32, Input, 0 ;-------------------------------------------------------------------------- proc StreamIn Input ;write input to test.txt invoke WriteFile,[Input],filename,0 endp ;-------------------------------------------------------------------8------- mov eax, [Input] ;clears command/text mov byte [edi + ecx], 0 ;--------------------------------------------------------------------------- Exit: invoke ExitProcess,0 ;--------------------------------------------------------------------------- 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' It's a mix of your code above and a posted rich edit code. It will open, then windows will post app crash =( |
|||
08 Mar 2012, 01:48 |
|
revolution 08 Mar 2012, 02:06
You left out the setting of ebx
Code: invoke GetStdHandle, STD_OUTPUT_HANDLE mov ebx, eax ;<--- you need this line, else the handle in eax is lost. |
|||
08 Mar 2012, 02:06 |
|
drewtoby 08 Mar 2012, 02:57
Corrected and still crashes =( Thanks though!
Code: format PE CONSOLE 4.0 include 'E:/fasmw16940/INCLUDE/Win32A.Inc' ;---------------------------------------------------------------------- section '.data' data readable writeable filename db 'test.txt',0 RichEditDLL db 'riched20.DLL', 0 hRichEditDLL dd ? vv dd ? Input dd 0 welcome db 'Welcome. Please input letters to be written to test.txt ' ,0 response rb 32 ;----------------------------------------------------------------------- section '.code' code readable executable Start: invoke GetStdHandle, STD_OUTPUT_HANDLE ;calls libaries mov ebx, eax ;<--- you need this line, else the handle in eax is lost. invoke LoadLibrary, RichEditDLL mov [hRichEditDLL],ebx invoke GetModuleHandle,0 mov [vv],eax align 32 invoke SetConsoleTextAttribute, ebx, 0Ah invoke WriteConsole, ebx, welcome, 13, Input, 0 ; ; Now, wait for a user to type in a string and hit ENTER ; invoke SetConsoleTextAttribute, ebx, 0Fh invoke GetStdHandle, STD_INPUT_HANDLE mov ebx, eax ;<--- you need this line, else the handle in eax is lost. mov edi, response invoke ReadConsole, ecx, edi, 32, Input, 0 ;-------------------------------------------------------------------------- proc StreamIn Input ;write input to test.txt invoke WriteFile,[Input],filename,0 endp ;-------------------------------------------------------------------8------- mov eax, [Input] ;clears command/text mov byte [edi + ecx], 0 ;--------------------------------------------------------------------------- Exit: invoke ExitProcess,0 ;--------------------------------------------------------------------------- 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' |
|||
08 Mar 2012, 02:57 |
|
revolution 08 Mar 2012, 03:02
You changed this line:
Code: mov [hRichEditDLL],eax ;You need the returned value from LoadLibrary in eax here |
|||
08 Mar 2012, 03:02 |
|
drewtoby 08 Mar 2012, 13:55
Changed: still app crash...
Code: format PE CONSOLE 4.0 include 'E:/fasmw16940/INCLUDE/Win32A.Inc' ;---------------------------------------------------------------------- section '.data' data readable writeable filename db 'test.txt',0 RichEditDLL db 'riched20.DLL', 0 hRichEditDLL dd ? vv dd ? Input dd 0 welcome db 'Welcome. Please input letters to be written to test.txt ' ,0 response rb 32 ;----------------------------------------------------------------------- section '.code' code readable executable Start: invoke GetStdHandle, STD_OUTPUT_HANDLE ;calls libaries mov ebx, eax ;<--- you need this line, else the handle in eax is lost. invoke LoadLibrary, RichEditDLL mov [hRichEditDLL],eax ;You need the returned value from LoadLibrary in eax here invoke GetModuleHandle,0 mov [vv],eax align 32 invoke SetConsoleTextAttribute, ebx, 0Ah invoke WriteConsole, ebx, welcome, 13, Input, 0 ; ; Now, wait for a user to type in a string and hit ENTER ; invoke SetConsoleTextAttribute, ebx, 0Fh invoke GetStdHandle, STD_INPUT_HANDLE mov ebx, eax ;<--- you need this line, else the handle in eax is lost. mov edi, response invoke ReadConsole, ecx, edi, 32, Input, 0 ;-------------------------------------------------------------------------- proc StreamIn Input ;write input to test.txt invoke WriteFile,[Input],filename,0 endp ;-------------------------------------------------------------------8------- mov eax, [Input] ;clears command/text mov byte [edi + ecx], 0 ;--------------------------------------------------------------------------- Exit: invoke ExitProcess,0 ;--------------------------------------------------------------------------- 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' |
|||
08 Mar 2012, 13:55 |
|
revolution 08 Mar 2012, 14:04
Code: invoke ReadConsole, ecx, edi, 32, Input, 0 BTW: Even after fixing this line there are still lots more errors that you will find. |
|||
08 Mar 2012, 14:04 |
|
AsmGuru62 08 Mar 2012, 15:13
@drewtoby:
There are way too many problems in your code. 1. Why did you put a 'proc' in the middle of the code. 2. 'WriteFile' is used without actually opening a file. 3. 'WriteFile' has incorrect # of parameters. I suggest this source to study: http://msdn.microsoft.com/en-us/library/aa364232(v=vs.85).aspx You'll need at least 3 functions from there: CreateFile WriteFile CloseHandle |
|||
08 Mar 2012, 15:13 |
|
drewtoby 08 Mar 2012, 17:02
Okay, will continue to work on and post again in a day if my re-write fails. Will use your resource.
|
|||
08 Mar 2012, 17:02 |
|
Enko 08 Mar 2012, 19:38
your code doesn´t define an EntryPoint
Code:
format PE CONSOLE 4.0
start is the label name, it could be what ever name you want, but it should be a Valid Label from where your code start to execute. Check the AsmGuru example |
|||
08 Mar 2012, 19:38 |
|
drewtoby 08 Mar 2012, 21:09
Okay. One last noob question: How can I include:
Code: include 'E:\PellesC\Lib\Win64\Kernel32.lib' include 'E:/PellesC/Include/win/Windows.h' So I can use the OpenFile/CreateFile function!? NOTE: I have tried #include<> too, but neither work. |
|||
08 Mar 2012, 21:09 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.