flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > .if macro feature not working

Author
Thread Post new topic Reply to topic
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 08 Dec 2010, 14:41
Found another macro feature that isn't working right, '.if ~eax' gives me an 'illegal instruction: ..var?3kL eax,eax' error.

[edit 2] It seems to be working correctly in my other code projects, only in a certain coding project it gives me this error, wonder what could be causing it?

See 'RegisterClassEx' in the code below:
Code:
;template for program using standard Win32 headers
format PE GUI 4.0 on 'nul'
entry WINMAIN

include '%fasminc%\win32a.inc'
include '%fasminc%\equates\msvcrt.inc'
include '%fasminc%\equates\kernel32.inc'
include '%fasminc%\equates\gdi32.inc'
include '%fasminc%\equates\user32.inc'
include '%fasminc%\equates\comctl32.inc'
include '%fasminc%\equates\comdlg32.inc'
include '%fasminc%\equates\winmm.inc'

;DISPLAY "SizeOf: ",<sizeof.teststruct, 10>,13,10
WINDOWWIDTH  = 800
WINDOWHEIGHT = 600
IDI_MAINICON = 500

section '.data' data readable writeable
  szAppTitle db 'Windows Shell',0
  szAppClass db 'WinShell32',0
  align 4

  mainhwnd  dd 0
  hinstance dd 0
  editfont  dd 0

  icex INITCOMMONCONTROLSEX sizeof.INITCOMMONCONTROLSEX, ICC_ALL_CLASSES

section '.code' code readable executable

proc WINMAIN  hInstance, hprevinstance, lpcmdline, ncmdshow
     local msg:MSG, wc:WNDCLASSEXA, test:DOUBLE, startx:DWORD, starty:DWORD, clientrectangle:RECT
     locals
         regclass db "RegisterClassEx()",0
         error    db "ERROR",0
     endl
     locals
         moretext db "Error number X:",0
     endl

     invoke  InitCommonControlsEx, icex
     cinvoke memset, addr wc, 0, sizeof.WNDCLASSEXA
     invoke  GetModuleHandle, 0
     mov     [wc.hInstance], eax
     mov     [hinstance], eax
     mov     [wc.cbSize], sizeof.WNDCLASSEXA
     invoke  LoadImage, [hinstance], IDI_MAINICON, IMAGE_ICON, 48, 48, LR_DEFAULTSIZE
     mov     [wc.hIcon], eax
     invoke  LoadImage, [hinstance], IDI_MAINICON, IMAGE_ICON, 16, 16, LR_DEFAULTSIZE
     mov     [wc.hIconSm], eax
     invoke  LoadCursor, 0, IDC_ARROW
     mov     [wc.hCursor], eax
     mov     [wc.style], CS_HREDRAW or CS_VREDRAW
     mov     [wc.lpfnWndProc], WndProc
     mov     [wc.cbClsExtra], 0
     mov     [wc.cbWndExtra], 0
     invoke  GetStockObject, WHITE_BRUSH
     mov     [wc.hbrBackground], eax
     mov     [wc.lpszMenuName], 0
     mov     [wc.lpszClassName], szAppClass

     invoke  RegisterClassEx, addr wc
     .if     ~eax  [b]ERROR[/b]
             invoke  MessageBox, NULL, addr regclass, addr error, MB_OK or MB_ICONERROR
             return  FALSE
     .endif

     invoke  GetSystemMetrics, SM_CXFULLSCREEN ;SM_CXSCREEN
     shr     eax, 1
     sub     eax, WINDOWWIDTH shr 1
     mov     [startx], eax

     invoke  GetSystemMetrics, SM_CYFULLSCREEN ;SM_CYSCREEN
     shr     eax, 1
     sub     eax, WINDOWHEIGHT shr 1
     mov     [starty], eax

     invoke  SetRect, addr clientrectangle, 0, 0, WINDOWWIDTH, WINDOWHEIGHT
     invoke  AdjustWindowRect, addr clientrectangle, WS_OVERLAPPEDWINDOW or WS_VISIBLE, NULL
     mov     eax, [clientrectangle.right]
     sub     eax, [clientrectangle.left]
     mov     ecx, [clientrectangle.bottom]
     sub     ecx, [clientrectangle.top]
     invoke  CreateWindowEx, NULL, szAppClass, szAppTitle, WS_OVERLAPPEDWINDOW + WS_VISIBLE, [startx], [starty], eax, ecx,\
             NULL, NULL, [hinstance], NULL
     .if     eax = NULL
             invoke  MessageBox, NULL, "CreateWindowEx()", "ERROR", MB_OK or MB_ICONERROR
             return  FALSE
     .endif
     mov     [mainhwnd], eax

     .while  [msg.message] <> WM_QUIT
             invoke  GetMessage, addr msg, NULL, 0, 0
             invoke  TranslateMessage, addr msg
             invoke  DispatchMessage, addr msg
     .endw

     invoke  ExitProcess, 0
     return
