在C语言中,我该如何写入特定的存储位置,例如DOS中的视频内存b800(实际DOS,MS DOS 6.22) [英] In C, how do I write to a particular memory location e.g. video memory b800, in DOS (real DOS, MS DOS 6.22)

查看:211
本文介绍了在C语言中,我该如何写入特定的存储位置,例如DOS中的视频内存b800(实际DOS,MS DOS 6.22)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C语言中,我如何写入特定的存储位置,例如视频内存b800,在DOS中(实际DOS,MS DOS 6.22)

In C, how do I write to a particular memory location e.g. video memory b800, in DOS (real DOS, MS DOS 6.22)

我了解到C并没有内置任何功能,但是可能会有一些特定于平台的信息,例如可以使用的DOS专用API函数.

I understand that C doesn't have anything built in to do that, but that there may be some platform specific e.g. DOS specific API functions that can.

一个小的演示程序就可以了.

A small demo program that does it would be great.

我有Turbo C(TCC.EXE-不是很小的c编译器,Turbo C编译器)

I have Turbo C (TCC.EXE - not tiny c compiler, Turbo C compiler)

我知道debug可以做到(例如,我所知道的一些调试细节)-f b800:0 FA0 21 CE(在命令行中写了一些感叹号).但是我想要一个C程序来写入b800:0

I know debug can do it (e.g. some of the tiny bit of debug that I know) -f b800:0 FA0 21 CE (that writes some exclamation marks to the command line). But i'd like a C program to write to b800:0

推荐答案

地址b800:0000使用段0xb800和偏移量0x0000.这对应于线性地址0xb8000(请注意额外的0,因为该段向左移4位).

The address b800:0000 uses a segment of 0xb800 and an offset of 0x0000. This corresponds to the linear address 0xb8000 (note the extra 0, as the segment is shifted left by 4 bits).

要在保护模式中创建指向此地址的指针,请使用

To create a pointer to this address in protected mode, you'd use

char *p = (char *)0xb8000;

但是,您很可能处于实模式中,因此您需要构造一个远指针:

However, you are most likely in real mode, so you need to construct a far pointer:

char far *p = (char far *)0xb8000000;

32位值分为两个16位值,分别分配给段和偏移.

The 32 bit value is split in two 16 bit values, which are assigned to segment and offset.

您可以正常使用此指针,然后:

You can use this pointer normally, then:

*p = '!';

这篇关于在C语言中,我该如何写入特定的存储位置,例如DOS中的视频内存b800(实际DOS,MS DOS 6.22)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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