flat assembler
Message board for the users of flat assembler.
Index
> Main > fasm C version (as close as possible) |
Author |
|
Borsuc 14 May 2009, 21:55
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 |
|||
14 May 2009, 21:55 |
|
sleepsleep 17 May 2009, 14:11
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 |
|||
17 May 2009, 14:11 |
|
Borsuc 17 May 2009, 19:30
Ah you're talking about .if, not if
there's a difference. |
|||
17 May 2009, 19:30 |
|
sleepsleep 18 May 2009, 00:21
how to use the .while? and .wend?
i tried but to no avail anyone wanna chip in? |
|||
18 May 2009, 00:21 |
|
LocoDelAssembly 18 May 2009, 00:49
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 |
|||
18 May 2009, 00:49 |
|
sleepsleep 18 May 2009, 13:25
thanks loco, that is exactly what i hope this thread turns out.
more people, chips in come on.. switch, select case... how to use array ... chip in.. this thread will forsure help many people who coming from C. |
|||
18 May 2009, 13:25 |
|
Enko 18 May 2009, 15:15
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] |
|||
18 May 2009, 15:15 |
|
Picnic 18 May 2009, 21:20
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 |
|||
18 May 2009, 21:20 |
|
sleepsleep 19 May 2009, 00:43
how bout some simplified example on array?
we can do it come on |
|||
19 May 2009, 00:43 |
|
Picnic 19 May 2009, 07:24
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 |
|||
19 May 2009, 07:24 |
|
sleepsleep 19 May 2009, 22:07
cool, thanks thimis & tomasz
|
|||
19 May 2009, 22:07 |
|
LocoDelAssembly 08 Jun 2009, 15:13
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?
|
|||
08 Jun 2009, 15:13 |
|
OzzY 08 Jun 2009, 18:33
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! |
|||
08 Jun 2009, 18:33 |
|
Raedwulf 10 Jun 2009, 14:36
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 |
|||
10 Jun 2009, 14:36 |
|
sleepsleep 10 Jun 2009, 15:49
Quote:
its ok, please adjust it at the place it supposes to be |
|||
10 Jun 2009, 15:49 |
|
LocoDelAssembly 02 Jul 2009, 22:44
OK, there was no serious opposition to the moving and another moderator agreed via PM this thread should be in Main.
Thread moved. |
|||
02 Jul 2009, 22:44 |
|
sleepsleep 03 Jul 2009, 12:59
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?
|
|||
03 Jul 2009, 12:59 |
|
Picnic 03 Jul 2009, 17:00
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 ;} |
|||
03 Jul 2009, 17:00 |
|
sleepsleep 04 Jul 2009, 02:38
thanks thimis cool
|
|||
04 Jul 2009, 02:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.