#define hibyte(a) (((a) >> 8) & 0xFF) #define lobyte(a) ((a) & 0xFF) #ifdef __DEBUG #include #endif //__DEBUG typedef /*unsigned*/ char byte; //1-byte typedef /*unsigned*/ short word; //2-bytes typedef /*unsigned*/ long dword; //4-bytes struct Regs16 { word ax; byte ah; byte al; word bx; byte bh; byte bl; word cx; byte ch; byte cl; word dx; byte dh; byte dl; word si; word di; word bp; word sp; word cs; word ds; word es; word fs; word gs; word ss; word ip; word flags; } regs16; // Move functions: Intel style void mov(word &dst, word src) { dst = src; } void mov(byte &dst, byte src) { dst = src; } //unsigned void movzx(word &dst, byte src) { //mov but pad hi-byte with 0x00... } //signed void movsx(word &dst, byte src) { //mov but pad with signededness 0xff? } void movsb() { //Implement movsb //move value at esi to edi } void xchg(word &dst, word &src) { word tmp = dst; dst = src; src = tmp; } void xchg(byte &dst, byte &src) { byte tmp = dst; dst = src; src = dst; } void lea(word &dst, word src) { //Implement lea } /////////////////////////////////////////////// // Math void add(word &dst, word src) { dst += src; } void add(byte &dst, byte src) { dst += src; } void sub(word &dst, word src) { dst -= src; } void sub(byte &dst, byte src) { dst -= src; } void mul(byte src) { //ax = al*src; } void mul(word src) { //dx:ax = ax*src } //print hex to be template, set width to sizeof(T)*2 int main() { regs16.ax = 0x0141; regs16.ah = hibyte(regs16.ax); regs16.al = lobyte(regs16.ax); #ifdef __DEBUG std::cout << "AX = " << std::hex << regs16.ax << std::endl; std::cout << "AH = " << std::hex << (int)regs16.ah << std::endl; std::cout << "AL = " << std::hex << (int)regs16.al << std::endl; #endif //__DEBUG return 0; }