What is EXTRN in Intel-syntax assembly?

1.1k Views Asked by At

x86 CPU: MSVC (2010)

What does EXTRN _printf:PROC means in code bellow and why after ":" we use some "PROC" directive instead of "near" or "far"?

CONST   SEGMENT 
$SG3830 DB     'hello, world', 0AH, 00H 
CONST   ENDS 
PUBLIC  _main 
EXTRN   _printf:PROC  <- what is this funct?!
_TEXT   SEGMENT 
_main   PROC 
        push   ebp 
        mov    ebp,    esp 
        push   OFFSET  $SG3830 
        call   _printf 
        add    esp,    4 
        xor    eax,    eax 
        pop    ebp 
        ret    0 
_main   ENDP 
_TEXT   ENDS
1

There are 1 best solutions below

0
On BEST ANSWER

Appears you are reading Reverse Engineering for Beginners by Dennis Yurichev. In 32-bit FLAT model everything is considered a NEAR pointer (within the 4Gib address space). The concept of NEAR/FAR applied to things like the segmented address model of DOS programs. The code you are looking is the assembly code from the MSVC compiler(CL) for a 32-bit Windows console program.

EXTRN just means there is external linkage to a symbol that is a function/PROCedure in some other module/library/object that will eventually be linked to. Without the EXTRN directive the call _printf would produce an error since the _printf function is not defined in the current assembly file.