endp

proc WndProc  hwnd, wmsg, wparam, lparam
     local hdc:DWORD, ps:PAINTSTRUCT, szBuffer[256*4]:BYTE, FreeBytes:QWORD, TotalBytes:QWORD, UsedBytes:QWORD

     ;check for messages wanted here
     .if     [wmsg] = WM_CREATE
             return  0

     .elseif [wmsg] = WM_PAINT
             finit
             invoke  BeginPaint, [hwnd], addr ps
             mov     [hdc], eax

             invoke  CreateFont, 24, 10, 0, 0, FW_BOLD, NULL, NULL, NULL, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,\
                     CLEARTYPE_QUALITY, VARIABLE_PITCH or FF_DONTCARE, "Courier New"; "Tahoma"
             mov     [editfont],eax
             invoke  SelectObject, [hdc], [editfont]

             invoke  GetDiskFreeSpaceEx, NULL, addr FreeBytes, addr TotalBytes, NULL
             fild    [TotalBytes]
             fst     [TotalBytes]
             fild    [FreeBytes]
             fst     [FreeBytes]
             fsubp
             fstp    [UsedBytes]
             cinvoke sprintf, addr szBuffer, "HARD DRIVE STATS:"
             invoke  TextOut, [hdc], 0, 0, addr szBuffer, eax
             cinvoke sprintf, addr szBuffer, "TotalBytes: %13.f", double [TotalBytes]
             invoke  TextOut, [hdc], 0, 20*1+(20/4), addr szBuffer, eax
             cinvoke sprintf, addr szBuffer, "FreeBytes:  %13.f", double [FreeBytes]
             invoke  TextOut, [hdc], 0, 20*2+(20/4), addr szBuffer, eax
             cinvoke sprintf, addr szBuffer, "UsedBytes:  %13.f", double [UsedBytes]
             invoke  TextOut, [hdc], 0, 20*3+(20/4), addr szBuffer, eax
             .if     [editfont]
                     invoke  DeleteObject, [editfont]
             .endif

             invoke  EndPaint, [hwnd], addr ps
             return  0

     .elseif [wmsg] = WM_KEYDOWN
             .if     [wparam] = VK_ESCAPE
                     invoke  PostQuitMessage, 0
             .endif
             return  0

     .elseif [wmsg] = WM_CLOSE
             invoke  PostQuitMessage, 0
             return  0

     .elseif [wmsg] = WM_DESTROY
             invoke  DestroyWindow, [hwnd]
             return  [hwnd]
     .endif

     invoke  DefWindowProc, [hwnd], [wmsg], [wparam], [lparam]
     return
endp

section '.rsrc' resource data readable
  directory RT_MANIFEST, manifest, RT_ICON, icons, RT_GROUP_ICON, group_icons

  resource manifest, 1, LANG_NEUTRAL, xpstyle
  resource icons, 1, LANG_NEUTRAL, icon_data
  resource group_icons, IDI_MAINICON, LANG_NEUTRAL, main_icon

  icon main_icon, icon_data, 'VistaIcon.ico'

  resdata xpstyle
          file '%fasminc%\winxpstyle.xml'
  endres

section '.idata' import data readable writeable

  library msvcrt,'MSVCRT.DLL',\
          kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL',\
          gdi32,'GDI32.DLL',\
          comctl32,'COMCTL32.DLL',\
          comdlg32,'COMDLG32.DLL',\
          shell32,'SHELL32.DLL',\
          winmm,'WINMM.DLL'

  include '%fasminc%\vapia\msvcrt.inc'
  include '%fasminc%\vapia\kernel32.inc'
  include '%fasminc%\vapia\gdi32.inc'
  include '%fasminc%\vapia\user32.inc'
  include '%fasminc%\vapia\comctl32.inc'
  include '%fasminc%\vapia\comdlg32.inc'
  include '%fasminc%\vapia\shell32.inc'
  include '%fasminc%\vapia\winmm.inc'
    
[/b]

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 08 Dec 2010, 14:41
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 08 Dec 2010, 15:42
You did define local variable named "test" and this breaks the "test" instruction. If you try to use "test" instruction directly somewhere inside your procedure, you will get similar error.
Post 08 Dec 2010, 15:42
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 08 Dec 2010, 15:53
Can't believe I did that, thanks.
Post 08 Dec 2010, 15:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.