flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
vid 07 Jun 2006, 13:36
hi, can't find good old align macro.
i just need to formula to calculate, how many bytes to fill to align something to some given value ![]() |
|||
![]() |
|
LocoDelAssembly 07 Jun 2006, 13:44
bytesToFill = $ mod alignValue ?
|
|||
![]() |
|
vid 07 Jun 2006, 13:54
no, byt maybe alignval - ($ mod alignval) seems a little better, except case when $ mod alignval is 0. I want that elegant form from old align macro
![]() |
|||
![]() |
|
Quantum 07 Jun 2006, 14:20
(($ + alignval - 1) and -alignval) - $
BTW, what happened to good old align directive? |
|||
![]() |
|
vid 07 Jun 2006, 14:22
it's not for FASM coding. i just needed algorithm.
good not-that-old align directive is still working |
|||
![]() |
|
vid 07 Jun 2006, 14:28
it's not for FASM coding. i just needed algorithm.
good not-that-old align directive is still working thanks |
|||
![]() |
|
LocoDelAssembly 07 Jun 2006, 16:03
And using NOPs in code is not too much efficient neither, anyway you can override align with your own macro
Code: macro align alignval {rb (($ + alignval - 1) and -alignval) - $} However make sure of use it on data sections because it reserves and initialize with zeroes if more data follows the align (which is the most probable). [edit] Code: macro align alignval, customval { if customval eq align alignval else times (($ + alignval - 1) and -alignval) - $ db customval end if } |
|||
![]() |
|
Tomasz Grysztar 07 Jun 2006, 16:50
Section 2.2.5 contains of fasm's manual an example how you can customize the alignment in any way you want. It's quite easy to make into macro.
And the so-called "good old align macro" you can find as one of the first examples in the 2.3.3 section. I know, nobody reads it, but it still contains a few useful things, you know. ![]() |
|||
![]() |
|
Quantum 07 Jun 2006, 19:52
2 locodelassembly and Tomasz Grysztar:
I already knew that, but thanks anyway. The point is I never asked for a macro solution. align is a directive, not a macro. I don't like macros at all. But that's only my very humble personal opinion. 2 locodelassembly: Quote:
People usually store uninitialized data in a block storage space section (BSS) or any other virtually extended (bss-like) place of another section (data/text). So, I'm not sure I understand your tip. |
|||
![]() |
|
vid 07 Jun 2006, 20:10
Quote: I know, nobody reads it, but it still contains a few useful things, you know. because we don't know what remained and what has changed. i don't want to read entire 200kb pure text file to find 0.05% of new things... |
|||
![]() |
|
Tomasz Grysztar 07 Jun 2006, 20:13
Actually the "align" macro was there for all the time, even in the previous manual.
|
|||
![]() |
|
amcl 07 Jun 2006, 20:29
Quantum wrote:
Sorry my response is offtopic, useless and pedantic, but BSS stands for 'Block Started by Symbol'. http://en.wikipedia.org/wiki/.bss |
|||
![]() |
|
Quantum 07 Jun 2006, 21:18
2 amcl:
Quote:
That's what many people believe (including D. Ritchie). But I prefer the former definition (mentioned somewhere by M. Pietrek). Oh, and never trust a wiki ![]() |
|||
![]() |
|
LocoDelAssembly 08 Jun 2006, 01:59
Quote:
That is because my english is terrible. I'd tried to say that never use my align macro on code sections because it will pad with zeroes which is a problem if those zeroes gets executed. And about the second macro (which has the same problem with code section unless you use a valid single byte opcode as customval or not pass a customval), the problem is if you have a source like this: Code: macro align alignval, customval { if customval eq align alignval else times (($ + alignval - 1) and -alignval) - $ db customval end if } db 1 align 16, 0 |
|||
![]() |
|
Quantum 08 Jun 2006, 02:36
2 locodelassembly:
Quote:
I see know. Well, a piece of padding code not intended to be executed should be filled with 0xCC bytes instead of 0x90's. At least MS VC guys think so. Quote:
That was clear from the beginning. Another little minus goes to macros ![]() Quote:
I whouldn't say that. Mine is worse. Mi español es un poco mejor. What really matters is that we finally understood each other. |
|||
![]() |
|
shism2 08 Jun 2006, 02:53
There was someone on this forum who made a macro which calculates the necessary alignment. I don't remember who and how to find it. But it was on here before.
|
|||
![]() |
|
LocoDelAssembly 08 Jun 2006, 03:18
Yep but the problem is that align is normally used to align loops where the preceding bytes will normally get executed.
Code: mov ecx, someValue align 16 .loop: dec .loop jnz .loop The bytes between "mov ecx, someVal" and .loop (if any) will be executed so apropiate opcodes are requiered here. Anyway good point about $CC, it could be used when you align PROCs. Si no has entendido dime y seguimos por PM en español así no te confundo más ![]() Regards |
|||
![]() |
|
shism2 08 Jun 2006, 04:34
ta hablodo a mi ?
|
|||
![]() |
|
Quantum 08 Jun 2006, 16:10
2 locodelassembly:
Quote:
In case of loops, nops ain't always the best solution. For example, instead of 2 consecutive nops it's more efficient to place a mov eax,eax. |
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.