用C ++或C#编写程序以计算内容 [英] write a program in c++ or c# to calculate the contents

查看:61
本文介绍了用C ++或C#编写程序以计算内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生;

我想用C ++或C#编写程序来计算工作寄存器的内容.
您能帮我解决这个问题吗?我该怎么写?

在此先感谢
Dalia

Dear sir;

I want to write a program in c++ or c# to calculate the contents of the working registers.
Can you help me in this issue? how can I write it?

Thanks in advance
Dalia

推荐答案

听起来您需要使用汇编语言来实现这一目标.您可以通过仅使用汇编代码来编写独立程序来完成此工作(颇具挑战性),或者在C ++编译器中使用嵌入式汇编程序.请参见此处 [
It sounds like you need to use assembler language to achieve this. You can do it by writing a stand-alone program using only assembler code (quite a challenge), or use the inline assembler in the C++ compiler. See here[^] for some useful guidelines.


通常建议您使用Google做一些工作.
寄存器是特定于CPU的,您将需要直接使用CPU指令来读取它们的值.这将需要汇编语言功能或内联ASM.

您尚未声明CPU或OS,因此您似乎尚未完成过多的作业.

从这里,我得到了这个示例来阅读英特尔EDX:

http://sim0n.wordpress.com/2009/04/15/c-getting -register-values/ [ ^ ]

As is often suggested you will need to do a little work using Google.
Registers are CPU specific and will you will need to employ CPU instructions directly to read their values. This will require assembly language functions or inlining ASM.

You have not stated CPU or OS so you seem not to have done too much homework yet.

From here I got this example to read Intel EDX:

http://sim0n.wordpress.com/2009/04/15/c-getting-register-values/[^]

#include <iostream>

void setEDX(int value) {
	//Moves 'value' into edx
	_asm mov edx, value;
}

int getEDX() {
	int value;
	//Moves edx into 'value'
	_asm mov value, edx;
	return value;
}

int main()
{
	int edxValue = getEDX() ; //Get Register
	std::cout << "EDX: " << edxValue << "\n"; // Display

	std::cout << "Set EDX Value: ";
	int value;
	std::cin >> value; //Get input
	setEDX(value); //Set register

	edxValue = getEDX() ; //Get Register
	std::cout << "EDX: " << edxValue << "\n"; //Display

	system("pause");
	return 1 ;
}


努力理解这个示例,您将可以从事业务.

对要检查的所有CPU寄存器重复此过程.

如果不是您需要的CPU寄存器,而是设备寄存器(例如UART),则可以使用相同的技术.


Work on understanding this example and you will be in business.

Repeat this process for all the CPU registers you wish to examine.

If it is not CPU registers you need but device registers (eg UART) then the same technique can be used.


问题不容易解决和调试,但这确实可行.最简单的基本思想是将寄存器压入堆栈.然后,您可以修改用于将数据从堆栈移动到某些内存的任何寄存器,例如,表示输出参数在堆栈帧中的位置或通过其地址传递的某些结构.然后,您可以还原堆栈或仅在返回时使用它.通常,您不需要保存指令指针,因为您可以使用返回地址的某些函数的地址.

—SA
The problem is not easy to solve and debug, but this is quite doable. The simplest basic idea is to push registers to stack. Then you can modify any registers used to moving data from stack to some memory, for example, representing the location of output parameters in the stack frame or some structure passed by its address. Then you restore the stack or just use it on return. Usually, you don''t need to save instruction pointer, as you can use the address of some function of return address.

—SA


这篇关于用C ++或C#编写程序以计算内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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