flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Borsuc
I don't get what you mean. The above features you enumerated do not generate instructions, they more like preprocessor (although fasm has an ever previous pre-preprocessor
![]() _________________ Previously known as The_Grey_Beast |
|||
![]() |
|
sleepsleep
i mean, to put a list of example on how to use the fasm macroinstruction in a C like pattern.
eg. Code: cinvoke printf,'EAX = 0x%X',eax .if eax = 8 jmp somewhere .elseif jmp anotherwhere .endif |
|||
![]() |
|
Borsuc
Ah you're talking about .if, not if
there's a difference. |
|||
![]() |
|
sleepsleep
how to use the .while? and .wend?
i tried but to no avail ![]() anyone wanna chip in? |
|||
![]() |
|
LocoDelAssembly
sleepsleep, something like this?
Code: ; This is a reproduction of the Fahrenheit-Celsius table code from "C Programming Language (2nd Edition)" UPPER = 300 LOWER = 0 STEP = 20 format pe console entry main include 'win32ax.inc' main: sub esp, 4*3 ; Reserve space for printf arguments virtual at esp .fmt dd ? .fahr dd ? .celsius dd ? end virtual ; fahr = lower mov esi, LOWER .while esi <= UPPER ; celsius = 5 * (fahr-32) / 9 lea eax, [esi*4+esi-32*5] cdq mov ecx, 9 idiv ecx ; printf("%d\t%d\t", fahr, celsius); mov [.fmt], fmt mov [.fahr], esi mov [.celsius], eax call [printf] ; fahr = fahr + step; add esi, STEP .endw add esp, 4*3 ; Probably not required invoke ExitProcess, 0 fmt db "%d", 9,"%d", 10, 0 align 4 ; Just to be safe data import library kernel32, 'kernel32.dll',\ msvcrt,'msvcrt.dll' import kernel32,\ ExitProcess, 'ExitProcess' import msvcrt,\ printf, 'printf' end data |
|||
![]() |
|
sleepsleep
thanks loco, that is exactly what i hope this thread turns out.
more people, chips in ![]() switch, select case... how to use array ... chip in.. this thread will forsure help many people who coming from C. |
|||
![]() |
|
Enko
Complete program: http://board.flatassembler.net/topic.php?t=9398
It use the c++ runtime, msvcrt.dll Code: mov [sock_addr.sin_addr],NULL invoke bind, [sock], sock_addr,sizeof.sockaddr_in .if eax <> 0 invoke WSAGetLastError cinvoke printf, szError, eax .endif invoke listen, [sock],MAX_QUEUE accepted: ;socket listening invoke accept, [sock],peerAddr,sizePeerAddr mov [peer],eax stdcall ipToString,[peerAddr.sin_addr],szIp cinvoke printf, szClient,szIp ;new thread for each connection invoke CreateThread, NULL,NULL, resolveConnection,[peer],NULL,NULL jmp accepted invoke ExitProcess,0 ;the connection manager proc resolveConnection, lpParam local lpeer: DWORD, lbuffer: DWORD, lurl: DWORD, lfile: DWORD mov eax, [lpParam] mov [lpeer],eax cinvoke malloc, BUFFER_SIZE mov [lbuffer],eax invoke recv, [lpeer],[lbuffer],BUFFER_SIZE,0 ;if there is a message then continue .if eax <> 0 mov ebx,[lbuffer] mov byte [ebx+eax],0 .if SHOW_DETAILED_MSG cinvoke printf,szRequest, [lbuffer] .endif cinvoke strtok, [lbuffer], szTockens .if eax <> 0 ;handling the GET message .if dword[eax] = "GET" ;url sring allocation ;getting the URL from GET message cinvoke malloc, MAX_URL_SIZE mov [lurl],eax cinvoke strcpy, [lurl],szRoot cinvoke strtok, NULL, szTockens cinvoke strcat,[lurl],eax mov ebx,eax cinvoke strlen, eax mov edx,eax dec edx .repeat dec eax cmp byte[ebx+eax],"/" .if ZERO? mov byte[ebx+eax],"\" .endif .until eax = 0 .if byte[ebx+edx] = "\" cinvoke strcat,[lurl],szIndex .endif cinvoke printf, szFile, [lurl] ;opening the file to send to browser invoke CreateFile,[lurl],GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,0 ;file exists, sending,,,, .if eax <> INVALID_HANDLE_VALUE mov [lfile],eax invoke GetFileSize, [lfile],NULL invoke TransmitFile, [lpeer],[lfile],eax,NULL,NULL,transmiteBuffer,NULL .if eax cinvoke printf, szStatus, szFileSent .endif invoke CloseHandle, [lfile] .else cinvoke printf, szStatus, szFileNotExists invoke send, [lpeer], h404, h404.size, 0 .endif cinvoke free, [lurl] .endif .endif .endif .exit: cinvoke free, [lbuffer] |
|||
![]() |
|
Picnic
Here is an example of the SetConsoleCtrlHandler function that is used to install a control handler.
Code: ; Registering a Control Handler Function ; http://msdn.microsoft.com/en-us/library/ms685049(v=vs.85).aspx format pe console entry main include "win32ax.inc" macro return x { mov eax, x ret } crlf equ 13,10 section ".code" code readable executable main: invoke SetConsoleCtrlHandler, CtrlHandler, TRUE .if ( eax ) cinvoke printf, <crlf,"The Control Handler is installed.",crlf> cinvoke printf, <crlf," -- Now try pressing Ctrl+C or Ctrl+Break, or"> cinvoke printf, <crlf," try logging off or closing the console...",crlf> cinvoke printf, <crlf,"(...waiting in a loop for events...)",crlf,crlf> .while ( 1 ) .endw .else cinvoke printf, <crlf,"ERROR: Could not set control handler"> return 1 .endif return 0 proc CtrlHandler uses ecx edx, fdwCtrlType:DWORD mov eax, [fdwCtrlType] ; Handle the CTRL-C signal. .if ( eax = CTRL_C_EVENT ) cinvoke printf, <"Ctrl-C event",crlf,crlf> return TRUE ; CTRL-CLOSE: confirm that the user wants to exit. .elseif ( eax = CTRL_CLOSE_EVENT ) cinvoke printf, <"Ctrl-Close event",crlf,crlf> return TRUE ; Pass other signals to the next handler. .elseif ( eax = CTRL_BREAK_EVENT ) cinvoke printf, <"Ctrl-Break event",crlf,crlf> return FALSE .elseif ( eax = CTRL_LOGOFF_EVENT ) cinvoke printf, <"Ctrl-Logoff event",crlf,crlf> return FALSE .elseif ( eax = CTRL_SHUTDOWN_EVENT ) cinvoke printf, <"Ctrl-Shutdown event",crlf,crlf> return FALSE .endif .default: return FALSE endp section ".idata" import data readable writeable library\ kernel32, "kernel32.dll",\ msvcrt, "msvcrt.dll" import kernel32,\ SetConsoleCtrlHandler, "SetConsoleCtrlHandler" import msvcrt,\ printf, "printf" Last edited by Picnic on 23 Dec 2012, 19:57; edited 1 time in total |
|||
![]() |
|
sleepsleep
how bout some simplified example on array?
we can do it ![]() ![]() |
|||
![]() |
|
Picnic
I'm not sure if that's what you want but checkout this example by Tomasz shows how to make arrays in a HLL-ish syntax using macros.
http://board.flatassembler.net/topic.php?t=3244 |
|||
![]() |
|
sleepsleep
cool, thanks
![]() |
|||
![]() |
|
LocoDelAssembly
BTW, I haven't noticed before but this thread is in Heap. Do you think it should be moved? It should be moved to Main? Which other forum if not Main?
|
|||
![]() |
|
OzzY
I don't know the current state of FASM macros, but I guess it's possible to implement a programming language with it.
Maybe parsing the source codes to adjust to the macros when compiling, but it really helps anyway. example: stdio.h Code: ; C macros macro init_libc { jmp @f crt dd 0 @@: invoke LoadLibrary, 'MSVCRT.DLL' mov [crt], eax } macro load_C_API api { invoke GetProcAddress, [crt], api } macro unload_libc { invoke FreeLibrary, [crt] } macro main { format PE console include '%fasminc%\win32ax.inc' main: init_libc load_C_API 'printf' mov [printf], eax jmp @f printf dd 0 @@: } macro return x { unload_libc invoke ExitProcess, x .end main } ; End C macros main.asm: Code: include 'stdio.h' main ;() { cinvoke printf, <'Hello world!',13,10,0> return 0 ;} Have fun! ![]() |
|||
![]() |
|
Raedwulf
LocoDelAssembly wrote: BTW, I haven't noticed before but this thread is in Heap. Do you think it should be moved? It should be moved to Main? Which other forum if not Main? Highlevel languages? But LocoDelAssembly... sleepsleep would never find this thread if it wasn't in Heap ![]() _________________ Raedwulf |
|||
![]() |
|
sleepsleep
Quote:
![]() ![]() ![]() ![]() ![]() |
|||
![]() |
|
LocoDelAssembly
OK, there was no serious opposition to the moving and another moderator agreed via PM this thread should be in Main.
Thread moved. |
|||
![]() |
|
sleepsleep
what about the thimis (if i am correct) api and text, and he mentioned little bit about fix... any idea how to put such ... "feature" into this idea?
|
|||
![]() |
|
Picnic
sleepsleep here is how 'text' replacing 'cinvoke printf,' in Ozzy's example above, using the fix directive.
main.asm: Code: include 'stdio.h' main ;() { text fix cinvoke printf, wait1sec fix cinvoke Sleep,1000 text <'Hello world!',13,10,0> wait1sec return 0 ;} |
|||
![]() |
|
sleepsleep
thanks thimis
![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.