flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [SOLVED] Macros keyword error compiling a linked list?

Author
Thread Post new topic Reply to topic
FASMNOOB



Joined: 09 Feb 2012
Posts: 21
FASMNOOB
I'm getting the error:


C:\fasm\INCLUDE>fasm linklist.asm
flat assembler version 1.69.35 (289846 kilobytes memory)
macro/macros.inc [178]:
macro define name { name fix defined }
error: reserved word used as symbol.

I had to download the include files and the source files as well. I changed the word apia to api in the source as the include directory.

I'm not sure why the url and code tags aren't working?

Code:
;##########################################################################
; linklist
; 13.12.2003
; coded by comrade <comrade2k@hotmail.com>
; IRC: #asm, #coders, #win32asm on EFnet
; Web: http://comrade64.cjb.net/
;      http://comrade.win32asm.com/
;##########################################################################
format PE GUI 4.0
entry start
;##########################################################################
_TITLE           equ  "Linked List"
_NAME           equ  "linklist"
_VERSION   equ  "1.0"
_VERSIONTEXT    equ  _VERSION
;##########################################################################
include "win32a.inc"
include "macro/if.inc"
include "macro/macros.inc"
OFFSET equ
;##########################################################################
struc NODE {
        .value   dd ?
       .hMemory  dd ?
      .next    dd ?
       .prev    dd ?
}
struct NODE
;##########################################################################
;##########################################################################
;##########################################################################
section ".code" code readable executable
;##########################################################################
start:
;##########################################################################
;##########################################################################
        stdcall [GetModuleHandle],0
 mov     [mbp.hInstance],eax
 stdcall [DialogBoxParam],eax,IDD_MAIN,0,OFFSET DlgProc,0
    stdcall [ExitProcess],0
;##########################################################################
proc DlgProc,hWnd,msg,wParam,lParam
       enter
       push    ebx esi edi
 ; find message
      mov     eax,[msg]
   mov     edx,OFFSET mainmsg
.scan:        cmp     eax,[edx]
   jne     @F
  jmp     dword [edx+04h]
@@:      add     edx,08h
     cmp     dword [edx],0
       je      .quit
       jmp     .scan

.initdlg:      ; INITDIALOG
        mov     eax,[hWnd]
  ; append "About..." item to system menu
   mov     [mbp.hwndOwner],eax
 stdcall [GetSystemMenu],eax,0
       mov     ebx,eax
     stdcall [AppendMenu],eax,MFT_SEPARATOR,0,0
  stdcall [AppendMenu],ebx,MFT_STRING,10,OFFSET szMenuAbout
   jmp     .quit
.command:  ; COMMAND
   mov     eax,[wParam]
        .if ax,e,ID_MAIN_ADD            ; Add
               stdcall InputBox,OFFSET szValuePrompt,OFFSET szValue,20h
            test    eax,eax
             jz      .quit

           ; allocate new node
         ; A>740Q< =>2K9 C75;
                xor     edi,edi
             stdcall [GlobalAlloc],GMEM_MOVEABLE,sizeof.NODE
             mov     esi,eax
             stdcall [GlobalLock],eax
            ; clear node
                ; >G8I05< C75;
            xchg    eax,edi
             mov     ecx,sizeof.NODE shr 2
               rep     stosd
               sub     edi,sizeof.NODE

         ; remember HGLOBAL handle, so we can deallocate it later
            ; A>E@0=O5< C:070B5;L => ?0<OBL
         mov     [edi+NODE.hMemory],esi
              ; set node value to user input
              ; 2AB02;O5< 40==>5 G8A;> 2 C75;
               stdcall ustr2dw,OFFSET szValue
              mov     [edi+NODE.value],eax
                ; add new node
              ; 4>102;O5< C75; 2 A?8A>:
           stdcall addNode,edi
         call    listNodes
   .elseif ax,e,ID_MAIN_EDIT       ; Edit
              stdcall [SendDlgItemMessage],[mbp.hwndOwner],ID_MAIN_LIST,LB_GETCURSEL,0,0
          test    eax,eax
             jl      .quit
               ; find selected node
                ; =0E>48< 2K1@0==K9 C75;
            stdcall getNode,eax
         test    eax,eax
             jz      .quit
               mov     edi,eax
             ; prompt user for edit
              ; A?@0H8205< =>2>5 7=0G5=85
               ccall   [wsprintf],OFFSET szValue,OFFSET szIntegerFormat,[edi+NODE.value]
           stdcall InputBox,OFFSET szValuePrompt,OFFSET szValue,20h
            test    eax,eax
             jz      .quit
               ; set node value to user input
              ; 70?8AK205< =>K>5 7=0G5=85
               stdcall ustr2dw,OFFSET szValue
              mov     [edi+NODE.value],eax
                ; refresh list
              ; >1=02;O5< A?8A>:
                call    listNodes
   .elseif ax,e,ID_MAIN_REMOVE     ; Remove
            stdcall [SendDlgItemMessage],[mbp.hwndOwner],ID_MAIN_LIST,LB_GETCURSEL,0,0
          test    eax,eax
             jl      .quit
               ; find selected node
                ; =0E>48< 2K1@0==K9 C75;
            stdcall getNode,eax
         test    eax,eax
             jz      .quit
               ; remove node
               ; C40;O5< C75;
            stdcall removeNode,eax
              call    listNodes
   .elseif ax,e,ID_MAIN_SORT       ; Sort
              call    sortNodes
           call    listNodes
   .elseif ax,e,ID_MAIN_ABOUT      ; About
     .about: mov eax,OFFSET mbp
              mov     [eax+MSGBOXPARAMS.cbSize],sizeof.MSGBOXPARAMS
               mov     [eax+MSGBOXPARAMS.lpszText],OFFSET szMsgAbout
               mov     [eax+MSGBOXPARAMS.lpszCaption],OFFSET szAppTitle
            mov     [eax+MSGBOXPARAMS.dwStyle],MB_OK+MB_APPLMODAL+MB_ICONASTERISK
               stdcall [MessageBoxIndirect],eax
    .elseif ax,e,ID_MAIN_CLOSE      ; Close
             stdcall [PostMessage],[hWnd],WM_CLOSE,0,0
   .endif
      jmp     .quit
