如何直接在Ada中访问内存地址? [英] How do I access memory addresses directly in Ada?

查看:149
本文介绍了如何直接在Ada中访问内存地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我是Ada的新手,我正在尝试在其中编写内核,但是似乎找不到关于如何正确执行此操作的任何好信息.在C语言中,我会写:

So I'm new to Ada, and I'm attempting to write a kernel in it, but I cannot seem to find any good information on how to do this properly. In C, I would write:

unsigned char* videoram = (char*) 0xB8000;
videoram[0] = 65;

直接访问视频ram并向其中写入"a".我听说我需要使用Ada数组和其他编译指示在Ada中以类型安全的方式执行此操作.这种Ada编程有什么好的资源吗?

to access the video ram directly and write 'a' to it. I've heard I need to use an Ada array and other pragma's to do this in a typesafe manner in Ada. Is there any good resources on this kind of Ada programming?

推荐答案

您可以使用'Address属性:

Videoram : String (1 .. Videoram_Size);
for Videoram'Address use 16#B8000#;
-- ...
Videoram (1) := 'a';

如果您不想使用字符串和字符,则可以定义自己的数据类型.如:

If you don't want to use String and Characters, you can define your own data types.. like:

type Byte is mod 2**8; -- unsigned char
type Byte_Array is array (Natural range <>) of Byte;
Videoram : Byte_Array (0 .. Videoram_Size - 1);
for Videoram'Address use 16#B8000#;
-- ...
Videoram (0) := 65;

顺便说一句,您甚至可以对索引进行范围检查,因此您不能写在Videoram范围之外.

Btw, you even get range checking for the index, so you can't write outside of the Videoram range.

这篇关于如何直接在Ada中访问内存地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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