flat assembler
Message board for the users of flat assembler.
Index
> Main > Comment to "Making a real-time assembler" stream |
Author |
|
ProMiNick 14 May 2020, 19:55
Tomasz, (as mostly always I watch last one offline) very nice.
I didn`t find its in any resources so reproduce it from video. (1 moment: I see in video fasmg build header,inc to 8 bytes, while mine was 4 bytes - feel that in reproduction is something wrong not lefting me) And based on this a made for fasmg.dll asmgdemo.exe (in old style, as fasm.dll used) - it is less convinient then thour last via editbox. In thour variant I added 2 rows for scroll sinchronizing of output edit (but subclassing is my week part): Code: format PE GUI 4.0 entry start include 'win32a.inc' struct MEMORY_REGION address dd ? size dd ? ends EXPRESSION_MAX_LENGTH = 32767 IDR_CALCULATOR = 37 ID_EXPRESSION = 100 ID_HEXADECIMAL = 116 ID_VERSION = 199 section '.text' code readable executable start: invoke VirtualAlloc,0,100000h,MEM_RESERVE,PAGE_READWRITE mov [aout.address],eax mov [aout.size],0 invoke VirtualAlloc,0,100000h,MEM_RESERVE,PAGE_READWRITE mov [conv.address],eax mov [conv.size],0 invoke DialogBoxParam,PE_IMAGE_BASE,IDR_CALCULATOR,HWND_DESKTOP,CalculatorDialog,0 invoke ExitProcess,0 CalculatorDialog: procedure (hwnd,msg,wparam,lparam) push ebx, esi, edi cmp [msg],WM_INITDIALOG je init cmp [msg],WM_COMMAND je command cmp [msg],WM_CLOSE je close xor eax,eax jmp finish linescroll: ; but it event of ID_EXPRESSION looks uncatchable throw parent dialog , and with what event to trigger that a question invoke SendDlgItemMessage,[hwnd],ID_EXPRESSION,EM_GETFIRSTVISIBLELINE,0,0 invoke SendDlgItemMessage,[hwnd],ID_HEXADECIMAL,EM_LINESCROLL,0,eax jmp processed init: invoke fasmg_GetVersion invoke SetDlgItemText,[hwnd],ID_VERSION,eax jmp processed command: cmp [wparam],IDCANCEL je close cmp [wparam],IDOK je processed cmp [wparam],ID_EXPRESSION + EN_CHANGE shl 16 jne processed ;invoke GetDlgItemText,[hwnd],ID_EXPRESSION,expression_buffer,EXPRESSION_MAX_LENGTH invoke fasmg_Assemble,source_string,NULL,aout,NULL,NULL,NULL test eax,eax jnz error mov eax,[aout.size] lea eax,[eax*8+8] cmp eax,[conv.size] jbe convert_output mov [conv.size],eax invoke VirtualAlloc,[conv.address],eax,MEM_COMMIT,PAGE_READWRITE test eax,eax jnz convert_output invoke VirtualFree,[conv.address],0,MEM_RELEASE invoke VirtualAlloc,0,[conv.size],MEM_COMMIT,PAGE_READWRITE test eax,eax jz error mov [conv.address],eax convert_output: mov esi,[aout.address] mov ecx,[aout.size] mov edi,[conv.address] lea ebx,[esi+ecx-4] listing: mov ecx,[ebx-4] sub ecx,[ebx] jecxz hex_ready to_hex: lodsb mov dl,al shr al,4 cmp al,10 sbb al,69h das stosb mov al,dl and al,0Fh cmp al,10 sbb al,69h das stosb mov al,' ' stosb loop to_hex hex_ready: mov ax,$0A0D stosw sub ebx,4 cmp esi,ebx jb listing xor al,al stosb invoke SetDlgItemText,[hwnd],ID_HEXADECIMAL,[conv.address] jmp processed error: invoke SetDlgItemText,[hwnd],ID_HEXADECIMAL,error_string jmp processed close: invoke EndDialog,[hwnd],0 processed: mov eax,1 finish: pop edi, esi, ebx ret endp section '.data' data readable writeable error_string: db 0 source_string: file 'header.inc' db 10 expression_buffer db EXPRESSION_MAX_LENGTH dup ? aout MEMORY_REGION conv MEMORY_REGION section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL',\ fasmg,'FASMG.DLL' import kernel,\ VirtualAlloc,'VirtualAlloc',\ VirtualFree,'VirtualFree',\ ExitProcess,'ExitProcess' import user,\ DialogBoxParam,'DialogBoxParamA',\ GetDlgItemText,'GetDlgItemTextA',\ SendDlgItemMessage,'SendDlgItemMessageA',\ SetDlgItemText,'SetDlgItemTextA',\ EndDialog,'EndDialog' import fasmg,\ fasmg_GetVersion,'fasmg_GetVersion',\ fasmg_Assemble,'fasmg_Assemble' section '.rsrc' resource data readable directory RT_DIALOG,dialogs resource dialogs,\ IDR_CALCULATOR,LANG_ENGLISH+SUBLANG_DEFAULT,calculator_dialog dialog calculator_dialog,'fasmg-powered mini assembler',100,120,400,200,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME,,,'Courier New' dialogitem 'EDIT','',ID_EXPRESSION,4,6,194,180,WS_VISIBLE+WS_BORDER+WS_TABSTOP+WS_VSCROLL+WS_HSCROLL+ES_AUTOHSCROLL+ES_MULTILINE+ES_WANTRETURN+ES_AUTOVSCROLL dialogitem 'EDIT','',ID_HEXADECIMAL,202,6,194,180,WS_VISIBLE+WS_BORDER+WS_TABSTOP+WS_VSCROLL+WS_HSCROLL+ES_READONLY+ES_MULTILINE dialogitem 'STATIC','fasm g .',-1,326,188,30,8,WS_VISIBLE+SS_RIGHT dialogitem 'STATIC','',ID_VERSION,356,188,20,8,WS_VISIBLE+SS_RIGHT enddialog whole fasmdlls use (fasmarm.dll,fasm.dll & fasmg.dll) - https://yadi.sk/d/qUsD5JzJb-3lYw _________________ I don`t like to refer by "you" to one person. My soul requires acronim "thou" instead. |
|||
14 May 2020, 19:55 |
|
bitRAKE 15 May 2020, 11:51
I tried to pass in file handles to the DLL, but it doesn't write to the file?
Code: format PE GUI 4.0 entry start include 'win32a.inc' struct MEMORY_REGION address dd ? size dd ? ends EXPRESSION_MAX_LENGTH = 32767 IDR_CALCULATOR = 37 ID_EXPRESSION = 100 ID_HEXADECIMAL = 116 ID_VERSION = 199 section '.text' code readable executable start: invoke VirtualAlloc,0,100000h,MEM_RESERVE,PAGE_READWRITE mov [aout.address],eax mov [aout.size],0 invoke VirtualAlloc,0,100000h,MEM_RESERVE,PAGE_READWRITE mov [conv.address],eax mov [conv.size],0 invoke GetModuleHandle,0 invoke DialogBoxParam,eax,IDR_CALCULATOR,HWND_DESKTOP,CalculatorDialog,0 invoke ExitProcess,0 proc CalculatorDialog hwnd,msg,wparam,lparam push ebx esi edi cmp [msg],WM_INITDIALOG je init cmp [msg],WM_COMMAND je command cmp [msg],WM_CLOSE je close xor eax,eax jmp finish linescroll: invoke SendDlgItemMessage,[hwnd],ID_EXPRESSION,EM_GETFIRSTVISIBLELINE,0,0 invoke SendDlgItemMessage,[hwnd],ID_HEXADECIMAL,EM_LINESCROLL,0,eax jmp processed init: invoke fasmg_GetVersion invoke SetDlgItemText,[hwnd],ID_VERSION,eax ; create file handles for stdout/stderr invoke CreateFile,_StdOut.txt,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_DELETE,\ 0,CREATE_ALWAYS,FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE,0 ;invoke CreateFile,_StdOut.txt,GENERIC_READ or GENERIC_WRITE,0,\ ; 0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0 mov [hStdOut],eax jmp processed command: cmp [wparam],IDCANCEL je close cmp [wparam],IDOK je processed cmp [wparam],ID_EXPRESSION + EN_CHANGE shl 16 jne processed ;invoke GetDlgItemText,[hwnd],ID_EXPRESSION,expression_buffer,EXPRESSION_MAX_LENGTH invoke SetFilePointer,[hStdOut],0,0,FILE_BEGIN mov [std_buf_read],0 invoke fasmg_Assemble,\ source_string,\ ; source string NULL,\ ; source path aout,\ ; output region NULL,\ ; output path [hStdOut],\ ; stdout [hStdOut] ; stderr test eax,eax jnz error mov eax,[aout.size] lea eax,[eax*8+8] cmp eax,[conv.size] jbe convert_output mov [conv.size],eax invoke VirtualAlloc,[conv.address],eax,MEM_COMMIT,PAGE_READWRITE test eax,eax jnz convert_output invoke VirtualFree,[conv.address],0,MEM_RELEASE invoke VirtualAlloc,0,[conv.size],MEM_COMMIT,PAGE_READWRITE test eax,eax jz error mov [conv.address],eax convert_output: mov esi,[aout.address] mov ecx,[aout.size] jecxz error mov edi,[conv.address] lea ebx,[esi+ecx-4] listing: mov ecx,[ebx-4] sub ecx,[ebx] jecxz hex_ready to_hex: lodsb mov dl,al shr al,4 cmp al,10 sbb al,69h das stosb mov al,dl and al,0Fh cmp al,10 sbb al,69h das stosb mov al,' ' stosb loop to_hex hex_ready: mov ax,$0A0D stosw sub ebx,4 cmp esi,ebx jb listing xor al,al stosb cmp [aout.address],esi jz error invoke SetDlgItemText,[hwnd],ID_HEXADECIMAL,[conv.address] jmp processed error: ; always from the start, read stdout / stderr files invoke SetFilePointer,[hStdOut],0,0,FILE_BEGIN invoke ReadFile,[hStdOut],std_buf,std_buf_bytes,std_buf_read,0 invoke SetDlgItemText,[hwnd],ID_HEXADECIMAL,std_buf;error_string jmp processed close: invoke CloseHandle,[hStdOut] invoke EndDialog,[hwnd],0 processed: mov eax,1 finish: pop edi esi ebx ret endp section '.data' data readable writeable hStdOut rd 1 ; hStdErr rd 1 std_buf_read rd 1 _StdOut.txt db "stdout.txt",0 error_string: db 0 source_string: file 'header.inc' db 10 expression_buffer db EXPRESSION_MAX_LENGTH dup ? aout MEMORY_REGION conv MEMORY_REGION std_buf_bytes = 4096 std_buf rb std_buf_bytes section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL',\ fasmg,'FASMG.DLL' import kernel,\ CloseHandle,'CloseHandle',\ CreateFile,'CreateFileA',\ GetModuleHandle,'GetModuleHandleA',\ ReadFile,'ReadFile',\ SetFilePointer,'SetFilePointer',\ VirtualAlloc,'VirtualAlloc',\ VirtualFree,'VirtualFree',\ ExitProcess,'ExitProcess' import user,\ DialogBoxParam,'DialogBoxParamA',\ GetDlgItemText,'GetDlgItemTextA',\ SendDlgItemMessage,'SendDlgItemMessageA',\ SetDlgItemText,'SetDlgItemTextA',\ EndDialog,'EndDialog' import fasmg,\ fasmg_GetVersion,'fasmg_GetVersion',\ fasmg_Assemble,'fasmg_Assemble' section '.rsrc' resource data readable directory RT_DIALOG,dialogs resource dialogs,\ IDR_CALCULATOR,LANG_ENGLISH+SUBLANG_DEFAULT,calculator_dialog dialog calculator_dialog,'fasmg-powered mini assembler',100,120,400,200,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME,,,'Courier New' dialogitem 'EDIT','',ID_EXPRESSION,4,6,194,180,WS_VISIBLE+WS_BORDER+WS_TABSTOP+WS_VSCROLL+WS_HSCROLL+ES_AUTOHSCROLL+ES_MULTILINE+ES_WANTRETURN+ES_AUTOVSCROLL dialogitem 'EDIT','',ID_HEXADECIMAL,202,6,194,180,WS_VISIBLE+WS_BORDER+WS_TABSTOP+WS_VSCROLL+WS_HSCROLL+ES_READONLY+ES_MULTILINE dialogitem 'STATIC','fasm g .',-1,326,188,30,8,WS_VISIBLE+SS_RIGHT dialogitem 'STATIC','',ID_VERSION,356,188,20,8,WS_VISIBLE+SS_RIGHT enddialog _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
15 May 2020, 11:51 |
|
Tomasz Grysztar 15 May 2020, 12:18
You only have something written to stdout when there are DISPLAY directives in source, and you only get something written to stderr when there are errors.
You have GetDlgItemText commented out, so you are only assembling header.inc without the text that is entered. After uncommenting that line and entering some text that causes an error I get the error messages showing with your sample. And if I enter DISPLAY directive, I get the display output, too. |
|||
15 May 2020, 12:18 |
|
bitRAKE 15 May 2020, 20:37
That's what I get for being up at 5am, lol.
Code: format PE GUI 4.0 entry start include 'win32a.inc' struct MEMORY_REGION address dd ? size dd ? ends EXPRESSION_MAX_LENGTH = 32767 IDR_CALCULATOR = 37 ID_EXPRESSION = 100 ID_HEXADECIMAL = 116 ID_VERSION = 199 section '.text' code readable executable start: invoke VirtualAlloc,0,100000h,MEM_RESERVE,PAGE_READWRITE mov [aout.address],eax mov [aout.size],0 invoke VirtualAlloc,0,100000h,MEM_RESERVE,PAGE_READWRITE mov [conv.address],eax mov [conv.size],0 invoke GetModuleHandle,0 invoke DialogBoxParam,eax,IDR_CALCULATOR,HWND_DESKTOP,CalculatorDialog,0 invoke ExitProcess,0 proc CalculatorDialog hwnd,msg,wparam,lparam push ebx esi edi cmp [msg],WM_INITDIALOG je init cmp [msg],WM_COMMAND je command cmp [msg],WM_CLOSE je close xor eax,eax jmp finish linescroll: invoke SendDlgItemMessage,[hwnd],ID_EXPRESSION,EM_GETFIRSTVISIBLELINE,0,0 invoke SendDlgItemMessage,[hwnd],ID_HEXADECIMAL,EM_LINESCROLL,0,eax jmp processed init: invoke fasmg_GetVersion invoke SetDlgItemText,[hwnd],ID_VERSION,eax invoke CreateFile,_StdOut.txt,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_DELETE,\ 0,CREATE_ALWAYS,FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE,0 mov [hStdOut],eax invoke CreateFile,_StdErr.txt,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_DELETE,\ 0,CREATE_ALWAYS,FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE,0 mov [hStdErr],eax jmp processed command: cmp [wparam],IDCANCEL je close cmp [wparam],IDOK je processed cmp [wparam],ID_EXPRESSION + EN_CHANGE shl 16 jne processed invoke GetDlgItemText,[hwnd],ID_EXPRESSION,expression_buffer,EXPRESSION_MAX_LENGTH invoke SetFilePointer,[hStdOut],0,0,FILE_BEGIN invoke SetFilePointer,[hStdErr],0,0,FILE_BEGIN invoke SetEndOfFile,[hStdOut] invoke SetEndOfFile,[hStdErr] invoke fasmg_Assemble,\ source_string,\ ; source string NULL,\ ; source path aout,\ ; output region NULL,\ ; output path [hStdOut],\ ; stdout [hStdErr] ; stderr test eax,eax jnz error mov eax,[aout.size] lea eax,[eax*8+8] cmp eax,[conv.size] jbe convert_output mov [conv.size],eax invoke VirtualAlloc,[conv.address],eax,MEM_COMMIT,PAGE_READWRITE test eax,eax jnz convert_output invoke VirtualFree,[conv.address],0,MEM_RELEASE invoke VirtualAlloc,0,[conv.size],MEM_COMMIT,PAGE_READWRITE test eax,eax jz error mov [conv.address],eax convert_output: mov esi,[aout.address] mov ecx,[aout.size] jecxz nobytes mov edi,[conv.address] lea ebx,[esi+ecx-4] listing: mov ecx,[ebx-4] sub ecx,[ebx] jecxz hex_ready to_hex: lodsb mov dl,al shr al,4 cmp al,10 sbb al,69h das stosb mov al,dl and al,0Fh cmp al,10 sbb al,69h das stosb mov al,' ' stosb loop to_hex hex_ready: mov ax,$0A0D stosw sub ebx,4 cmp esi,ebx jb listing xor al,al stosb cmp [aout.address],esi jz nobytes invoke SetDlgItemText,[hwnd],ID_HEXADECIMAL,[conv.address] jmp processed nobytes: invoke SetFilePointer,[hStdOut],0,0,FILE_BEGIN mov [std_buf_read],0 invoke ReadFile,[hStdOut],std_buf,std_buf_bytes,std_buf_read,0 jmp bufout error: invoke SetFilePointer,[hStdErr],0,0,FILE_BEGIN mov [std_buf_read],0 invoke ReadFile,[hStdErr],std_buf,std_buf_bytes,std_buf_read,0 bufout: mov eax,[std_buf_read] mov byte[std_buf+eax],0 invoke SetDlgItemText,[hwnd],ID_HEXADECIMAL,std_buf;error_string jmp processed close: invoke CloseHandle,[hStdOut] invoke CloseHandle,[hStdErr] invoke EndDialog,[hwnd],0 processed: mov eax,1 finish: pop edi esi ebx ret endp section '.data' data readable writeable hStdOut rd 1 hStdErr rd 1 std_buf_read rd 1 _StdOut.txt db "stdout.txt",0 _StdErr.txt db "stderr.txt",0 error_string: db 0 source_string: file 'header.inc' db 10 expression_buffer db EXPRESSION_MAX_LENGTH dup ? aout MEMORY_REGION conv MEMORY_REGION std_buf_bytes = 4096 std_buf rb std_buf_bytes section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL',\ fasmg,'FASMG.DLL' import kernel,\ CloseHandle,'CloseHandle',\ CreateFile,'CreateFileA',\ GetModuleHandle,'GetModuleHandleA',\ ReadFile,'ReadFile',\ SetEndOfFile,'SetEndOfFile',\ SetFilePointer,'SetFilePointer',\ VirtualAlloc,'VirtualAlloc',\ VirtualFree,'VirtualFree',\ ExitProcess,'ExitProcess' import user,\ DialogBoxParam,'DialogBoxParamA',\ GetDlgItemText,'GetDlgItemTextA',\ SendDlgItemMessage,'SendDlgItemMessageA',\ SetDlgItemText,'SetDlgItemTextA',\ EndDialog,'EndDialog' import fasmg,\ fasmg_GetVersion,'fasmg_GetVersion',\ fasmg_Assemble,'fasmg_Assemble' section '.rsrc' resource data readable directory RT_DIALOG,dialogs resource dialogs,\ IDR_CALCULATOR,LANG_ENGLISH+SUBLANG_DEFAULT,calculator_dialog dialog calculator_dialog,'fasmg-powered mini assembler',100,120,400,200,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME,,,'Courier New' dialogitem 'EDIT','',ID_EXPRESSION,4,6,194,180,WS_VISIBLE+WS_BORDER+WS_TABSTOP+WS_VSCROLL+WS_HSCROLL+ES_AUTOHSCROLL+ES_MULTILINE+ES_WANTRETURN+ES_AUTOVSCROLL dialogitem 'EDIT','',ID_HEXADECIMAL,202,6,194,180,WS_VISIBLE+WS_BORDER+WS_TABSTOP+WS_VSCROLL+WS_HSCROLL+ES_READONLY+ES_MULTILINE dialogitem 'STATIC','fasm g .',-1,326,188,30,8,WS_VISIBLE+SS_RIGHT dialogitem 'STATIC','',ID_VERSION,356,188,20,8,WS_VISIBLE+SS_RIGHT enddialog Instant feedback on my typos. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
15 May 2020, 20:37 |
|
ProMiNick 15 May 2020, 22:24
realy nice, bitRAKE.
What could bring this toy tool to more featured one. hang immunity: If I typed Code: repeat %t end repeat that hangs app immidiately. separate thread for compilation (and ability to terminate it by timeout|request) could solve this. for easyest thread management in one time only one compilation thread, and button that closes current thread and forces new one, It would be convinient to switch via different views (output,error,display) and to have ability to save output view in textual or binary form. |
|||
15 May 2020, 22:24 |
|
bitRAKE 15 May 2020, 22:35
At this point, I would say better to make it a pluggin to existing editor/tools. Because it needs line numbers, paste filtering, etc. It's a valuable perspective that flattens the learning curve for fasmg and x86.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
15 May 2020, 22:35 |
|
Tomasz Grysztar 16 May 2020, 10:08
Yes, making it multi-threaded might be an obvious next step - not only because someone might write something like "while 1" into source box, but also because allowing larger sources might lead to assembly times that would make response to keystrokes so slow to render it nearly unusable. With fasmg_Assemble launched in a separate thread, you could prematurely terminate it as soon as a new keystroke arrives.
bitRAKE wrote: At this point, I would say better to make it a pluggin to existing editor/tools. Because it needs line numbers, paste filtering, etc. It's a valuable perspective that flattens the learning curve for fasmg and x86. |
|||
16 May 2020, 10:08 |
|
ProMiNick 16 May 2020, 19:58
For fasm in flat editor control there are highlighted keywords. that almost useless for fasmg.
for classical fasmg macros could be helpful background-lighting of symbol context - white - global, grey - local,some other color for in-macro, more other for more nested level in-macro, and so on (that is for symbols in apropriate namespaces too). But I have no idea what could be introduced in IDE to help users understand CALM specifics.That what make them intuitive understandable. |
|||
16 May 2020, 19:58 |
|
Tomasz Grysztar 16 May 2020, 20:29
ProMiNick wrote: For fasm in flat editor control there are highlighted keywords. that almost useless for fasmg. |
|||
16 May 2020, 20:29 |
|
bitRAKE 27 Oct 2022, 20:01
I've made UI updates to asmgmini tool:
Quote: ; - size / sizing dynamics _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
27 Oct 2022, 20:01 |
|
luboput 09 Mar 2023, 17:19
not working INCLUDE
init: ; invoke GetEnvironmentVariable,'INCLUDE',std_buf,1 mov eax,11 std_buf db 'F:\FASM\inc',0,0,0,0 |
|||
09 Mar 2023, 17:19 |
|
edfed 17 Mar 2023, 04:35
time is not real.
real is not real also |
|||
17 Mar 2023, 04:35 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.