News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Align a bss label on a 64k boundary in MASM

Started by @lx, November 12, 2009, 02:35:43 PM

Previous topic - Next topic

@lx

Hi,
I would like to align a data on a 64k boundary, unfortunately, the align keyword only works up to 8192 bytes....
Do you know any way to perform such an alignment?

I tried this kind of brute force macro, but

BssBufferAling64k macro var, BufLen
    ; Try to align to next 64K boundary
    org $ and 0ffff0000h + 000010000h       ; <- assembler error here it expects a constant ( the ($ and 0FFFF0000h) is not a constant)
    ; Allocate a large buffer
var db ?
    org $+BufLen-1                           
ENDM

dedndave

you might be better off to let the assembler create the segment as it wants to, then align your array/buffer to 64K
another approach is to allocate the buffer dynamically with Global or Heap functions
allocate more than you need so you can align the buffer and still have enough space

qWord

Quote from: @lx on November 12, 2009, 02:35:43 PM
unfortunately, the align keyword only works up to 8192 bytes....
you are talking about jwasm? - masm allows only up to 16 bytes.

To do arithmetic with the location counter in masm, you must (do not ask me why) subtract some other label from it. You should also notice, that the bss-segment is glued to the data segment, so that your alignment get lost. You can solve this by corresponding alignment of data section at the end of your program. However, I'm not sure that alignment of 2^16 will work without assembler/linker support for it. Here is how I does alignment > 16 it in masm:
nAlign=65536
IFNDEF algin_zero_lbl_bss
_BSS SEGMENT
align_mark_bss:
org 0
algin_zero_lbl_bss: ; label at pos. 0
org align_mark_bss
_BSS ENDS
ENDIF
align_msk = nAlign-1
db (nAlign-(align_msk AND ($-OFFSET algin_zero_lbl_bss)))*(1 AND ((align_msk AND ($-OFFSET algin_zero_lbl_bss)) NE 0)) dup (?)



FPU in a trice: SmplMath
It's that simple!

@lx

Quote from: dedndave on November 12, 2009, 03:17:28 PM
you might be better off to let the assembler create the segment as it wants to, then align your array/buffer to 64K
another approach is to allocate the buffer dynamically with Global or Heap functions
allocate more than you need so you can align the buffer and still have enough space
I'm indeed using the previous macro in a bss section like this :

BssSegment segment public 'bss'
BssBufferAling64k myBuffer, 512*8
ends

I do not want to use Global/Head Functions as i want to keep my program as small as possible (so let the alignment be resolved at compile time).
Quote from: qWordyou are talking about jwasm? - masm allows only up to 16 bytes.
Oops, my mystake, the 8192 limit is on the section alignment.

thanks! i'll try your solution!

dedndave

another idea - you may be able to modify the PE header and force alignment
i am not sure if it allows for 64k alignment - it may