How to run and debug assembly code in Visual Studio?

Source: Internet
Author: User
Tags visual studio 2010
The simplest method is to directly write the Assembly using _ ASM {} in the C ++ file of vs2010. Code The instance code is as follows:
 
# Include<Iostream>Using namespaceSTD;IntMain (){CharA [10] ="1234";_ ASM{Push eax push edX push ECx Lea eax, a mov Cl, byte PTR [eax] mov DL, byte PTR [eax] movzx ECx, CL movzx edX, dl shr ECx, 4 SHL edX, 4 or ECX, EDX mov byte PTR [eax], CL Inc eax mov Cl, byte PTR [eax] Pop ECx pop edX pop eax }}

In addition, the compilation code is thoroughly written. The specific steps are as follows and will not be translated.

How to Use vs2010 to write assembly

====================================

Using Visual Studio to write an assembly program may be tricky. specific steps are to be followed in order to be able to create your first MASM x86 assembly program with vs2010 (images from the configuration steps mentioned below are taken from here ):

Expand'Other project types'Tree, select'Visual Studio Solutions', And create a new'Blank Solution'.

File | add | new project...

Expand'Other ages','Visual c ++','General'Section and create a new'Empty Project'.

Now right click on the project in the Solution Explorer and select'Build mizmizations...'.

Tick'MASM'Box and say OK.

Add a new file to the project with. ASMExtension by Right clicking on the project in the Solution Explorer and selecting'Add | new item...'Then'Text File'. Enter a filename ending. ASM(E.g. Test. ASM). Press OK.

Now (and if you skipped the last steps, this won't work) Right click on the project and select'Properties'. You shoshould see a dialog like this (note the MASM item at the bottom of the tree). If you don't, then something went wrong.

There are a few critical things to set up in the linker options in order to get it to work:

Set the following property to Windows or console as appropriate:

Configuration Properties> linker> system> Subsystem

Set the entry point to the name of your main method (as per the end directive-see Code ):

Configuration Properties> linker> advanced> entrypoint

All you have to do now is write some code and run it.

 

Following the steps above, I successfully ran and debugged a piece of assembly code. below is mySource codeAnd debugging.

. 586; target processor. use instructions for Pentium class machines

. Model flat, C; use the flat memory model. Use C calling conventions

. Stack; define a stack segment of 1kb (not required for this example)

. Data; create a near data segment. Local variables are declared after

; This directive (not required for this example)

. Code; indicates the start of a code segment.

Main proc

Push EBP

MoV EBP, ESP

Movedx, 80002418 H

XOR eax, eax

MoV ECx, 20 h

Sft1:

SHR edX, 1

JNC loop1

INC eax

Loop1:

Loop sft1

Pop EBP

RET

Main endp

End

 

 

 

References

======================================

Assembly programming with Visual Studio 2010

Http://www.codeproject.com/Articles/271627/Assembly-Programming-with-Visual-Studio-2010

Assembly sample source codes

Http://www.assembly.happycodings.com/code6.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.