微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在C中实现Y86提取指令

如何解决在C中实现Y86提取指令

很抱歉,这个问题很长,但是我真的迷失了这个任务。本质上要求我实现fetchInstruction。我猜另外两个是我应该使用的辅助函数。我在下面附加了fetchInstruction.c代码和struction.h代码。我不希望得到直接的答案和完整的代码,但是有人可以指出我如何开始的正确方向吗?对于那些想知道的人,programMap指的是内存本身,而location是指令的位置。

/* Reads one byte from memory,at the specified address. Stores the
     read value into *value. Returns 1 in case of success,or 0 in case
     of failure (e.g.,if the address is beyond the limit of the memory
     size). */
int memReadByte(machine_state_t *state,uint64_t address,uint8_t *value)
{
    if (address > machine_state->programSize)
       return 0;
    *value = machine_state->programMap[address];
    return 1;
}

/* Reads one quad-word (64-bit number) from memory in little-endian
     format,at the specified starting address. Stores the read value
     into *value. Returns 1 in case of success,or 0 in case of failure
     (e.g.,if the address is beyond the limit of the memory size). */
int memReadQuadLE(machine_state_t *state,uint64_t *value)
{

    return 0;
}

/* Fetches one instruction from memory,at the address specified by
     the program counter. Does not modify the machine's state. The
     resulting instruction is stored in *instr. Returns 1 if the
     instruction is a valid non-halt instruction,or 0 (zero)
     otherwise. */
int fetchInstruction(machine_state_t *state,y86_instruction_t *instr)
{

    return 0;
}
typedef enum y86_icode {
  I_HALT      = 0x0,I_nop       = 0x1,I_RRMVXX    = 0x2,I_IRMOVQ    = 0x3,I_RMMOVQ    = 0x4,I_MRMOVQ    = 0x5,I_OPQ       = 0x6,I_JXX       = 0x7,I_CALL      = 0x8,I_RET       = 0x9,I_PUSHQ     = 0xA,I_POPQ      = 0xB,I_INVALID   = 0xE,I_TOO_SHORT = 0xF
} y86_icode_t;

typedef enum y86_reg {
  R_RAX = 0x0,R_RCX = 0x1,R_RDX = 0x2,R_RBX = 0x3,R_RSP = 0x4,R_RBP = 0x5,R_RSI = 0x6,R_RDI = 0x7,R_R8  = 0x8,R_R9  = 0x9,R_R10 = 0xA,R_R11 = 0xB,R_R12 = 0xC,R_R13 = 0xD,R_R14 = 0xE,R_NONE = 0xF
} y86_register_t;

typedef enum y86_condition {
  C_NC = 0x0,C_LE = 0x1,C_L  = 0x2,C_E  = 0x3,C_NE = 0x4,C_GE = 0x5,C_G  = 0x6
} y86_condition_t;

typedef enum y86_operation {
  A_ADDQ = 0x0,A_SUBQ = 0x1,A_ANDQ = 0x2,A_XORQ = 0x3,A_MULQ = 0x4,A_DIVQ = 0x5,A_MODQ = 0x6
} y86_operation_t;

typedef struct instruction {

  y86_icode_t    icode;
  uint8_t        ifun;
  y86_register_t rA;
  y86_register_t rB;
  uint64_t       valC;
  
  uint64_t       location;
  uint64_t       valP;
} y86_instruction_t;

#define CC_ZERO_MASK     0x1
#define CC_SIGN_MASK     0x2
#define CC_CARRY_MASK    0x4
#define CC_OVERFLOW_MASK 0x8

typedef struct machine_state {
  
  uint8_t *programMap;
  uint64_t programSize;
  
  uint64_t programCounter;

  uint64_t registerFile[16];

  uint8_t conditionCodes;
  
} machine_state_t;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?