News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ALIGN 64

Started by jj2007, August 29, 2015, 08:03:11 PM

Previous topic - Next topic

jj2007

Any idea how to achieve align 64? I've tried with currentpos=$ etc but no success so far.

dedndave

you might try a macro that generates 0's until the address mod 64 = 0

dedndave

start with ALIGN 16 - generate 0's in 16-byte blocks   :P

nidud

#3
deleted

jj2007

Looks good, Nidud :t

JWasm inserts the right amount of bytes, but ML 6.15 and ML 10 choke, after a long while, with "fatal error A1004: out of memory". Even better, ML 10 drives one of my cores to 100%. Naive Windows user might think that is no problem for a multitasking OS, but it slows down the whole system to a crawl, and the only solution is to reboot (and it takes ages to shut it down in this freeze condition...). Windows 7-64 at its best 8)

include \masm32\include\masm32rt.inc
Align64 MACRO
Local pos
  pos=0 ; PROBLEM: how to get initial position
  ; pos=$ ; not possible
  WHILE 1
pos=pos+1
ife (pos and 63)
EXITM
endif
nop
  ENDM
ENDM

alignx macro x
while (($ - _TEXT) and (x - 1))
   nop
   align 16
endm
endm

.code
start:
nop
codeStart:
  ; Align64
  alignx 64
codeEnd:

  mov eax, codeEnd
  sub eax, codeStart
  inkey str$(eax), " bytes inserted"
  exit
end start

dedndave

Quote from: nidud on August 29, 2015, 10:22:02 PM

alignx macro x
while (($ - _TEXT) and (x - 1))
   nop
   align 16
endm
endm


you can't emit NOP's in the data section
try it with DB 0

jj2007

Quote from: dedndave on August 29, 2015, 10:45:47 PMyou can't emit NOP's in the data section

It's supposed to be in the code section, Dave:

include \masm32\include\masm32rt.inc
alignx macro x
  while (($ - _TEXT) and (x - 1))
nop
align 16
  endm
endm

.code
start:
  nops 20 ; misalign for testing
codeStart:
  alignx 64
codeEnd:

  mov ebx, start
  print hex$(ebx), " is start:", 13, 10
  mov ebx, codeStart
  print hex$(ebx), " is codeStart:", 13, 10
  mov ebx, codeEnd
  print hex$(ebx), " is codeEnd:", 13, 10
  mov eax, ebx
  sub eax, codeStart
  inkey str$(eax), " bytes inserted"
  exit
end start


Output:
00401000 is start:
00401014 is codeStart:
00401040 is codeEnd:
44 bytes inserted


nidud

#7
deleted

nidud

#8
deleted

jj2007

Nidud,
Your macro works perfectly with JWasm, see reply #6, but it hangs with ML...

TouEnMasm


And what about LINK  /ALIGN:64 ??
Seems the more secure way.
Fa is a musical note to play with CL

nidud

#11
deleted

jj2007

Fails with ml 6.15 :(

But here is one tested with ML 6.15 + 10.0 and JWasm:

include \masm32\include\masm32rt.inc

AlignX macro abytes
Local xbytes
  xbytes=abytes-(($-_TEXT) and (abytes-1))
  if xbytes
db xbytes dup(90h)
  endif
endm

.code
start:
nops 20 ; misalign for testing
codeStart:
  AlignX 64
codeEnd:

  mov ebx, offset start
  print hex$(ebx), " is start:", 13, 10
  mov ebx, offset codeStart
  print hex$(ebx), " is codeStart:", 13, 10
  mov ebx, offset codeEnd
  print hex$(ebx), " is codeEnd:", 13, 10
  mov eax, ebx
  sub eax, codeStart
  inkey str$(eax), " bytes inserted"
  exit
end start


Thanks a lot for the inspiration, Nidud :t

And here is a first application (timings welcome, see attached exe):

      NanoTimer()
      AlignX 64
      .Repeat
            inc swVar
            .If swVar > MaxVar
                  xor swVar, swVar
            .EndIf
            MbSwitch_s:
            Switch_ swVar      ; --------- new MasmBasic macro, ~40% faster ------------
            Case_ 5
                  inc ct0
            Case_ 1
                  inc ct1
            Case_ 2
                  inc ct2
            Case_ 3
                  inc ct3
            Case_ 4
                  inc ct4
            Default_
                  inc ctDef
            Endsw_

            MbSwitch_endp:
            inc loopCt
      .Until loopCt >= Loops
      Print Str$("%i\tms for MasmBasic Switch\t", NanoTimer(ms)), Str$("ct1=%i", ct1), Str$(", ct2=%i", ct2), Str$(", ct3=%i", ct3), Str$(", ctDef=%i\n", ctDef)


Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
1083    ms for plain if chain   ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000
1055    ms for if/elseif chain  ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000
1086    ms for Masm32 switch    ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000
607     ms for MasmBasic Switch ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000

1055    ms for plain if chain   ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000
1027    ms for if/elseif chain  ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000
1093    ms for Masm32 switch    ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000
615     ms for MasmBasic Switch ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000

1031    ms for plain if chain   ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000
1036    ms for if/elseif chain  ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000
1072    ms for Masm32 switch    ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000
596     ms for MasmBasic Switch ct1=10000000, ct2=10000000, ct3=10000000, ctDef=150000000

52      bytes for PlainIf
52      bytes for ElseIf
54      bytes for SwitchMasm32
84      bytes for MbSwitch

hutch--

i think from memory that you can set the code alignment in an object module to values higher than 16. With the tool FDA in MASM32 which produces a data object module and I think from memory it works the same way with a code module.

nidud

#14
deleted