News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

ALIGN 64

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

Previous topic - Next topic

nidud

#15
deleted

jj2007

Quote from: nidud on August 30, 2015, 04:52:57 AM
What happened with version 6.15, how did it fail?

It inserts zeros:
00401013                  ³.  90                     nop
00401014                  ³.  0000                   add [eax], al
00401016                  ³.  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...
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
start:
nops 19 ; misalign for testing
int 3
codeStart:
  alignx 64
codeEnd:


nidud

#17
deleted

jj2007

Quote from: nidud on August 30, 2015, 07:38:17 AMKeep in mind that the $ offset is zero based so you cant use this approach in a library or object module.

Very good point :t

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

include \masm32\include\masm32rt.inc
AlignX macro abytes
Local 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)
  endif
endm
Align64 equ <AlignX 64>

.code
start:
nops 20 ; misalign for testing
codeStart:
  Align64
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
  print str$(eax), " bytes inserted"
  exit
end start


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