.syscommand:       ; SYSCOMMAND
        cmp     [wParam],10
 je      .about
      jmp     .quit
.close:    ; CLOSE
     call    freeNodes
   stdcall [EndDialog],[hWnd],0
.quit:      xor     eax,eax
     pop     edi esi ebx
 return
;##########################################################################
proc getNode,index
 enter
       xor     edx,edx
     mov     eax,[parent]
        jmp     .chk
.node:      cmp     edx,[index]
 je      .quit
       inc     edx
 mov     eax,[eax+NODE.next]
.chk:        test    eax,eax
     jnz     .node
.quit:     return
;##########################################################################
proc addNode,node
  enter
       push    edi
 mov     edi,[node]
  ; is there at least one node?
       ; 5A;8 E>BO 1K >48= C75;?
       cmp     [parent],0
  jne     @F
  ; no nodes yet, set first one to new one
    ; =8 >4=>3> C7;0 =5 ACI5AB2C5B, 45;05< =>2K9 C75; =0G0;L=K<
 mov     [parent],edi
        jmp     .quit
@@:        ; there is at least one node, so link it to new one
 ; C75; C65 5ABL, A2O7K205< =>2K9 A ?>A;54=8< 2 A?8A:5
   mov     eax,[parent]
        jmp     .addchk
@@:      mov     eax,[eax+NODE.next]
.addchk:cmp  [eax+NODE.next],0
   jne     @B
  ; link both nodes
   ; A2O7:0
        mov     [eax+NODE.next],edi
 mov     [edi+NODE.prev],eax
.quit:       pop     edi
 return
;##########################################################################
proc removeNode,node
       enter
       push    esi edi
     mov     eax,[node]
  ; retrieve node's siblings
 ; 4>AB0Q< A2O7:8 40==>3> C7;0
       mov     esi,[eax+NODE.prev]
 mov     edi,[eax+NODE.next]
 ; deallocate node
   ; C40;O5< C75; 87 ?0<OB8
  push    [eax+NODE.hMemory]
  stdcall [GlobalUnlock],[esp]
        call    [GlobalFree]
        ; link removed node's siblings together
    ; A2O7K205< A2O7:8 C40;Q==>3> C7;0 <564C A>1>9
    test    esi,esi
     jnz     @F
  ; there was no previous node (removed node was parent)
      ; ?@5284CI53> C740 =5 1K;> (C40;Q= =0G0;L=K9 C75;)
  mov     [parent],edi
        jmp     .lnknx
@@:       mov     [esi+NODE.next],edi
.lnknx: test edi,edi
     jz      @F
  mov     [edi+NODE.prev],esi
@@:  pop     edi esi
     return
;##########################################################################
sortNodes:
     push    ebx esi edi
 ; bubble-sort nodes
 ; A>@B8@>2:0
    mov     esi,[parent]
        jmp     .chk
.node:      mov     ebx,[esi+NODE.value]
        mov     edi,[esi+NODE.next]
 jmp     .ichk
       .cmp:       ; compare both nodes
                ; A@02=5=85
           cmp     ebx,[edi+NODE.value]
                jle     @F
          ; swap nodes
                ; <5=O5< <5AB0<8
              xchg    ebx,[edi+NODE.value]
        @@: mov     edi,[edi+NODE.next]
 .ichk:      test    edi,edi
             jnz     .cmp
        mov     [esi+NODE.value],ebx
        mov     esi,[esi+NODE.next]
.chk:        test    esi,esi
     jnz     .node
       pop     edi esi ebx
 retn
;##########################################################################
freeNodes:
       push    esi
 mov     esi,[parent]
        jmp     .chk
