visual-studioassemblydlllabelmasm

How to fix: (cannot have implicit far jump or call to near label) and (use a register assumed to ERROR)


I'm trying to create dll using VS 2017.

The dll will have one proc: symbol_count.

It asks to enter the string and then set symbol what is needed to count.

.def file

LIBRARY  name  
EXPORTS  
    symbol_count   

Code:

.586
.model flat, stdcall
option casemap: none 

include C:\masm32\include\windows.inc 
include C:\masm32\include\user32.inc 
include C:\masm32\include\msvcrt.inc

includelib C:\masm32\lib\msvcrt.lib
includelib C:\masm32\lib\user32.lib 

.data
msg_string db 'Enter string: ', 0
msg_symbol db 'Enter symbol: ', 0
result db 'Count = %d', 0
str_modifier db '%s', 0
sym_modifier db '%c', 0

.data
string db ?
symbol db ?

DllEntry PROC hInstDLL:DWORD, reason:DWORD, reserved:DWORD  
    mov  eax, 1  
    ret 
DllEntry ENDP 

symbol_count PROC  

    invoke crt_printf, OFFSET msg_string
    invoke crt_scanf, OFFSET str_modifier, OFFSET string
    invoke crt_printf, OFFSET msg_symbol
    invoke crt_scanf, OFFSET sym_modifier, OFFSET symbol

    xor esi, esi
    xor ecx, ecx

    mov ebx, OFFSET string
    mov ecx, eax
    mov al, symbol
loop1: <------------------------------------------ A2108
    cmp byte ptr [ebx + ecx], 0
    je endloop <------------------------------ A2107
    cmp al, byte ptr [ebx + ecx]
    jne next <-------------------------------- A2107
    inc esi
next: <------------------------------------------- A2108
    inc ecx
    jmp loop1 <------------------------------- A2107
endloop: <---------------------------------------- A2108

    invoke crt_printf, OFFSET result, esi

    ret 

symbol_count ENDP 

End DllEntry

Here is the list of error messages, what a compiler gives to me: ( in the code, I marked the places where the compiler swears)

A2108 use of register assumed to ERROR
A2108 use of register assumed to ERROR  
A2108 use of register assumed to ERROR  
A2107 cannot have implicit far jump or call to near label
A2107 cannot have implicit far jump or call to near label
A2107 cannot have implicit far jump or call to near label
procedure argument or local not referenced : hInstDLL      } all this points
procedure argument or local not referenced : reason        } to DllEntry ENDP 
procedure argument or local not referenced : reserved      } 

Solution

  • "You put your code into the .data section which may or may not cause some of the errors. The last 3 should just be warnings as you don't use the arguments." – @Jester