2 Replies - 377 Views - Last Post: 21 September 2017 - 10:21 AM

#1 sunshine33  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 15-September 17

What are these lines of code ?

Posted 21 September 2017 - 09:07 AM

Where can i learn more about these ?

extern  [email protected]
 extern  [email protected]
 extern  [email protected]
 extern  [email protected]


I found this code in this program , Not sure what it means .

%include "io.inc"

section .text
global CMAIN
CMAIN:
   
  ; ----------------------------------------------------------------------------
; hello.asm
;
; This is a Win32 console program that writes "Hello, World" on one line and
; then exits.  It uses only plain Win32 system calls from kernel32.dll, so it
; is very instructive to study since it does not make use of a C library.
; Because system calls from kernel32.dll are used, you need to link with
; an import library.  You also have to specify the starting address yourself.
;
; Assembler: NASM
; OS: Any Win32-based OS
; Other libraries: Use gcc's import library libkernel32.a
; Assemble with "nasm -fwin32 hello.asm"
; Link with "ld -e go hello.obj -lkernel32"
; ----------------------------------------------------------------------------

        global  go
        extern  [email protected]
        extern  [email protected]
        extern  [email protected]
        extern  [email protected]

        section .data
msg:    db      'Hello, World', 10
handle:         dd      0
read_handle dd 0
written:        db      0

        section .text
go:
        ; handle = GetStdHandle(-11)
        push    dword -11
        call    [email protected]
        mov     [handle], eax

        push -10  ; stdin
        call [email protected]
        mov [read_handle], eax

        ; WriteConsole(handle, &msg[0], 13, &written, 0)
        push    dword 0
        push    written
        push    dword 13
        push    msg
        push    dword [handle]
        call    [email protected]

        push eax
        mov eax, esp ; buffer for char?
        push 0
        push written ; reuse this?
        push 1 ; characters to read?
        push eax
        push dword [read_handle]
        call  [email protected]
        pop eax ; character read in al?

        ; ExitProcess(0)
        push    dword 0
        call    [email protected]
    xor eax, eax
    ret





Is This A Good Question/Topic? 0
  • +

Replies To: What are these lines of code ?

#2 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6552
  • View blog
  • Posts: 30,682
  • Joined: 10-May 07

Re: What are these lines of code ?

Posted 21 September 2017 - 09:14 AM

While it has been a while since I have done Assembly, extern I believe are calls from linked dll's. Those look to me like Windows API calls.
Was This Post Helpful? 0
  • +
  • -

#3 sunshine33  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 15-September 17

Re: What are these lines of code ?

Posted 21 September 2017 - 10:21 AM

I googled for "Assembly language windows api" and found few links which explains parts of it .

http://mathimaaran.a...ld_tutorial.htm

http://forum.codecal...th-windows-api/




Quote

The Win32 API


The Windows API (Application Programming Interface) includes the vast collection of data types, constants, functions, and structures used to create applications for the Windows OS. Most of the API functions, including ExitProcess which we used above, are stored in 3 main DLLs:

KERNEL32.DLL - Low level kernel services
GDI32.DLL - Graphics Device Interface: drawing and printing
USER32.DLL - User Interface controls, windows and messaging services

If you use windows API functions in your program, your program has to "import" the functions from the DLLs. Import libraries (.lib files) contain information the linker needs to resolve calls to functions residing in DLLs, so the system can load the specified DLL and locate the exported functions needed when your code is executed. For example, to call the ExitProcess function which resides in kernel32.dll, you must link your code with the import library kernel32.lib. However, the library file is not the only thing you need. An include file (kernel32.inc) is also needed.


Include (.inc) files contain "prototypes" which define the attributes of all functions stored in the DLL of the same name. These can be automatically generated from the library files using the lib2inc utiliy. There is no easy way of generating a library file from a given DLL but luckily most API functions you will require are located in DLLs for which the MASM32 distribution has appropriate library files.
The official Win32 API documentation is written for C and C++ programmers and a typical API function is defined in the following format:


Quote

include kernel32.inc - tells MASM to process the file named (as if the contents were copied into the sourcecode here)
includelib kernel32.lib - tells linker which import libraries to link with (kernel32.lib in this case).


[FONT=Tahoma][SIZE=3]ReturnType FunctionName ( ParamType1 ParamName1, ParamType2 ParamName2,...);
[/SIZE][/FONT]

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1