.node:      pushd   [esi+NODE.hMemory] [esp]
    mov     esi,[esi+NODE.next]
 call    [GlobalUnlock]
      call    [GlobalFree]
.chk:       test    esi,esi
     jnz     .node
.quit:     pop     esi
 retn
;##########################################################################
listNodes:
       push    esi
 stdcall [SendDlgItemMessage],[mbp.hwndOwner],ID_MAIN_LIST,LB_RESETCONTENT,0,0
       mov     esi,[parent]
        jmp     .chk
.node:      ccall   [wsprintf],OFFSET szValue,OFFSET szIntegerFormat,[esi+NODE.value]
   stdcall [SendDlgItemMessage],[mbp.hwndOwner],ID_MAIN_LIST,LB_ADDSTRING,0,OFFSET szValue
     mov     esi,[esi+NODE.next]
.chk:        test    esi,esi
     jnz     .node
.quit:     pop     esi
 retn
;##########################################################################
proc DlgInputBoxProc,hWnd,msg,wParam,lParam
  enter
       push    ebx esi edi
 ; find message
      mov     eax,[msg]
   mov     edx,OFFSET inputboxmsg
.scan:    cmp     eax,[edx]
   jne     @F
  jmp     dword [edx+04h]
@@:      add     edx,08h
     cmp     dword [edx],0
       jne     .scan
       xor     eax,eax
     jmp     .quit

.initdlg:      ; INITDIALOG
        mov     ebx,[lParam]
        stdcall [SetDlgItemText],[hWnd],ID_INPUTBOX_PROMPT,[ebx+00h]
        stdcall [SetDlgItemText],[hWnd],ID_INPUTBOX_VALUE,[ebx+04h]
 stdcall [SetWindowLong],[hWnd],GWL_USERDATA,[lParam]
        xor     eax,eax
     inc     eax
 jmp     .quit
.command:  ; COMMAND
   mov     eax,[wParam]
        .if ax,e,ID_INPUTBOX_OK         ; OK
                stdcall [GetWindowLong],[hWnd],GWL_USERDATA
         stdcall [GetDlgItemText],[hWnd],ID_INPUTBOX_VALUE,[eax+04h],[eax+08h]
               stdcall [PostMessage],[hWnd],WM_CLOSE,1,0
   .elseif ax,e,ID_INPUTBOX_CANCEL ; Cancel
            stdcall [PostMessage],[hWnd],WM_CLOSE,0,0
   .endif
      jmp     .quit
.close:    ; CLOSE
     stdcall [EndDialog],[hWnd],[wParam]
.quit:       pop     edi esi ebx
 return
;##########################################################################
proc InputBox,pszPrompt,pszValue,dwValueLength
     enter
       lea     eax,[pszPrompt]
     stdcall [DialogBoxParam],[mbp.hInstance],IDD_INPUTBOX,[mbp.hwndOwner],OFFSET DlgInputBoxProc,eax
    return
;##########################################################################
proc ustr2dw,pszInput
      enter
       mov     edx,[pszInput]
      xor     eax,eax
     xor     ecx,ecx
     jmp     .chk
.char:      mov     cl,[edx]
    sub     cl,"0"
    jb      .quit
       cmp     cl,"9"-"0"
      ja      .quit
       ; digit
     lea     eax,[eax*4+eax]
     add     eax,eax
     add     eax,ecx
     inc     edx
.chk:        cmp     byte [edx],0
        jne     .char
.quit:     return
;##########################################################################
;##########################################################################
;##########################################################################
;##########################################################################
section ".data" import data readable writeable
      library kernel32,"kernel32.dll",user32,"user32.dll"
     include "api/kernel32.inc"
        include "api/user32.inc"
;##########################################################################
   szAppTitle      db      _TITLE,0
    szMsgAbout      db      _TITLE,13,10
                        db      "version ",_VERSIONTEXT,13,10
                     db      "coded by comrade <comrade2k@hotmail.com>",13,10
                    db      "13.12.2003 - ",DATE," ",TIME,13,10,13,10
                       db      "IRC:",9,"#asm, #coders, #win32asm on EFnet",13,10
                  db      "Web:",9,"http://comrade64.cjb.net/",13,10
                      db      9,"http://comrade.win32asm.com/",0
    szMenuAbout     db      "&About ",_TITLE,"...",0
    szValuePrompt   db      "Enter value:",0
      szIntegerFormat db      "%u",0
    mainmsg         dd      WM_INITDIALOG,DlgProc.initdlg
                       dd      WM_COMMAND,DlgProc.command
                  dd      WM_SYSCOMMAND,DlgProc.syscommand
                    dd      WM_CLOSE,DlgProc.close
                      dd      0
   inputboxmsg     dd      WM_INITDIALOG,DlgInputBoxProc.initdlg
                       dd      WM_COMMAND,DlgInputBoxProc.command
                  dd      WM_CLOSE,DlgInputBoxProc.close
                      dd      0
