Home > Back-end >  How to write assembly under vs2015, call the stdio library function?
How to write assembly under vs2015, call the stdio library function?

Time:09-18

How to write assembly under vs2015, call the stdio library function?

CodePudding user response:

Why do you want?

CodePudding user response:

Because writing a file, and then can run under vs2013 but cannot run in 2015 and 2017, in the code is used to print the stdio library, have MSVCRT. Lib, but can't use at present

CodePudding user response:

The source code with vs2015 recompile,

CodePudding user response:

Tried, can't, the file, I write my own on/vc/include, and then in the code contains the file, I really just want to use the stdio print, but still won't do in 2015 and 2017, 2010 and 2013

CodePudding user response:

You used to write papers? Call the print function?

CodePudding user response:

; VcIO. Inc declarations for standard I/O, the console I/O Function as
; Copyright (c) FCL 2010. All rights reserved.
686
.The model flat, stdcall
Option casemap: none; Case sensitive
;=======================================================================
; Assembly language can invoke the C/C + + language library functions, as long as the C language library functions show the prototype can,

Includelib MSVCRT. Lib; C language of the stdio. H conio. H runtime library
; C the Run - Time Libraries (CRT)
; C I/O library function prototype description
; Function as
C: printf PROTO dword, : vararg; Vararg parameter: a variable parameter, the number of parameter uncertainty
The scanf PROTO C: dword, : vararg; Dword parameters: the format description list of valid address,
_getch PROTO C: vararg; Note: all the parameters are dwords type!
C: _kbhit PROTO vararg
;=======================================================================

This is the written. Inc file, then the code is
; The Template for the Win32 Console Application, 2008
The include vcIO. Inc
. The data; Set the data segment
Hello byte 'hello MAS32', 0; String
FrmStr byte '% s', 0 ah, 0; According to the format of the string description string, 0 ah:
"\ n"The code
The main proc
Pushad; Protect the eight general-purpose registers
Invoke the printf, offset frmStr, offset the hello; According to string
Popad; Restore eight general-purpose registers
Ret. Return to the Windows
The main endp
; (insert additional procedures here)
End the main; The end of the assembly

CodePudding user response:

Because you use the wrong library, starting from the vc + + 2015, part of the standard library function has been changed to the inline function, so libcmt. Lib, MSVCRT. Do not have these functions of symbols, lib from assembly code calls these library functions will appear in the Unresolved external symbol XXX referenced in the function...
Solution is simple, the use of the old version of the library, such as the masm32 own MSVCRT. Lib, or with vc + + belt dumpbin. Exe, lib. Exe corresponding DLL generated from import libraries,

CodePudding user response:

;//VS15/17 Template for Win32 Console Application
686
.The MODEL flat, stdcall
Option casemap: none

Includelib ucrt. Lib
Includelib MSVCRT. Lib
; Function as
Puts PROTO C: dword
Printf PROTO C: dword, : vararg

.data
Hello byte "Hello", 10, 0
The code
The main proc
Invoke the puts, offset the Hello
; Invoke the printf, offset the Hello
Ret

The main endp
In the end the main

Code contains MSVCRT. Lib or MSVCRTD. Print all have no way to run after the lib, you said that I learned the, but I still don't know how to solve,

CodePudding user response:

Thank you, I have found the way to solve the
;//VS15/17 Template for Win32 Console Application
686
.The MODEL flat, stdcall
Option casemap: none


Includelib ucrt. Lib
Includelib legacy_stdio_definitions. Lib

; Function as

Printf PROTO C: dword, : vararg
_getch PROTO C: vararg

.data
Hello byte "Hello", 10, 0
The code
The main proc

Invoke the printf, offset the Hello
Invoke _getch

Ret

The main endp
In the end the main
In this way, at the same time, contains both. Lib

CodePudding user response:

The measured directly with the masm32 MSVCRT lib is allowed, generated. Exe 3 KB, you can also like this, just generated. Exe, 4 KB,
  • Related