format PE GUI 4.0
entry start

include 'win32ax.inc'

section '.text' code readable executable

  start:

	invoke	GetModuleHandle,0
	mov	[h_process],eax

	invoke	LUsolve,A,L,U,b,y,x

	invoke	CreateFileA,arquivo,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
	mov	[hfile],eax

	invoke	RtlZeroMemory,buff,1024d

	invoke	lstrcat,buff,MatrixA
	invoke	WriteMatrix2Buffer,A,buff
	invoke	lstrcat,buff,ArrayB
	invoke	WriteArray2Buffer,b,buff
	invoke	lstrcat,buff,MatrixL
	invoke	WriteMatrix2Buffer,L,buff
	invoke	lstrcat,buff,MatrixU
	invoke	WriteMatrix2Buffer,U,buff
	invoke	lstrcat,buff,ArrayY
	invoke	WriteArray2Buffer,y,buff
	invoke	lstrcat,buff,ArrayX
	invoke	WriteArray2Buffer,x,buff

	invoke	lstrcat,buff,Text

	invoke	lstrlen,buff
	invoke	WriteFile,[hfile],buff,eax,nchar,NULL

	invoke	CloseHandle,[hfile]
  exit:
	invoke	ExitProcess,0

section '.data' data readable writable

  struc matrix i,j,M
  {
	.i dd i
	.j dd j
	.M dd M
  }
  struc array i,M
  {
	.i dd i
	.M dd M
  }
  align 16
  a dq	-2.00,	1.50,  4.00,  5.00,  0.20,  0.01,\
	 3.25, -1.15, -4.50,  1.00,  0.05, -0.12,\
	 1.00,	2.05,  1.35,  1.45, -1.27,  2.00,\
	 4.00,	1.00,  2.00,  1.23,  5.67,  1.90,\
	 3.15, -4.67,  1.15,  0.05,  0.01,  3.45,\
	-1.11,	0.01, -0.02,  0.23, 10.11,  1.78

  l dq	 1.00,	0.00,  0.00,  0.00,  0.00,  0.00,\
	 0.00,	1.00,  0.00,  0.00,  0.00,  0.00,\
	 0.00,	0.00,  1.00,  0.00,  0.00,  0.00,\
	 0.00,	0.00,  0.00,  1.00,  0.00,  0.00,\
	 0.00,	0.00,  0.00,  0.00,  1.00,  0.00,\
	 0.00,	0.00,  0.00,  0.00,  0.00,  1.00

  ;u dq   0.00,  0.00,  0.00,  0.00,  0.00,  0.00,\
  ;       0.00,  0.00,  0.00,  0.00,  0.00,  0.00,\
  ;       0.00,  0.00,  0.00,  0.00,  0.00,  0.00,\
  ;       0.00,  0.00,  0.00,  0.00,  0.00,  0.00,\
  ;       0.00,  0.00,  0.00,  0.00,  0.00,  0.00,\
  ;       0.00,  0.00,  0.00,  0.00,  0.00,  0.00

  u dq 6*6 dup (0.00)

  B dq	 1.00,	1.50,  2.00,  1.00,  1.30,  1.40

  ;Y dq   0.00,  0.00,  0.00,  0.00,  0.00,  0.00

  Y dq 6 dup (0.00)

  X dq 6 dup (0.00)

  A matrix 6,6,a
  L matrix 6,6,l
  U matrix 6,6,u
  b array  6,B
  y array  6,Y
  x array  6,X
  arquivo db 'matrix.txt',0
  MatrixA db 'A = ',13,10,0
  MatrixL db 13,10,'L = ',13,10,0
  MatrixU db 13,10,'U = ',13,10,0
  ArrayB  db 13,10,'b = ',13,10,0
  ArrayY  db 13,10,'y = ',13,10,0
  ArrayX  db 13,10,'x = ',13,10,0
  Text	  db 13,10,13,10,'x is the solution to A . x = b',13,10,0

section '.bss' readable writeable

  align 16
  h_process  dd ? ;handles to the executable process.
  hfile dd ?
  nchar dd ?
  buff rb 1024d

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
	  advapi32,'ADVAPI32.DLL',\
	  user32,'USER32.DLL',\
	  msvcrt,'MSVCRT.DLL',\
	  lusolve,'LUSOLVE.DLL'

  include 'API\KERNEL32.INC'
  include 'API\ADVAPI32.INC'
  include 'API\USER32.INC'

  import msvcrt,\
	 sprintf,'sprintf'

  import lusolve,\
	 LUdecompose,'LUdecompose',\
	 LybSolve,'LybSolve',\
	 UxySolve,'UxySolve',\
	 LUsolve,'LUsolve',\
	 WriteMatrix2Buffer,'WriteMatrix2Buffer',\
	 WriteArray2Buffer,'WriteArray2Buffer'

;section '.reloc' fixups data discardable