;##########################################################################
    mbp             MSGBOXPARAMS
        szValue         rb      20h

     parent          rd      01h
;##########################################################################
section ".rsrc" resource data readable
      ; identifiers
       IDV_MAIN                = 01
        IDI_MAIN                = 02
        IDI_COPY                = 03
        IDD_MAIN                = 20
        IDD_INPUTBOX            = 21
        ID_MAIN_LIST            = 01
        ID_MAIN_ADD             = 02
        ID_MAIN_EDIT            = 03
        ID_MAIN_REMOVE          = 04
        ID_MAIN_SORT            = 05
        ID_MAIN_ABOUT           = 06
        ID_MAIN_CLOSE           = 07
        ID_INPUTBOX_PROMPT      = 01
        ID_INPUTBOX_VALUE       = 02
        ID_INPUTBOX_OK          = 03
        ID_INPUTBOX_CANCEL      = 04
        ; resources
 directory RT_VERSION,versions,RT_DIALOG,dialogs
     resource versions,IDV_MAIN,SUBLANG_NEUTRAL+LANG_NEUTRAL,version
     resource dialogs, IDD_MAIN,SUBLANG_NEUTRAL+LANG_NEUTRAL,main,\
                       IDD_INPUTBOX,SUBLANG_NEUTRAL+LANG_NEUTRAL,inputbox
        ; version
   version version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,SUBLANG_NEUTRAL+LANG_NEUTRAL,0,\
               "FileDescription",_TITLE,\
               "LegalCopyright",<0A9h," comrade">,\
             "FileVersion",_VERSION,\
         "ProductVersion",_VERSION,\
              "ProductName",_TITLE,\
           "InternalName",_NAME,\
           "OriginalFilename",<_NAME,".exe">
 ; main dialog
       dialog main,_TITLE,0,0,240,102,DS_CENTER+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX,0,0,"Tahoma",8
              dialogitem "LISTBOX","",ID_MAIN_LIST,4,4,176,94,LBS_NOINTEGRALHEIGHT+WS_BORDER+WS_VSCROLL+WS_TABSTOP+WS_VISIBLE
         dialogitem "BUTTON","&Add",ID_MAIN_ADD,184,4,52,14,BS_PUSHBUTTON+WS_TABSTOP+WS_VISIBLE
              dialogitem "BUTTON","&Edit",ID_MAIN_EDIT,184,20,52,14,WS_TABSTOP+WS_VISIBLE
         dialogitem "BUTTON","&Remove",ID_MAIN_REMOVE,184,36,52,14,WS_TABSTOP+WS_VISIBLE
             dialogitem "BUTTON","&Sort",ID_MAIN_SORT,184,52,52,14,WS_TABSTOP+WS_VISIBLE
         dialogitem "BUTTON","A&bout...",ID_MAIN_ABOUT,184,68,52,14,BS_PUSHBUTTON+WS_TABSTOP+WS_VISIBLE
              dialogitem "BUTTON","&Close",ID_MAIN_CLOSE,184,84,52,14,BS_PUSHBUTTON+WS_TABSTOP+WS_VISIBLE
 enddlg
      ; inputbox dialog
   dialog inputbox,"Input Box",0,0,180,58,DS_CENTER+DS_MODALFRAME+WS_CAPTION+WS_SYSMENU,0,0,"Tahoma",8
             dialogitem "STATIC","",ID_INPUTBOX_PROMPT,4,4,172,12,WS_VISIBLE
         dialogitem "EDIT","",ID_INPUTBOX_VALUE,4,16,172,12,ES_AUTOHSCROLL+WS_TABSTOP+WS_VISIBLE+WS_BORDER
               dialogitem "STATIC","",0,4,34,172,12,SS_ETCHEDHORZ+WS_VISIBLE
           dialogitem "BUTTON","&OK",ID_INPUTBOX_OK,30,40,52,14,BS_DEFPUSHBUTTON+WS_TABSTOP+WS_VISIBLE
         dialogitem "BUTTON","&Cancel",ID_INPUTBOX_CANCEL,96,40,52,14,BS_PUSHBUTTON+WS_TABSTOP+WS_VISIBLE
    enddlg
;##########################################################################
;##########################################################################
    
edit by revolution - fixed code formatting


Last edited by FASMNOOB on 10 Feb 2012, 06:00; edited 1 time in total
Post 09 Feb 2012, 11:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
FASMNOOB wrote:
I'm not sure why the url and code tags aren't working?
Your URLs were not working because put your URL in quotation marks. And your code tags were not working because you ticked "Disable BBCode in this post". I already fixed it for you.

And as to your question:
Code:
error: reserved word used as symbol.    
"define" and "defined" are reserved words.
Post 09 Feb 2012, 12:08
View user's profile Send private message Visit poster's website Reply with quote
FASMNOOB



Joined: 09 Feb 2012
Posts: 21
FASMNOOB
Whats your suggestion for fixing it? What line is it on btw?


I see it, its the last couple of lines in macro.inc

