I have to do a homework: make a CPU simulator using C language.
I have a set of asm instructions so I have to write a program
that should:
- load .asm file
- view .asm file
- do a step by step simulation
- display registers contents
I tried to search con google with no success.
Any help (links, tricks/tips...)
would be really appreciated.
Thanks in advance.
I googled eax ebx ecx edx ax bx in com.lang.c
-->
_______________________
I have repeatedly come across declarations of
the type 'struct REGS' (i think that was what was called,
have seen a few variations) and was wondering if
someone could tell me it's contents, and what it is used for.
I only have a very basic shareware compiler (for my PC anyway,
and I have never seen it under Unix) and it has no mention of this
structure.
Could someone enlighten me ?
This is not a Unix item but strictly a PC item as follows:
union REGS {
struct WORDREGS x;
struct BYTEREGS h;
};
struct WORDREGS {
unsigned int ax, bx, cx, dx;
unsigned int si, di, cflag, flags;
};
struct BYTEREGS {
unsigned char al, ah, bl, bh;
unsigned char cl, ch, dl, dh;
};
These structures allow C programs on PCs to access the CPU registers.
AX,BX,CX,DX,SI,DI,CF(carry flag),and FLAGS are all Intel 80x86
registers
AL/AH,BL/BH,CL/CH,DL/DH are pseudo 8 bit registers which are derived
from the
AL = Low half of AX, AH = High half of AX, etc.
The basic registers are 16 bits while the extended registers are 32
bits
EAX,EBX,ECX,EDX, etc.
In addition you have the segment registers CS,DS,ES,SS and the
pointers
SP,BP plus the index registers SI,DI and on the 80386 and above you
also
have debug registers.
In protected mode the segment registers become selector registers.
The segments are as follows:
CS code segment
DS data segment
ES extra segment
SS stack segment
The pointers are:
SP stack pointer
BP base pointer
--
Scott Hopson (
[email protected])
____________________________________________
Hi,
I am not really familiar with interrupt calls, especially when done in
a 32 Bit OS enviroment.
I using the WatCom C Compiler Ver. 11b building 32 Bit Dos
applications.
I am trying to call interrupt 2FH, function 0DH for detecting the
driveletters of all connected cdroms.
I programmed this under 16bit dos and it works well, but I am not sure
how to adapt it for 32 Bit.
I have enclosed the code for 16 Bit. I would be pleased if anyone can
give advice.
Thanks a lot in advance.
Philipp
{
union REGS regs;
struct SREGS sregs;
char driveLetters [27];
regs.x.ax = 0x150D;
sregs.es = FP_SEG (driveLetters);
regs.x.bx = FP_OFF (driveLetters);
int86x (0x2F, ®s, ®s, &sregs);
}
**********************
* Auszug aus <i86.h> *
**********************
struct DWORDREGS {
unsigned int eax;
unsigned int ebx;
unsigned int ecx;
unsigned int edx;
unsigned int esi;
unsigned int edi;
unsigned int cflag;
};
struct WORDREGS {
unsigned short ax; __FILLER(_1)
unsigned short bx; __FILLER(_2)
unsigned short cx; __FILLER(_3)
unsigned short dx; __FILLER(_4)
unsigned short si; __FILLER(_5)
unsigned short di; __FILLER(_6)
#if defined(__WINDOWS_386__)
unsigned short cflag;
#else
unsigned int cflag;
#endif
};
struct BYTEREGS {
unsigned char al, ah; __FILLER(_1)
unsigned char bl, bh; __FILLER(_2)
unsigned char cl, ch; __FILLER(_3)
unsigned char dl, dh; __FILLER(_4)
};
union REGS {
#if defined(__386__) && !defined(__WINDOWS_386__)
struct DWORDREGS x;
#else
struct WORDREGS x;
#endif
struct WORDREGS w;
struct BYTEREGS h;
};
struct SREGS {
unsigned short es, cs, ss, ds;
#if defined(__386__)
unsigned short fs, gs;
#endif
};