Author Topic: use of register assumed to ERROR  (Read 21743 times)

Offline Fixer

  • Jr. Member
  • *
  • Posts: 11
use of register assumed to ERROR
« on: December 06, 2012, 11:55:53 PM »
I am converting some older code so it will assemble.
It's masm code.

I am getting this message from my compiler on the WHILE TRUE line.

Use of register assumed to ERROR

Thanks,
        Andy
Code: [Select]
invoke RegisterClassEx, addr wc ; register our window class

invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,280,150,NULL,NULL,hInstance,NULL ; Create the window
mov hwnd,eax

invoke ShowWindow, hwnd,CmdShow ; display our window
invoke UpdateWindow, hwnd

.WHILE TRUE ;  use of register assumed to ERROR

invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
Edit: Added code tags - fbk
« Last Edit: December 07, 2012, 02:03:57 AM by Frank Kotler »

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Re: use of register assumed to ERROR
« Reply #1 on: December 07, 2012, 12:22:47 AM »
From what I remember of MASM it should be

.while eax
    or
while (eax = TRUE)


Offline Fixer

  • Jr. Member
  • *
  • Posts: 11
Re: use of register assumed to ERROR
« Reply #2 on: December 07, 2012, 03:45:05 AM »
Thanks TightCoderEx, it helped me fix that problem.

I am down to two errors.

                MOV al, [esi]

               .IF al > 29h

1st error here .IF al AND al, 0Fh

2nd error here  .IF al SUB al, 55   
                     ADD byte ptr [edx+ecx], al


C:\masm32\SOURCE\fixer1.asm(365) : error A2008: syntax error : ,

C:\masm32\SOURCE\fixer1.asm(400) : error A2008: syntax error : SUB

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Re: use of register assumed to ERROR
« Reply #3 on: December 07, 2012, 02:27:26 PM »
Please show your code.  There is a little more going on here than just the errors you've shown and it might be helpful to you to see another version of your logic.

Offline Fixer

  • Jr. Member
  • *
  • Posts: 11
Re: use of register assumed to ERROR
« Reply #4 on: December 07, 2012, 03:50:40 PM »
I have comments on the lines with problems.

; last error in is LASTERR Error No impersonation token
; A.P.K.
 ; reparieren.asm Help from Fetter,Dave,Frank,qWord,
 ; To err is O.K. as long as there are too many.

Andy

Code: [Select]
start:

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD

LOCAL wc:WNDCLASSEX ; create local variables on stack
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX ; fill values in members of wc
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax

invoke RegisterClassEx, addr wc ; register our window class

invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,280,150,NULL,NULL,hInstance,NULL ; Create the window

mov hwnd,eax

invoke ShowWindow, hwnd,CmdShow ; show our window
invoke UpdateWindow, hwnd

.WHILE TRUE ; The MessageLoop use of register assumed to ERROR <error FIXED Friday, December 07, 2012>

invoke GetMessage, ADDR msg,NULL,0,0

.BREAK .IF (!eax)

invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg

.ENDW

mov eax,msg.wParam
ret

WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL Fpointer

.IF uMsg==WM_CREATE

; Create 2 buttons and 2 editboxes

invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,ADDR WinName,WS_CHILD,30,15,210,20,hWnd,StringID,hInstance,NULL

 ; invoke CreateWindowEx,WS_EX_LEFT or WS_EX_ACCEPTFILES,
 ;                           ADDR szClassName,
 ;                           ADDR szDisplayName,
 ;                           WS_OVERLAPPED | WS_VISIBLE,                       
 ;                           Wtx,Wty,Wwd,Wht,
 ;                           NULL,NULL,
 ;                           hInstance,NULL

 ; CreateWindowEx(
 ;
 ;     DWORD dwExStyle, // extended window style
 ;     LPCTSTR lpClassName, // pointer to registered class name
 ;     LPCTSTR lpWindowName, // pointer to window name
 ;     DWORD dwStyle, // window style
 ;     int x, // horizontal position of window
 ;     int y, // vertical position of window
 ;     int nWidth, // window width
 ;     int nHeight, // window height
 ;     HWND hWndParent, // handle to parent or owner window
 ;     HMENU hMenu, // handle to menu, or child-window identifier
 ;     HINSTANCE hInstance, // handle to application instance
 ;     LPVOID lpParam // pointer to window-creation data

mov hwndString,eax

; I think there are mistakes in some/all of these CreateWindowsEX :-)

invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or ES_AUTOHSCROLL,30,40,210,20,hWnd,NStringID,hInstance,NULL

mov hwndNString,eax

invoke SetFocus, hwndString

invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonOpen,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,50,70,85,20,hWnd,ButtonOpenID,hInstance,NULL

mov hwndOpen,eax

invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonPatch,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,150,70,85,20,hWnd,ButtonPatchID,hInstance,NULL

mov hwndPatch,eax

.ELSEIF uMsg==WM_COMMAND

mov eax,wParam
mov edx,wParam
shr edx,16

.IF dx==BN_CLICKED

.IF ax==ButtonOpenID ; Open button clicked?

mov ofn.lStructSize,SIZEOF ofn
mov ofn.lpstrFile, OFFSET FilePath
mov ofn.lpstrFilter, OFFSET FilterString
mov ofn.nMaxFile,MAXSIZE
mov ofn.Flags, OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ofn.lpstrTitle, OFFSET Caption

invoke GetOpenFileName, ADDR ofn

.IF eax == TRUE

; Open file to be repaired
invoke CreateFile, ofn.lpstrFile, GENERIC_READ OR GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL

.IF eax!=INVALID_HANDLE_VALUE