Code:
macro define name { name fix defined } 
    
Post 09 Feb 2012, 12:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
FASMNOOB wrote:
Whats your suggestion for fixing it?
Change "define" to something else that is not reserved.
FASMNOOB wrote:
What line is it on btw?
Line 178: "macro/macros.inc [178]:"
Post 09 Feb 2012, 12:23
View user's profile Send private message Visit poster's website Reply with quote
FASMNOOB



Joined: 09 Feb 2012
Posts: 21
FASMNOOB
Ok changed it to definex and now I get



C:\fasm\INCLUDE>fasm linklist.asm
flat assembler version 1.69.35 (350249 kilobytes memory)
error: out of memory.

C:\fasm\INCLUDE>fasm linklist.asm
flat assembler version 1.69.35 (411270 kilobytes memory)
error: out of memory.

C:\fasm\INCLUDE>
Post 09 Feb 2012, 12:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
There have been many changes to fasm since 2003. Here is an updated version:
Code:
;##########################################################################
; linklist
; 13.12.2003
; coded by comrade <comrade2k@hotmail.com>
; IRC: #asm, #coders, #win32asm on EFnet
; Web: http://comrade64.cjb.net/
;      http://comrade.win32asm.com/
;##########################################################################
format PE GUI 4.0
entry start
;##########################################################################
_TITLE             equ  "Linked List"
_NAME           equ  "linklist"
_VERSION   equ  "1.0"
_VERSIONTEXT    equ  _VERSION
;##########################################################################
include "win32a.inc"
include "macro/if.inc"
;##########################################################################
struct NODE
    value    dd ?
       hMemory  dd ?
       next     dd ?
       prev     dd ?
ends
;##########################################################################
;##########################################################################
;##########################################################################
section ".code" code readable executable
;##########################################################################
start:
;##########################################################################
;##########################################################################
 stdcall [GetModuleHandle],0
 mov     [mbp.hInstance],eax
 stdcall [DialogBoxParam],eax,IDD_MAIN,0,DlgProc,0
   stdcall [ExitProcess],0
;##########################################################################
proc DlgProc,hWnd,msg,wParam,lParam
       push    ebx esi edi
 ; find message
      mov     eax,[msg]
   mov     edx,mainmsg
.scan:       cmp     eax,[edx]
   jne     @F
  jmp     dword [edx+04h]
@@:      add     edx,08h
     cmp     dword [edx],0
       je      .quit
       jmp     .scan

.initdlg:      ; INITDIALOG
        mov     eax,[hWnd]
  ; append "About..." item to system menu
   mov     [mbp.hwndOwner],eax
 stdcall [GetSystemMenu],eax,0
       mov     ebx,eax
     stdcall [AppendMenu],eax,MFT_SEPARATOR,0,0
  stdcall [AppendMenu],ebx,MFT_STRING,10,szMenuAbout
  jmp     .quit
.command:  ; COMMAND
   mov     eax,[wParam]
        .if ax,e,ID_MAIN_ADD            ; Add
               stdcall InputBox,szValuePrompt,szValue,20h
          test    eax,eax
             jz      .quit

           ; allocate new node
         ; ??????? ????? ????
                xor     edi,edi
             stdcall [GlobalAlloc],GMEM_MOVEABLE,sizeof.NODE
             mov     esi,eax
             stdcall [GlobalLock],eax
            ; clear node
                ; ??????? ????
              xchg    eax,edi
             mov     ecx,sizeof.NODE shr 2
               rep     stosd
               sub     edi,sizeof.NODE

         ; remember HGLOBAL handle, so we can deallocate it later
            ; ????????? ????????? ?? ??????
             mov     [edi+NODE.hMemory],esi
              ; set node value to user input
              ; ????????? ?????? ????? ? ????
             stdcall ustr2dw,szValue
             mov     [edi+NODE.value],eax
                ; add new node
              ; ????????? ???? ? ??????
           stdcall addNode,edi
         call    listNodes
   .elseif ax,e,ID_MAIN_EDIT       ; Edit
              stdcall [SendDlgItemMessage],[mbp.hwndOwner],ID_MAIN_LIST,LB_GETCURSEL,0,0
          test    eax,eax
             jl      .quit
               ; find selected node
                ; ??????? ????????? ????
            stdcall getNode,eax
         test    eax,eax
             jz      .quit
               mov     edi,eax
             ; prompt user for edit
              ; ?????????? ????? ????????
         ccall   [wsprintf],szValue,szIntegerFormat,[edi+NODE.value]
         stdcall InputBox,szValuePrompt,szValue,20h
          test    eax,eax
             jz      .quit
               ; set node value to user input
              ; ?????????? ????? ????????
         stdcall ustr2dw,szValue
             mov     [edi+NODE.value],eax
                ; refresh list
              ; ????????? ??????
          call    listNodes
   .elseif ax,e,ID_MAIN_REMOVE     ; Remove
            stdcall [SendDlgItemMessage],[mbp.hwndOwner],ID_MAIN_LIST,LB_GETCURSEL,0,0
          test    eax,eax
             jl      .quit
               ; find selected node
                ; ??????? ????????? ????
            stdcall getNode,eax
         test    eax,eax
             jz      .quit
               ; remove node
               ; ??????? ????
              stdcall removeNode,eax
              call    listNodes
   .elseif ax,e,ID_MAIN_SORT       ; Sort
              call    sortNodes
           call    listNodes
   .elseif ax,e,ID_MAIN_ABOUT      ; About
     .about: mov eax,mbp
             mov     [eax+MSGBOXPARAMS.cbSize],sizeof.MSGBOXPARAMS
               mov     [eax+MSGBOXPARAMS.lpszText],szMsgAbout
              mov     [eax+MSGBOXPARAMS.lpszCaption],szAppTitle
           mov     [eax+MSGBOXPARAMS.dwStyle],MB_OK+MB_APPLMODAL+MB_ICONASTERISK
               stdcall [MessageBoxIndirect],eax
    .elseif ax,e,ID_MAIN_CLOSE      ; Close
             stdcall [PostMessage],[hWnd],WM_CLOSE,0,0
   .endif
      jmp     .quit
