### Author Topic: ALIGN 64  (Read 5061 times)

#### nidud

• Member
• Posts: 1562
##### Re: ALIGN 64
« Reply #15 on: August 30, 2015, 05:50:17 AM »
Come to think of it you actually HAVE to align all objects (at least the ones you use the macro in) to 64 from the top for this to work.

#### jj2007

• Member
• Posts: 8596
• Assembler is fun ;-)
##### Re: ALIGN 64
« Reply #16 on: August 30, 2015, 06:53:40 AM »
What happened with version 6.15, how did it fail?

It inserts zeros:
Code: [Select]
`00401013                  ³.  90                     nop00401014                  ³.  0000                   add [eax], al00401016                  ³.  0000                   add [eax], al`
Strange, now that I tested it again it fails with all assemblers, with an exception. Copied and pasted from your code above...
Code: [Select]
`alignx macro x if ((\$ - _TEXT) and (x - 1))     org \$ + x - ((\$ - _TEXT) and (x - 1)) endif endm`
What do you see in the debugger with this code?
Code: [Select]
`.codestart: nops 19 ; misalign for testing int 3codeStart:  alignx 64codeEnd:`

#### nidud

• Member
• Posts: 1562
##### Re: ALIGN 64
« Reply #17 on: August 30, 2015, 07:38:17 AM »
It inserts zeros:

Yes, they all should pad with zeros.

Quote
Strange, now that I tested it again it fails with all assemblers, with an exception.

As it should if you fall trough the ORG offset as you do. You have to pad with nop's in that case.

Quote
What do you see in the debugger with this code?

I didn't test real code, only viewed the list output. Keep in mind that the \$ offset is zero based so you cant use this approach in a library or object module.

#### jj2007

• Member
• Posts: 8596
• Assembler is fun ;-)
##### Re: ALIGN 64
« Reply #18 on: August 30, 2015, 10:45:03 AM »
Keep in mind that the \$ offset is zero based so you cant use this approach in a library or object module.

Very good point

I've included Align64 in the latest MasmBasic edition of 30 August. It will throw an error when used in a library:

Code: [Select]
`include \masm32\include\masm32rt.incAlignX macro abytesLocal xbytes  ifndef start .err <### AlignX can't be used in libraries and object modules ###>  endif  xbytes=abytes-((\$-_TEXT) and (abytes-1))  if xbytes db xbytes dup(90h)  endifendmAlign64 equ <AlignX 64>.codestart: nops 20 ; misalign for testingcodeStart:  Align64codeEnd:  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  print str\$(eax), " bytes inserted"  exitend start`
Output:
Code: [Select]
`00401000 is start:00401014 is codeStart:00401040 is codeEnd:44 bytes inserted`