我想将c代码更改为程序集 [英] i want to change c code to assembly

查看:76
本文介绍了我想将c代码更改为程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了代码,我想将代码转换为汇编代码,以及如何编写外部文件并将代码执行到应用程序exe,以及如何将代码发送到机器代码。



I have write a c code and I want to convert the code to assembly , and also how I can write a external file and execute the code to the application exe, and how I can send the code to machine code.

// bin.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
# include <stdio.h>
int main()
{
    char a = 'a';
    int num1 = 0 / 8;
    int num2 = 1 / 8;
    int sum;

    switch(a) {
        case '+':
            if(num1 + num2)
            {
            sum = num1 + num2;
            }
            else
            {
             sum = num2 + num1;
            }
            break;
        case '-':
            if(num1 - num2)
            {
            sum = num1 - num2;
            }
            else
            {
             sum = num2 - num1;
            }
            break;
        case '*':
            if(num1 * num2)
            {
            sum = num1 * num2;
            }
            else
            {
             sum = num2 * num1;
            }
            break;
        case '/':
            if(num1 / num2)
            {
            sum = num1 / num2;
            }
            else
            {
             sum = num2 / num1;
            }
            break;
        default:

            break;
            }

    return 0;
}

推荐答案

嗯。它不是那么简单:C指令不一定转换为单个机器(或汇编)指令 - 特别是情况比你想象的更复杂。



可能最好的起点是使用谷歌为你选择的处理器找到一个反汇编程序(你没有指定它,并且汇编是处理器或处理器系列特定的,不像C)并查看编译的内容。



但是,如果你不知道汇编程序那么它可能没什么用。

至少,你可能会发现你的C编译器支持类似

Um. It's not that simple: a C instruction does not necessarily translate to a single machine (or assembly) instruction - and case in particular is a more complex operation than you might think.

Probably the best place to start is to use Google to find a disassembler for your chosen processor (you don't specify it, and assembly is processor or processor family specific unlike C) and look at what that compiles to.

However, if you don't "know assembler" then it probably won't help much.
At a minimum, you may find that your C compiler supports something like
#pragma ASM

,它允许你包括C源文件中的汇编代码 - 无需为小任务提供单独的汇编程序。

which allows you to include assembly code in your C source file - obviating the need for a separate assembler for small tasks.


嗯,Visual Studio提供了将C / C ++代码转换为ASM的功能。



为此,您只需按照指示进行操作n!



1.在线上设一个断点

Well, Visual Studio offer a functionality to convert C/C++ code to ASM.

To do that you only follow under instruction!

1. Make a break point at line
switch(a){



2.调试程序。

3.当光标处于调试点时,按Ctrl + F11。

你可以得到汇编代码来自你的编辑。

4.你必须写


2. Debug program.
3. When cursor is at debug point, press Ctrl+F11.
You can get assembly code from your Editor.
4. You have to write

__asm{
}



5.复制&将汇编代码粘贴到__asm {};

6.删除


5. Copy & Paste assembly code into __asm{};
6. Delete

switch(a){
...
default:
break;
}


这篇关于我想将c代码更改为程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