.syscommand:       ; SYSCOMMAND
        cmp     [wParam],10
 je      .about
      jmp     .quit
.close:    ; CLOSE
     call    freeNodes
   stdcall [EndDialog],[hWnd],0
.quit:      xor     eax,eax
     pop     edi esi ebx
 ret
endp
;##########################################################################
proc getNode,index
    xor     edx,edx
     mov     eax,[parent]
        jmp     .chk
.node:      cmp     edx,[index]
 je      .quit
       inc     edx
 mov     eax,[eax+NODE.next]
.chk:        test    eax,eax
     jnz     .node
.quit:     ret
endp
;##########################################################################
proc addNode,node
     push    edi
 mov     edi,[node]
  ; is there at least one node?
       ; ???? ???? ?? ???? ?????
   cmp     [parent],0
  jne     @F
  ; no nodes yet, set first one to new one
    ; ?? ?????? ???? ?? ??????????, ?????? ????? ???? ?????????
 mov     [parent],edi
        jmp     .quit
@@:        ; there is at least one node, so link it to new one
 ; ???? ??? ????, ????????? ????? ? ????????? ? ??????
       mov     eax,[parent]
        jmp     .addchk
@@:      mov     eax,[eax+NODE.next]
.addchk:cmp  [eax+NODE.next],0
   jne     @B
  ; link both nodes
   ; ??????
    mov     [eax+NODE.next],edi
 mov     [edi+NODE.prev],eax
.quit:       pop     edi
 ret
endp
;##########################################################################
proc removeNode,node
  push    esi edi
     mov     eax,[node]
  ; retrieve node's siblings
 ; ??????? ?????? ??????? ????
       mov     esi,[eax+NODE.prev]
 mov     edi,[eax+NODE.next]
 ; deallocate node
   ; ??????? ???? ?? ??????
    push    [eax+NODE.hMemory]
  stdcall [GlobalUnlock],[esp]
        call    [GlobalFree]
        ; link removed node's siblings together
    ; ????????? ?????? ?????????? ???? ????? ?????
      test    esi,esi
     jnz     @F
  ; there was no previous node (removed node was parent)
      ; ??????????? ???? ?? ???? (?????? ????????? ????)
  mov     [parent],edi
        jmp     .lnknx
@@:       mov     [esi+NODE.next],edi
.lnknx: test edi,edi
     jz      @F
  mov     [edi+NODE.prev],esi
@@:  pop     edi esi
     ret
endp
;##########################################################################
sortNodes:
        push    ebx esi edi
 ; bubble-sort nodes
 ; ??????????
        mov     esi,[parent]
        jmp     .chk
.node:      mov     ebx,[esi+NODE.value]
        mov     edi,[esi+NODE.next]
 jmp     .ichk
       .cmp:       ; compare both nodes
                ; ?????????
         cmp     ebx,[edi+NODE.value]
                jle     @F
          ; swap nodes
                ; ?????? ???????
            xchg    ebx,[edi+NODE.value]
        @@: mov     edi,[edi+NODE.next]
 .ichk:      test    edi,edi
             jnz     .cmp
        mov     [esi+NODE.value],ebx
        mov     esi,[esi+NODE.next]
.chk:        test    esi,esi
     jnz     .node
       pop     edi esi ebx
 retn
;##########################################################################
freeNodes:
       push    esi
 mov     esi,[parent]
        jmp     .chk
.node:      pushd   [esi+NODE.hMemory] [esp]
    mov     esi,[esi+NODE.next]
 call    [GlobalUnlock]
      call    [GlobalFree]
.chk:       test    esi,esi
     jnz     .node
.quit:     pop     esi
 retn
