如何读取C ++中的硬编码地址的值? [英] How to read a value of an hard coded address in C++?

查看:284
本文介绍了如何读取C ++中的硬编码地址的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找读取地址302H中的值。目的是从硬件(104pc堆栈的一部分)读取输入。当我运行下面的代码a得到这个错误:未处理的异常在0x004134b9在setOutput.exe:0xC0000005:访问冲突读取位置0x00000302

I am looking to read the value that is located in address 302H. The purpose is to read an input from hardware (a part of a 104pc stack). When I run the following code a get this error: Unhandled exception at 0x004134b9 in setOutput.exe: 0xC0000005: Access violation reading location 0x00000302.

#include <stdlib.h> 

#define PORTBASE 0x302
int _tmain(int argc, char *argv[])
{
    int value;
    int volatile * port = (int *) PORTBASE;
    printf("port = %d\n", port);
    value = *port;
    printf("port value = %d\n", value);
}

编辑:

我运行这下widows xp。只有文档我可以在板上找到

I am running this under widows xp. Only Documentation I can find on the board is below

编辑:

在下面的答案中,我可以看到我需要为板子编写驱动程序。

From your answers below, I can see that I need to write a driver for the board. Can someone point me to a resource on how to do so?

推荐答案

为了在Windows下直接访问物理内存,您需要开发驱动程序。我建议您阅读虚拟地址空间,了解原因。简短的故事:从用户模式进程看到的内存地址与物理内存地址无关,硬件生存的地址受操作系统保护,以防止用户模式应用程序弄乱事情。

In order to access physical memory directly under Windows, you need to develop a driver. I suggest you read up on Virtual Address Space to see why. The short story: The memory addresses you see from a usermode process has no relation to physical memory addresses, and the addresses where hardware lives are protected by the OS to prevent usermode applications from messing up things.

这篇关于如何读取C ++中的硬编码地址的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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