0

I have a program that was an example from our textbook, however when i put it in visual studio i get all kinds of errors. I am very new to Assembly, so I don't really know what this code is supposed to do, and i don't know why it is not working. Here is the code:

.model flat,c
.code

; extern "C" int CalcResult1_(int a, int b, int c);

CalcResult1_ proc
    push ebp
    mov ebp,esp

    mov eax,[ebp+8]
    mov ecx,[ebp+12]
    mov edx,[ebp+16]
    
    add eax,ecx
    imul eax,edx
    pop ebp
    ret
CalcResult1_ endp
    end

Here are the errors it gives:

1>------ Build started: Project: CompOrgHW2, Configuration: Debug Win32 ------ 1>assembly_.asm

1>g:\comporghw2\comporghw2\assembly_.asm(1): error C2059: syntax error: '.'

1>g:\comporghw2\comporghw2\assembly_.asm(2): error C2059: syntax error: '.'

1>g:\comporghw2\comporghw2\assembly_.asm(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>g:\comporghw2\comporghw2\assembly_.asm(7): error C2365: 'CalcResult1_': redefinition; previous definition was 'function'

1>g:\comporghw2\comporghw2\assembly_.asm(4): note: see declaration of 'CalcResult1_'

1>g:\comporghw2\comporghw2\assembly_.asm(7): error C2146: syntax error: missing ';' before identifier 'proc'

1>Done building project "CompOrgHW2.vcxproj" -- FAILED.

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Community
  • 1
  • 1
Kyounge1
  • 23
  • 3
  • 1
    Apparently you tried to build this assembly file with the C compiler. That won't work. You need to assemble it. See [this answer](https://stackoverflow.com/a/4549741/547981) – Jester Sep 21 '18 at 18:18
  • Well I followed those instructions, and it still didn't work. So then, i right clicked on the actual assembly_.asm file, went to properties, and changed the item type from C/C++ compiler to Microsoft Macro Assembler. Now, i am getting all sorts of syntax errors. – Kyounge1 Sep 21 '18 at 18:32
  • Then update your question to show the actual errors. Looks like valid 32-bit code to me, but it won't assemble as 64-bit because `push ebp` isn't encodable in 64-bit code. – Peter Cordes Sep 22 '18 at 00:48

0 Answers0