Author Topic: [SOLVED] Issue While Working On My Homework (LNK2001 Error)  (Read 232 times)

kennyd8200

  • Regular Member
  • *
  • Posts: 2
[SOLVED] Issue While Working On My Homework (LNK2001 Error)
« on: September 06, 2020, 07:47:11 AM »
So I am new to the programming world, I started a class on microprocessors this semester and our first lab is using Visual Studio to create an Assembly file to add two numbers. I have followed the instructions completely and keep coming up with error code LNK2001 unresolved external symbol _MAIN   LINK  Line 1, followed by LNK1120. I had a Zoom meeting with my professor today and he can't even understand the problem with it. If anyone can help, please go into as much detail as possible as I am pretty much illiterate when it comes to coding. This is what I'm working with.

 .MODEL  FLAT
 .DATA
 .CODE

main   PROC
      ;----- CLEAR CONTENTS OF REGISTERS -----
      xor eax,eax
      xor ebx,ebx
      xor ecx,ecx
      xor edx,edx
      ;----- BEGIN MAIN PROCEDURE HERE -----

      mov  ax,5
      add  ax,3

      ;----- END MAIL PROCEDURE HERE -----
      ret
main   ENDP

END
« Last Edit: September 06, 2020, 09:44:24 AM by kennyd8200 »

fearless

  • Member
  • ***
  • Posts: 480
    • LetTheLightIn
Re: Issue While Working On My Homework (LNK2001 Error)
« Reply #1 on: September 06, 2020, 09:11:40 AM »
I would add stdcall to the model directive and precede with a processor directive .386 as an example, and end with the end pointing to the main proc
Code: [Select]
.386
.MODEL FLAT, STDCALL
.DATA
.CODE

main PROC
      ;----- CLEAR CONTENTS OF REGISTERS -----
      xor eax,eax
      xor ebx,ebx
      xor ecx,ecx
      xor edx,edx
      ;----- BEGIN MAIN PROCEDURE HERE -----

      mov  ax,5
      add  ax,3

      ;----- END MAIL PROCEDURE HERE -----
      ret
main ENDP

END main
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

kennyd8200

  • Regular Member
  • *
  • Posts: 2
Re: Issue While Working On My Homework (LNK2001 Error)
« Reply #2 on: September 06, 2020, 09:44:00 AM »
You sir, are a life saver. I used all parts that you suggested and got a success notification, did a little edit and found out that stdcall was the only necessary addition. Thank you for your help!

mineiro

  • Member
  • ****
  • Posts: 644
Re: Issue While Working On My Homework (LNK2001 Error)
« Reply #3 on: September 06, 2020, 09:54:41 AM »
hello sir kennyd8200;
Code: [Select]
ENDWhen you code this way (remove that line or comment), you're doing a module that will be added (agregate) to other modules to form final executable or a library (like dll files or .lib files), well, read object files that will be joined to final executable file.
You need specify where your program will start, the address (entry point) of your program by adding a label (memory address) to that as fearless point you.
Please, next time post your command line too, will be more easy to help you. Assembler (linker) have an option to you specify what's the entry point of your program in command line instead of being in code.
Windows adopt some rules to programs runs fine in it, this means that we need follow rules to our program runs in windows, and better, others can call our "modules" if they follow rules. Thats the "stdcall".
Good lucky man, keep walking.

---edited--- linker, (remove that line or comment)
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

deeR44

  • Regular Member
  • *
  • Posts: 28
Re: [SOLVED] Issue While Working On My Homework (LNK2001 Error)
« Reply #4 on: September 11, 2020, 05:21:07 PM »

Zeroing the registers does nothing useful.

I can't imagine what you mean by "Begin a Mail Procedure." I worked for the Postal Service for thirty years and never once began a "mail procedure." And I was a Systems Analyst.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7608
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: [SOLVED] Issue While Working On My Homework (LNK2001 Error)
« Reply #5 on: September 11, 2020, 05:54:06 PM »
I imagine it was only test code.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: