flat assembler
Message board for the users of flat assembler.
Index
> Main > What is FASM's equivalent of local or locals? |
Author |
|
fasmnewbie 14 Feb 2018, 00:11
locals / local is a high-level statement. Not part of FASM's internal core nor it is part of the Instruction Set. It is however a support macro usually ships with FASM distribution as separate include files that support high-level statements such PROC, etc... notably for Windows.
Code: format SomeFormat include 'win32axp.inc' or include 'proc32.inc'... proc start locals hello db 'Hello',0ah,0 endl ... ret endp or something like that |
|||
14 Feb 2018, 00:11 |
|
ar18 14 Feb 2018, 20:28
What you are saying doesn't match any of the text in the FASM Programmer's Manual, but I tried it anyways and it doesn't work. Maybe there is something else in the program that is keeping it from working:
Code: format PE64 GUI 5.0 entry start ;============================================= DEFINES include 'include/encoding/utf8.inc' include 'include/win64a.inc' include 'include/macro/proc64.inc' BUTTON1 = '1' ;MASK_FLOAT = '[+/-]?(/d+/.?/d*|/./d+)' MACRO dll %fnRtn,%fn,%p1,[%p] { reverse push %p forward call %fn mov %fnRtn,rax } dqTest dq 0 ;============================================== START section '.text' code readable executable start proc local dlg dll [dqTest],fnTest,rax,0 ret proc fnTest ret endp section '.idata' data import readable library crt,"pocrt64.dll" import crt, \ fclose,"fclose", \ ferror,"ferror", \ fopen,"fopen", \ fread,"fread", \ free,"free", \ fseek,"fseek", \ ftell,"ftell", \ fwrite,"fwrite", \ malloc,"malloc", \ realloc,"realloc", \ strcan,"strcan", \ strlen,"strlen", \ strrchr,"strrchr", \ strtok,"strtok" Notice the string that I commented out at the beginning? The MASK_FLOAT = '[+/-]?(/d+/.?/d*|/./d+)'? It came from an actual program I wrote, assembled, and ran without a problem. What's wrong with that string? FASM won't process it without giving an error that makes no sense. The FASM Progammer's Manual (pg 113, version 1.72) says that LOCAL will work but only if I specify PROC first, but I can't find any way to get LOCAL or PROC to work with start. |
|||
14 Feb 2018, 20:28 |
|
fasmnewbie 14 Feb 2018, 21:05
@ar
I don't understand what your program is for, but it looks like you're porting from NASM. I can't help you much with the content but I can make structural suggestions / corrections to cut down the number of errors you're having; Code: format PE64 GUI 5.0 ;Are you sure it's for windows, not console? entry start include 'include/encoding/utf8.inc' ;'encoding/utf8.inc' include 'include/win64a.inc' ;'win64axp.inc' include 'include/macro/proc64.inc' ;not needed. Already included above BUTTON1 = '1' ;MASK_FLOAT = '[+/-]?(/d+/.?/d*|/./d+)' ; use equ MACRO dll %fnRtn,%fn,%p1,[%p] { ;loose that %, just for code clarity. reverse push %p forward call %fn mov %fnRtn,rax } dqTest dq 0 section '.text' code readable executable start proc ;==> proc start local dlg ;incomplete syntax. Is it a DB? DQ? See my example above. dll [dqTest],fnTest,rax,0 ret ;==> missing endp proc fnTest ret endp |
|||
14 Feb 2018, 21:05 |
|
ar18 15 Feb 2018, 01:04
"It looks like you're porting from NASM"
Remind me to never try NASM then I actually have used MASM, MASM32, and GoASM. ;Are you sure it's for windows, not console? It's actually just a test to see how easy it is to write a program for FASM. I won't rewrite code for a new language until I see how well it works and how well it is documented first. ; use equ Why don't I need to use equ for BUTTON = '1'? What is FASM's rule behind that? ;loose that %, just for code clarity. GoASM suggested using it for code clarity ;incomplete syntax. Is it a DB? DQ? See my example above. I can see that now, but following your example above didn't work. This is the actual FASM rule: 1) Use :dword, :qword, :byte, etc for LOCAL 2) Use dd, dq, db, etc for LOCALS ... ENDL Anything else will not work. Also not sure if any of the above is case sensitive. I'm kind of disappointed that I can't have a default size, such as qword for PE64 and dword for PE32. I have programs where certain functions have up to thirty local vars, and with FASM it will bloat it to twice the size it was before. I do like the macro style LOCALS, since you can initialize values at the same time you define them. The following code compiles now, so thank you for your input: Code: format PE64 GUI 5.0 entry start ;============================================== DEFINES include 'include/encoding/utf8.inc' include 'include/win64a.inc' BUTTON1 = '1' MASK_FLOAT equ '[+/-]?(/d+/.?/d*|/./d+)' MACRO dll fnRtn,fn,p1,[p] { reverse push p forward call fn mov fnRtn,rax } dqTest dq 0 ;=============================================== START section '.text' code readable executable proc start local dlg:QWORD dll [dqTest],fnTest,rax,0 ret endp proc fnTest locals dlg dq ? endl ret endp section '.idata' data import readable library crt,"pocrt64.dll" import crt, \ fclose,"fclose", \ ferror,"ferror", \ fopen,"fopen", \ fread,"fread", \ free,"free", \ fseek,"fseek", \ ftell,"ftell", \ fwrite,"fwrite", \ malloc,"malloc", \ realloc,"realloc", \ strcan,"strcan", \ strlen,"strlen", \ strrchr,"strrchr", \ strtok,"strtok" I will be doing a few more tests, one of them to test the UTF8 functionality (with or w/o BOM). PS -- Obviously FASM has a method for inserting calls to DLLs, but does it have the same built-in functionality for inserting code from static libraries? |
|||
15 Feb 2018, 01:04 |
|
Furs 15 Feb 2018, 13:44
In FASM, you have two stages. First is preprocessor, which is text substitution (but much more powerful than the C preprocessor, if you're familiar with that gimped one).
EQU and DEFINE are preprocessor directives, so they can do text substitution (i.e. replace their use with anything). DEFINE is same as EQU except it doesn't substitute other symbolic constants (defined with equ or define) in its own definition (i.e. it does "raw" defines). BUTTON = '1' on the other hand is an assembler-stage directive, not preprocessor. It is numerical only. Also, assembly-time constants like this are very powerful since they can be evaluated in multiple passes (example: defining it at the end will work, FASM will do another pass for it, and optimize if something changed). In this case '1' is not a string, it's the numerical value of 1 in ASCII. Just like in C, '1' is a numerical value (character) not a string. |
|||
15 Feb 2018, 13:44 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.