News:

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

Main Menu

Using MASM's DSEG CSEG 32-bit

Started by coder, April 29, 2017, 01:54:57 AM

Previous topic - Next topic

coder

Interesting that a DSEG/CSEG allows you to set the alignment manually (although it's aligned to page anyway). Below is a modified version for use with XMM instead for those who don't have AVX. Added SSEG. All sections are page-aligned (which also aligned to 32). I think it's more convenient this way for any alignment larger than 16.

;ml /c /coff myprog.asm
;gcc -m32 myprog.obj -o myprog.exe

.686p
.xmm
.model flat,c
option casemap:none
printf PROTO C:vararg

DSEG SEGMENT ALIGN(32) PUBLIC 'DATA'
x  dq 56.33,10.36,11.98,71.24
z  dq 89.23,90.12,11.28,55.57
v1 dq 0.0
outstring db '%f',10,0
confirm db 'x = %p, WinMain@16 = %p, t = %p',10,0
DSEG ENDS

SSEG SEGMENT STACK 'STACK'
t dq 0
SSEG ENDS

CSEG SEGMENT PUBLIC 'CODE'
WinMain@16 proc
enter 0,0
invoke printf,addr confirm,addr x, addr WinMain@16, addr t
movdqa xmm0,xmmword ptr x
movdqa xmm1,xmmword ptr z
shufpd xmm1,xmm0,0
movq v1,xmm1
invoke printf,addr outstring,v1
leave
ret
WinMain@16 endp
CSEG ENDS
END


The output for all three markers

x = 00405000, WinMain@16 = 00403000, t = 00406000
89.230000


I'm just not sure if SSEG really mean anything to ESP though.

hutch--

The crude technique for testing if a variable (esp based) is aligned correctly for an SSE or AVX instruction is to make a test piece and use an instruction that must be aligned to a minimum boundary. You will find out soon enough if its correct or not.  :P

coder

Yea hutch. I still can't figure out what SSEG has anything to do with ESP. Using ASSUME SS don't seem to help either. ESP still aligns 4.


hutch--

This should do the job.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .data?
      __esp dd ?


    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    call aligned

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

aligned proc

    mov __esp, esp          ; save ESP

    memalign esp, 1024
    sub esp, 1024

  ; -------------------------------
  ; see what your alignment is here
  ; -------------------------------

    mov esp, __esp          ; restore ESP

    ret

aligned endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start

nidud

#19
deleted