|
蓝森林 http://www.lslnet.com 2006年6月6日 10:18
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
gcc 中 怎么得到 一个变量的 段地址和偏移地址??
tc中 FP_SEG 类似的?? 有么 请高手指点
djgpp 中怎么搞 主要目的是使用int86x()
----------------------------------------------------------
下面的程序在xp下 编译成功 但是运行程序出错 为啥?
--------------------------------------------------------
#include<stdio.h>;
#include<dos.h>;
#define FP_OFF(fp) ((unsigned)(fp))
#define FP_SEG(fp) ((unsigned)((unsigned long)(fp) >;>; 16))
typedef unsigned int WORD;
typedef unsigned long DWORD;
typedef unsigned long long QWORD;
unsigned long CYLINDERS,HEADS,SECTOR_PER_TRACK;
unsigned long long SECTORS;
unsigned int BYTE_PER_SECTOR;
int get_parameter(int drive)
{
union REGS regs;
struct SREGS sregs;
struct{
WORD packetsize;
WORD infoflags;
DWORD cylns;
DWORD heads;
DWORD sects_per_track;
QWORD sectors;
WORD bps;
}package;
regs.h.ah=0x48;
regs.h.dl=0x80;
sregs.ds=FP_SEG(&package);
regs.x.si=FP_OFF(&package);
int86x(0x13,®s,®s,&sregs);
CYLINDERS=package.cylns;
HEADS=package.heads;
SECTOR_PER_TRACK=package.sects_per_track;
SECTORS=package.sectors;
BYTE_PER_SECTOR=package.bps;
if (regs.h.ah)
return regs.h.ah;
else
return 0;
}
int main()
{
if (get_parameter(0x80)==0)
{
printf("%ldCYLINDERS:\n",CYLINDERS);
printf("%ldHEADS:\n",HEADS);
printf("%ldSECTOR_PER_TRACK:\n",SECTOR_PER_TRACK);
printf("%lldSECTORS:\n",SECTORS);
printf("%dBYTE_PER_SECTOR:\n",BYTE_PER_SECTOR);
}
return 0;
} |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
嘿嘿,你的概念早过时了 |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
这个代码我没有看,但是你要得到 段地址和偏移地址 是和cpu有关的,有的cpu没有分段机制,有的cpu可以选择是否分段,所以,没有任何检测代码的代码不是健壮的代码。
另外,XP对物理设备的访问有保护,除非你写驱动,否则肯定出错。 |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
段地址和偏移可以有很多种答案的
这个你翻翻那些老书就知道了 |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
嵌入汇编取段地址寄存器ds,偏移应该就是&name,但我不知道保护模式下可不可以这样做. |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
我 当然是在x86上写的,各位没看到 下面两个宏是tc2 dos。h中定义的
用来取得段地址和偏移地址
#define FP_OFF(fp) ((unsigned)(fp))
#define FP_SEG(fp) ((unsigned)((unsigned long)(fp) >;>; 16))
可在djgpp中使用 好像有些问题,到底是什么问题呢〉? |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
求各位高手帮忙调试一下程序 谢谢阿 |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
既然用的是djgpp,那就按照他的规则来.不要把TC的那一套套在DJGPP的头上.
[code]
看一下下面两个函数.
#include <bios.h>;
int biosdisk(int cmd, int drive, int head, int track,
int sector, int nsects, void *buffer)
char buffer[512];
if (biosdisk(2, 0x80, 0, 0, 0, 1, buffer))
error("disk");
#include <bios.h>;
unsigned _bios_disk(unsigned cmd, struct diskinfo_t *di)
char record_buffer[512];
struct diskinfo_t di;
di.drive = 0x80;
di.head = 0;
di.track = 0;
di.sector = 1;
di.nsectors = 1;
di.buffer = &record_buffer;
if ( _bios_disk(_DISK_READ, &di) )
puts("Disk error.");
[/code]
只需要上面两个函数应当就可以解决你的问题了.
另外,要注意的是,在2000-XP上面,你应当使用2.03版以上的.否则会出很多问题. |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
楼上的兄弟误会了
我是要调用bios int 13 的 48h功能取得磁盘驱动器的相关参数
biosdisk()怎么能达到我的目的呢? |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
[code]
#include <bios.h>;
int biosdisk(int cmd, int drive, int head, int track,
int sector, int nsects, void *buffer);
Description
This function interfaces with the BIOS disk sevice (interrupt 0x13). Please refer to a BIOS reference manual for detailed information about the parameters of this call. All known calls are supported. A sector size of 512 bytes is assumed.
0 - reset disk subsystem
1 - get disk subsystem status
2 - read one or more sectors
3 - write one or more sectors
5 - format a track
6 - format back track
7 - format drive
8 - get drive parameters
9 - initialize drive parameters
10 - read long sectors
11 - write long sectors
12 - seek to cylinder
13 - alternate fixed disk reset
14 - read test buffer
15 - write test buffer
16 - test for drive ready
17 - recalibrate drive
18 - controller RAM diagnostic
19 - controller drive diagnostic
20 - controller internal diagnostic
15 - read fixed disk type
22 - read disk change line status
23 - set DASD type (pass dasd in nsects)
24 - set media type for format
The first request with more sectors than will fit in the transfer buffer will cause a DOS buffer to be allocated. This buffer is automatically freed when your application exits. Since this buffer is big enough to hold 18 sectors, requests for more sectors than that will fail.
Request eight returns values in buffer as follows:
byte 0 = sectors per track (bits 0..5) and top two bits of cylinder (in bits 6..7)
byte 1 = cyliders (bits 0..7)
byte 2 = number of drives
byte 3 = number of heads
Return Value
The value of AH returned by the BIOS
[/code]
The 8th got the driver parameter. |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
-->
renstone921 你干什么的啊
知道你心好
但这样什么都不分原则的顶 :em17:
会害了他们的 :em06:
(本来学校就已经毒害他们那么深了(._.!) |
[高级]gcc 中 怎么得到 一个变量的 段地址和偏移地址??
谢谢楼上的兄弟:) |
| |