flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
JohnFound 02 Dec 2003, 18:54
Well, it compiles whole Fresh.
(And it builds inside Fresh fine too). Good work, Privalov. Regards |
|||
![]() |
|
Frank 02 Dec 2003, 20:31
I have a macro called "stackdata" to declare and align local variables on the stack. The macro is being used inside a "virtual at ( ebp + 8 )" / "end virtual" block. It looks like this:
Code: macro stackdata data { local ..start, ..size ..start: data ..size = $ - ..start rb (4 - (..size MOD 4)) MOD 4 } FASM 14996 compiles my original program nicely, and the executable works. But when I replace the line "rb (4 - (..size MOD 4)) MOD 4" in the above macro with "align 4", FASM complains: "error: section is not aligned enough for this operation." How can one make the internal ALIGN directive work with the stack? Regards Frank |
|||
![]() |
|
Tomasz Grysztar 02 Dec 2003, 20:38
It's because fasm doesn't know whether ESP/EBP will be aligned to 4 or not when executing your code, so it's impossible to do alignment in such virtual section. Having this knowledge you can just use such macro (which is based on the assumption that ESP/EBP are aligned to 4) - fasm will do the alignment for you only when it can be sure it will be always correct.
|
|||
![]() |
|
art_sands 02 Dec 2003, 20:40
Hi Privalov,
Nice work there. My sources compile fine too. About the example, I posted earlier for beginners. In the example, I've used your macros to hide a lot of implementation details from a total newbie. But there's somethin I wanted to ask. Is there anyway that specific macro or identifier name be made case-insensitive, so that .CODE, .code, .CoDe, and all the other variants refer to the same identifier, instead of manually creating all the variants to cover all possibilities? Regards, Art |
|||
![]() |
|
Tomasz Grysztar 02 Dec 2003, 22:12
I'm sorry, it's not possible. There was once a suggestion to make some variant of MACRO directive that would define case-insensitive macros, but that would too much complicate and slow-down the preprocessor in my opinion.
|
|||
![]() |
|
Frank 03 Dec 2003, 13:35
Privalov wrote: It's because fasm doesn't know whether ESP/EBP will be aligned to 4 or not when executing your code Oops, I overlooked the obvious. ![]() Thank you, Frank |
|||
![]() |
|
Randall Hyde 03 Dec 2003, 19:32
Hi,
I've been working on the port of HLA v1.60 to this new FASM. Assembly works fine, but when I link the code with the MS-Linker the linker crashes. Here's the code: HLA: Code: program t; label hij; @external; procedure abc; begin abc; def: hij:: end abc; begin t; jmp hij; end t; FASM output: Code: ; Assembly code emitted by HLA compiler ; Version 1.60 build 8461 (prototype) ; HLA compiler written by Randall Hyde ; FASM compatible output format MS COFF offset32 equ ptr equ ExceptionPtr__hla_ equ fs:0 include 't.extpub.inc' section '.data' data readable writeable align 16 _origin___hla_ = $ include 't.data.inc' dd 0 ;dummy to keep linker happy section '.bss' readable writeable align 16 _origin___hla_ = $ include 't.bss.inc' rb 4 ;dummy to keep linker happy section '.text' code readable executable _origin___hla_ = $ include 't.consts.inc' include 't.ro.inc' ; Code begins here: L1_abc__hla_ : push ebp ;/*Dynamic link*/ push dword ptr [ebp-4] ;/*Display for lex level 0*/ lea ebp,[esp+4] ;/*Get frame ptr*/ push ebp ;/*Ptr to this proc's A.R.*/ and esp, 0fffffffch L2_def__hla_: hij: xL1_abc__hla___hla_: mov esp, ebp pop ebp ret ;L1_abc__hla_ endp HWexcept__hla_ : jmp shorthwExcept__hla_ ;HWexcept__hla_ endp DfltExHndlr__hla_: jmp shortDfltExcept__hla_ ;DfltExHndlr__hla_ endp _HLAMain : ;/* Set up the Structured Exception Handler record */ ;/* for this program. */ call BuildExcepts__hla_ pushd 0 ;/* No Dynamic Link. */ mov ebp, esp ;/* Pointer to Main's locals */ push ebp ;/* Main's display. */ jmp hij QuitMain__hla_: pushd 00h call dword ptr [__imp__ExitProcess@4] ;_HLAMain endp ;*************************************************** ; t.data.inc label MainPgmCoroutine__hla_ byte dd MainPgmVMT__hla_ dd 00h ;/* CurrentSP */ dd 00h ;/* Pointer to stack */ dd 00h ;/* ExceptionContext */ dd 00h ;/* Pointer to last caller */ label MainPgmVMT__hla_ word dd QuitMain__hla_ ; t.extpub.inc extrn __imp__MessageBoxA@16:dword extrn __imp__ExitProcess@4:dword section '.text' code readable executable align 16 extrn shorthwExcept__hla_ extrn abstract__hla_ extrn BuildExcepts__hla_ extrn Raise__hla_ extrn shortDfltExcept__hla_ public hij public MainPgmCoroutine__hla_ public DfltExHndlr__hla_ public _HLAMain public HWexcept__hla_ The other include files are empty. Here's the output from MS-Link: Code: Compiling "t.hla" to "t.asm" Compilation complete, 19 lines, 0.001 seconds, 19000 lines/second Assembling "t.asm" to "t.obj" via [fasm "t.asm" "t.obj"] flat assembler version 1.49.9.6 3 passes, 851 bytes. Linking via [link @t.link._.link] Microsoft (R) Incremental Linker Version 6.00.8168 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. -heap:0x1000000,0x1000000 -stack:0x1000000,0x1000000 -base:0x4000000 -entry:HLAMain -section:.text,ER -section:.data,RW -section:.bss,RW kernel32.lib user32.lib gdi32.lib -subsystem:console -out:t.exe d:\hla\hlalib\hlalib.lib t.obj t.obj : error : Internal error during Pass2 ExceptionCode = C0000005 ExceptionFlags = 00000000 ExceptionAddress = 0040C6D2 NumberParameters = 00000002 ExceptionInformation[ 0] = 00000000 ExceptionInformation[ 1] = FDFC00DC CONTEXT: Eax = 000000DC Esp = 0012F684 Ebx = 00329A40 Ebp = 02940000 Ecx = 00A50000 Esi = FDFC00DC Edx = 02940000 Edi = 00981000 Eip = 0040C6D2 EFlags = 00010206 SegCs = 0000001B SegDs = 00000023 SegSs = 00000023 SegEs = 00000023 SegFs = 00000038 SegGs = 00000000 Dr0 = 0012F684 Dr3 = 00329A40 Dr1 = 02940000 Dr6 = 00A50000 Dr2 = 00000000 Dr7 = 00000000 Error returned by link = -2 One thing I've noticed is a case problem with the external symbols. I'll look into that. In the meantime, just thought I'd pass this along. Cheers, Randy Hyde |
|||
![]() |
|
Randall Hyde 03 Dec 2003, 19:44
Privalov wrote: The ALIGN directive performs the alignment by filling the space up to the alignment boundary with the undefined bytes (which are zeroed if they are included in the output files). If you need it to fill with the NOPs for example, when you need to align some place inside the code, you can use such macro: Why not just fill the gaps with NOPs in general? That would certainly be the safest solution. Cheers, Randy Hyde |
|||
![]() |
|
Randall Hyde 03 Dec 2003, 20:04
Consider the following HLA v1.60 output, fed through the prerelease FASM:
Code: ; Assembly code emitted by HLA compiler ; Version 1.60 build 8466 (prototype) ; HLA compiler written by Randall Hyde ; FASM compatible output format MS COFF macro codeAlign value { local ..size virtual @@: align value ..size = $-@b end virtual times ..size nop } offset32 equ ptr equ ExceptionPtr__hla_ equ fs:0 include 't.extpub.inc' section '.data' data readable writeable align 16 _origin___hla_ = $ include 't.data.inc' dd 0 ;dummy to keep linker happy section '.bss' readable writeable align 16 _origin___hla_ = $ include 't.bss.inc' rb 4 ;dummy to keep linker happy section '.text' code readable executable align 16 _origin___hla_ = $ include 't.consts.inc' include 't.ro.inc' ; Code begins here: align 16 L1_abc__hla_ : push ebp ;/*Dynamic link*/ push dword ptr [ebp-4] ;/*Display for lex level 0*/ lea ebp,[esp+4] ;/*Get frame ptr*/ push ebp ;/*Ptr to this proc's A.R.*/ and esp, 0fffffffch L2_def__hla_: hij: xL1_abc__hla___hla_: mov esp, ebp pop ebp ret ;L1_abc__hla_ endp HWexcept__hla_ : jmp shorthwExcept__hla_ ;HWexcept__hla_ endp DfltExHndlr__hla_: jmp shortDfltExcept__hla_ ;DfltExHndlr__hla_ endp _HLAMain : ;/* Set up the Structured Exception Handler record */ ;/* for this program. */ call BuildExcepts__hla_ pushd 0 ;/* No Dynamic Link. */ mov ebp, esp ;/* Pointer to Main's locals */ push ebp ;/* Main's display. */ codeAlign 0x10 jmp hij QuitMain__hla_: pushd 00h call dword ptr [__imp__ExitProcess@4] ;_HLAMain endp FASM complains that the "codeAlign 0x10" invocation at the end of this sequence cannot be done because the section is not aligned enough... Code: D:\hla>hla -sf -fasm t flat assembler version 1.49.9.6 t.asm [87]: codeAlign 0x10 t.asm [12] codeAlign [3]: @@: align value error: section is not aligned enough for this operation. Error returned by Assembler = 2 As you can see, the declaration for the text segment is "align 16". Shouldn't this work? Cheers, Randy Hyde |
|||
![]() |
|
Tomasz Grysztar 03 Dec 2003, 23:42
Great thanks for your reports, Randy! I have fixed two bugs that were probably the source of your problems. I have also made it fill the alignment area with NOPs, so no macro for code alignment will be needed (unless you want to do some advanced code alignment tricks, like using combinations of instructions like "lea eax,[eax]"). Please check the updated fasm 1.49.9.7 from above.
|
|||
![]() |
|
JohnFound 04 Dec 2003, 04:33
Privalov wrote: I have also made it fill the alignment area with NOPs, so no macro for code alignment will be needed. Hi Privalov. Maybe I am missing something, but what if the align directive is used at the middle of the uninitialised data section - there will be some place filled with $90 and this will turn it to initialised data section. Or not? Regards |
|||
![]() |
|
Tomasz Grysztar 04 Dec 2003, 09:59
Please try.
![]() |
|||
![]() |
|
Vortex 04 Dec 2003, 11:03
Hi Privalov,
Have you any advancement on string manipulation macros? http://board.flatassembler.net/topic.php?p=3388#3388 _________________ Code it... That's all... |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.