;##########################################################################
listNodes:
       push    esi
 stdcall [SendDlgItemMessage],[mbp.hwndOwner],ID_MAIN_LIST,LB_RESETCONTENT,0,0
       mov     esi,[parent]
        jmp     .chk
.node:      ccall   [wsprintf],szValue,szIntegerFormat,[esi+NODE.value]
 stdcall [SendDlgItemMessage],[mbp.hwndOwner],ID_MAIN_LIST,LB_ADDSTRING,0,szValue
    mov     esi,[esi+NODE.next]
.chk:        test    esi,esi
     jnz     .node
.quit:     pop     esi
 retn
;##########################################################################
proc DlgInputBoxProc,hWnd,msg,wParam,lParam
  push    ebx esi edi
 ; find message
      mov     eax,[msg]
   mov     edx,inputboxmsg
.scan:   cmp     eax,[edx]
   jne     @F
  jmp     dword [edx+04h]
@@:      add     edx,08h
     cmp     dword [edx],0
       jne     .scan
       xor     eax,eax
     jmp     .quit

.initdlg:      ; INITDIALOG
        mov     ebx,[lParam]
        stdcall [SetDlgItemText],[hWnd],ID_INPUTBOX_PROMPT,[ebx+00h]
        stdcall [SetDlgItemText],[hWnd],ID_INPUTBOX_VALUE,[ebx+04h]
 stdcall [SetWindowLong],[hWnd],GWL_USERDATA,[lParam]
        xor     eax,eax
     inc     eax
 jmp     .quit
.command:  ; COMMAND
   mov     eax,[wParam]
        .if ax,e,ID_INPUTBOX_OK         ; OK
                stdcall [GetWindowLong],[hWnd],GWL_USERDATA
         stdcall [GetDlgItemText],[hWnd],ID_INPUTBOX_VALUE,[eax+04h],[eax+08h]
               stdcall [PostMessage],[hWnd],WM_CLOSE,1,0
   .elseif ax,e,ID_INPUTBOX_CANCEL ; Cancel
            stdcall [PostMessage],[hWnd],WM_CLOSE,0,0
   .endif
      jmp     .quit
.close:    ; CLOSE
     stdcall [EndDialog],[hWnd],[wParam]
.quit:       pop     edi esi ebx
 ret
endp
;##########################################################################
proc InputBox,pszPrompt,pszValue,dwValueLength
        lea     eax,[pszPrompt]
     stdcall [DialogBoxParam],[mbp.hInstance],IDD_INPUTBOX,[mbp.hwndOwner],DlgInputBoxProc,eax
   ret
endp
;##########################################################################
proc ustr2dw,pszInput
 mov     edx,[pszInput]
      xor     eax,eax
     xor     ecx,ecx
     jmp     .chk
.char:      mov     cl,[edx]
    sub     cl,"0"
    jb      .quit
       cmp     cl,"9"-"0"
      ja      .quit
       ; digit
     lea     eax,[eax*4+eax]
     add     eax,eax
     add     eax,ecx
     inc     edx
.chk:        cmp     byte [edx],0
        jne     .char
.quit:     ret
endp
;##########################################################################
;##########################################################################
;##########################################################################
;##########################################################################
section ".data" import data readable writeable
 library kernel32,"kernel32.dll",user32,"user32.dll"
     include "api/kernel32.inc"
        include "api/user32.inc"
;##########################################################################
   szAppTitle      db      _TITLE,0
    szMsgAbout      db      _TITLE,13,10
                        db      "version ",_VERSIONTEXT,13,10
                     db      "coded by comrade <comrade2k@hotmail.com>",13,10
                    db      "13.12.2003 - @DATE @TIME",13,10,13,10
                    db      "IRC:",9,"#asm, #coders, #win32asm on EFnet",13,10
                  db      "Web:",9,"http://comrade64.cjb.net/",13,10
                      db      9,"http://comrade.win32asm.com/",0
    szMenuAbout     db      "&About ",_TITLE,"...",0
    szValuePrompt   db      "Enter value:",0
      szIntegerFormat db      "%u",0
    mainmsg         dd      WM_INITDIALOG,DlgProc.initdlg
                       dd      WM_COMMAND,DlgProc.command
                  dd      WM_SYSCOMMAND,DlgProc.syscommand
                    dd      WM_CLOSE,DlgProc.close
                      dd      0
   inputboxmsg     dd      WM_INITDIALOG,DlgInputBoxProc.initdlg
                       dd      WM_COMMAND,DlgInputBoxProc.command
                  dd      WM_CLOSE,DlgInputBoxProc.close
                      dd      0
;##########################################################################
    mbp             MSGBOXPARAMS
        szValue         rb      20h

     parent          rd      01h
