0

I am in an Assembly language class in college and we are working on assignment that prints data using printf. In class we use Visual Studio Professional 2015 but on my laptop I have Visual Studio Community 2017. In class we change have to change the toolset to a 2013 version but my visual studio does not have that. Here is my code: (it worked perfectly in class but I get errors when running it on my pc):

; Author:  Keenan Kaufman
; Date:    9/20/2017

.586
.MODEL FLAT, STDCALL

INCLUDELIB msvcrt.lib

EXTERN printf:NEAR
EXTERN exit:NEAR

.STACK  4096

.DATA


plain   BYTE    'Hello, World!'
key     BYTE    02h
cipher  BYTE    SIZEOF plain DUP(?)


.CODE
main   PROC
   sub  eax, eax             ; clear registers
   sub  ebx, ebx
   sub  ecx, ecx

   mov  ebx, 0               ; index into strings
   mov  ecx, SIZEOF plain    ; number of chars in strings
   lea  esi, plain      
   lea  edi, cipher
COPYCHAR:
    mov al, [esi]
    add al, key
    mov [edi], al

    inc esi
    inc edi
    loop COPYCHAR

    lea eax, cipher
    push eax


    call printf               ; call printf C function

   add  esp, 4               ; clean up stack

   mov  eax, 0               ; exit with
   call exit                 ;   return code 0
main   ENDP

END

Any help would be appreciated! Thank You!

  • This is the error I get: "unresolved external symbol _printf referenced in function _main@0" – Keenan Kaufman Sep 25 '17 at 01:02
  • Sounds like you are failing to tell the linker to include the c runtime. – David Wohlferd Sep 25 '17 at 01:26
  • @DavidWohlferd Sorry but I am very new to this kind of programming. How would I do that? – Keenan Kaufman Sep 25 '17 at 01:32
  • Are you building as 64-bit on the machine where it doesn't work? Or as 32-bit? IDK visual studio and Windows libraries, but that might be the difference. – Peter Cordes Sep 25 '17 at 02:30
  • 1
    I was able to figure it out. I am using visual studio 2017 but the toolset platform I needed to use for printf to work was Visual Studio 2013 v120. So I installed Visual Studio 2013 and it now works for 2017. – Keenan Kaufman Sep 25 '17 at 02:41
  • 1
    Possible duplicate of [Call C standard library function from asm in Visual Studio](https://stackoverflow.com/questions/33721059/call-c-standard-library-function-from-asm-in-visual-studio) – Michael Petch Sep 25 '17 at 13:51

0 Answers0