mov hFile, eax
Invoke GetFileSize, hFile, NULL

mov FSize, eax ; Save FileSize
Invoke GlobalAlloc, GMEM_FIXED, FSize
mov FPointer, eax

.IF eax == NULL ; If no pointer, error message

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoMem
push OFFSET Error

JMP MESSAGE

.ENDIF

Invoke ReadFile, hFile,FPointer,FSize, ADDR Numb, NULL

.ELSE ; error message if no valid handle

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoFile
push OFFSET Error

jmp MESSAGE

.ENDIF

.ENDIF

.ELSEIF ax == ButtonPatchID ; See if Fix Button has been hit

Invoke GetDlgItemText,hWnd,StringID,ADDR StringBuf,MAXSTR ; Get first string
mov StrLenA, eax ; Save string length

Invoke Convert,ADDR StringBuf, ADDR OString ; Convert to bytes

Invoke GetDlgItemText,hWnd,NStringID,ADDR NStringBuf,MAXSTR ;Get 2nd string

.IF eax != StrLenA ; both strings equal?

push MB_OK OR MB_ICONINFORMATION ; If not, error message
push OFFSET Error
push OFFSET NotEqual
JMP MESSAGE

.ENDIF

Invoke Convert,ADDR NStringBuf, ADDR NString ; Convert to bytes

mov edi,FPointer ;move pointer to memory to edi
mov ecx,FSize ;move Filesize to ecx
mov esi,offset OString ;set ESI to the Opcode string we search
mov al, byte ptr [esi] ;move the first byte of the string to AL

SEARCH :

repnz scasb ;repeat until ECX=0 or AL equals the value of the byte [EDI], EDI is incremented by 1 every run

cmp ecx,0 ;If ECX=0, no matching string is found

jz NOT_FOUND

FOUND_A_MATCH :         ;found matching byte
push ecx                ;save registers
push edi
push esi
dec edi                 ;EDI-1 because REPZ added 1 byte to much
mov ecx,StrLen2         ;ECX = length of the string
repz cmpsb              ;repeat until the values in the memory o ;[EDI] and [ESI] are not equal, or ecx=0
cmp ecx,0               ;If ecx = 0, we have found the correct string

jz PATCH_IT

pop esi                 ;Restore registers for continuing search
pop edi
pop ecx
jmp SEARCH              ;go on with search

PATCH_IT :

pop esi
pop edi
pop ecx
dec edi ;EDI - 1
inc ecx ;ECX + 1
mov eax,FSize
sub eax,ecx ;compute the File Offset to fix (FileSize - Remaining bytes (ecx) = Offset to fix)

Invoke SetFilePointer, hFile, eax, NULL, FILE_BEGIN

Invoke WriteFile, hFile,offset NString, StrLen2, ADDR Numb, NULL

mov eax, Numb
.IF eax == StrLen2 ; bytes written = Bytes to write ?

push MB_OK ; If so success-message
push OFFSET AppName
push OFFSET Done

JMP MESSAGE

.ELSE

push MB_OK OR MB_ICONINFORMATION ; If not, error message
push OFFSET Error
push OFFSET WrFile

.ENDIF

NOT_FOUND :

push MB_OK OR MB_ICONINFORMATION ; If no handle, error message
push OFFSET Error
push OFFSET NotFound

MESSAGE :

push NULL
Call MessageBox

.ENDIF

.ENDIF


.ELSEIF uMsg==WM_DESTROY ; Close program

invoke CloseHandle, hFile ; Release handle
invoke GlobalFree,Fpointer ; Release memory block
invoke ExitProcess,eax ; Exit
invoke PostQuitMessage,NULL

.ELSE

invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret

WndProc endp

; This routine converts the ascii strings to their byte equivalent. eg
; string 7415FF -> 74h,15h,FFh
; Use only numbers, and uppercase letters (A,B,C,D,E,F)

; Change a string to its byte equivalent.
; Use only numbers, and uppercase letters

Convert proc LpBuffer:DWORD,LpString:DWORD

    push eax
    push esi
    push ecx
    push edx
    mov esi, LpBuffer
    mov edx, LpString
    xor ecx, ecx

MORE :

    MOV al, [esi]

    .IF al > 29h
       
        .if al&0Fh

            IMUL eax, 10h

        .ELSE

        .IF al>64

            .IF al

                SUB al, 55

                IMUL eax, 10h

            .ENDIF

        .ENDIF

    .ENDIF

    .ENDIF

    MOV byte ptr [edx+ecx], al
    INC esi
    mov al, [esi]

  .IF al >29h

      .if al&0Fh

            ADD byte ptr [edx+ecx], al

        .ELSE

            .IF al > 64

                 sub al,55

                .if !ZERO?

                    ADD byte ptr [edx+ecx], al

                .ENDIF

            .ENDIF

        .ENDIF

        .ENDIF

            .IF byte ptr [edx+ecx] != NULL

                INC esi
                INC ecx
                JMP MORE

            .ENDIF
            mov StrLen2, ecx

            pop edx
            pop ecx
            pop esi
            pop eax

            ret

Convert endp

end start

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Re: use of register assumed to ERROR
« Reply #5 on: December 07, 2012, 07:11:09 PM »
To get help with the example you've shown an MASM forum would be a better alternative.  Not that some of us here don't know about MASM, but this is after all, this is an NASM forum.

Offline Fixer

  • Jr. Member
  • *
  • Posts: 11
Re: use of register assumed to ERROR
« Reply #6 on: December 07, 2012, 07:47:49 PM »
I am getting help there also.

My program is assembling and compiling fine, but it's not running correctly.

Andy