;##########################################################################
section ".rsrc" resource data readable
      ; identifiers
       IDV_MAIN                = 01
        IDI_MAIN                = 02
        IDI_COPY                = 03
        IDD_MAIN                = 20
        IDD_INPUTBOX            = 21
        ID_MAIN_LIST            = 01
        ID_MAIN_ADD             = 02
        ID_MAIN_EDIT            = 03
        ID_MAIN_REMOVE          = 04
        ID_MAIN_SORT            = 05
        ID_MAIN_ABOUT           = 06
        ID_MAIN_CLOSE           = 07
        ID_INPUTBOX_PROMPT      = 01
        ID_INPUTBOX_VALUE       = 02
        ID_INPUTBOX_OK          = 03
        ID_INPUTBOX_CANCEL      = 04
        ; resources
 directory RT_VERSION,versions,RT_DIALOG,dialogs
     resource versions,IDV_MAIN,SUBLANG_NEUTRAL+LANG_NEUTRAL,version
     resource dialogs, IDD_MAIN,SUBLANG_NEUTRAL+LANG_NEUTRAL,main,\
                       IDD_INPUTBOX,SUBLANG_NEUTRAL+LANG_NEUTRAL,inputbox
        ; version
   versioninfo version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,SUBLANG_NEUTRAL+LANG_NEUTRAL,0,\
           "FileDescription",_TITLE,\
               "LegalCopyright",<0A9h," comrade">,\
             "FileVersion",_VERSION,\
         "ProductVersion",_VERSION,\
              "ProductName",_TITLE,\
           "InternalName",_NAME,\
           "OriginalFilename",<_NAME,".exe">
 ; main dialog
       dialog main,_TITLE,0,0,240,102,DS_CENTER+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX,0,0,"Tahoma",8
              dialogitem "LISTBOX","",ID_MAIN_LIST,4,4,176,94,LBS_NOINTEGRALHEIGHT+WS_BORDER+WS_VSCROLL+WS_TABSTOP+WS_VISIBLE
         dialogitem "BUTTON","&Add",ID_MAIN_ADD,184,4,52,14,BS_PUSHBUTTON+WS_TABSTOP+WS_VISIBLE
              dialogitem "BUTTON","&Edit",ID_MAIN_EDIT,184,20,52,14,WS_TABSTOP+WS_VISIBLE
         dialogitem "BUTTON","&Remove",ID_MAIN_REMOVE,184,36,52,14,WS_TABSTOP+WS_VISIBLE
             dialogitem "BUTTON","&Sort",ID_MAIN_SORT,184,52,52,14,WS_TABSTOP+WS_VISIBLE
         dialogitem "BUTTON","A&bout...",ID_MAIN_ABOUT,184,68,52,14,BS_PUSHBUTTON+WS_TABSTOP+WS_VISIBLE
              dialogitem "BUTTON","&Close",ID_MAIN_CLOSE,184,84,52,14,BS_PUSHBUTTON+WS_TABSTOP+WS_VISIBLE
 enddialog
   ; inputbox dialog
   dialog inputbox,"Input Box",0,0,180,58,DS_CENTER+DS_MODALFRAME+WS_CAPTION+WS_SYSMENU,0,0,"Tahoma",8
             dialogitem "STATIC","",ID_INPUTBOX_PROMPT,4,4,172,12,WS_VISIBLE
         dialogitem "EDIT","",ID_INPUTBOX_VALUE,4,16,172,12,ES_AUTOHSCROLL+WS_TABSTOP+WS_VISIBLE+WS_BORDER
               dialogitem "STATIC","",0,4,34,172,12,SS_ETCHEDHORZ+WS_VISIBLE
           dialogitem "BUTTON","&OK",ID_INPUTBOX_OK,30,40,52,14,BS_DEFPUSHBUTTON+WS_TABSTOP+WS_VISIBLE
         dialogitem "BUTTON","&Cancel",ID_INPUTBOX_CANCEL,96,40,52,14,BS_PUSHBUTTON+WS_TABSTOP+WS_VISIBLE
    enddialog
;##########################################################################
;##########################################################################    
It compiles, but I didn't run it so there may be bugs or runtime errors that you need to fix.
Post 09 Feb 2012, 12:59
View user's profile Send private message Visit poster's website Reply with quote
FASMNOOB



Joined: 09 Feb 2012
Posts: 21
FASMNOOB
Awesome! It runs and adds nodes, sorts them fine!

What exactly did you change so I can learn from it?
Post 09 Feb 2012, 13:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
I removed the macro.inc include,
Rewrote the NODE structure definition,
Delete the deprecated "enter" after "proc".
Added "endp" to finish the "proc".

Also, just for cosmetic reasons, I deleted all the superfluous "OFFSET"s

[edit]I almost forgot: renamed "version" to "versioninfo" and "enddlg" to "enddialog".

Do a diff to check, in case I forgot to mention something.
Post 09 Feb 2012, 13:06
View user's profile Send private message Visit poster's website Reply with quote
FASMNOOB



Joined: 09 Feb 2012
Posts: 21
FASMNOOB
thanks a lot.
Post 09 Feb 2012, 13:16
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
I've tested kdiff3 and its good (on Windows) for that purpose because starting from Windows 7 they've forgotten about diff importance.
Post 16 Feb 2012, 09:41
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.