1. 记账信息结构联合

typedef struct {
    unsigned int areaNum;
    unsigned int transNum;
    unsigned int station;
} phoneNumber;

struct {
    phoneNumber fromPhone;
    phoneNumber toPhone;
    phoneNumber payPhone;
} dialHistory;

2. 指令解码:

#include <stdio.h>

typedef struct {
    unsigned int dsg_reg : 3;
    unsigned int dst_mode: 2;
    unsigned int opcode  : 11;
} sgl;

typedef struct {
    unsigned int dst_reg : 3;
    unsigned int dst_mode: 3;
    unsigned int src_reg : 3;
    unsigned int src_mode: 3;
    unsigned int opcode  : 4;
} dbl;

typedef struct {
    unsigned int offset : 8;
    unsigned int opcode : 8;
} bran;

typedef struct {
    unsigned int dst_reg : 3;
    unsigned int dst_mode : 3;
    unsigned int src_reg : 3;
    unsigned int opcode : 7;
} reg;

typedef struct {
    unsigned int opcode : 16;
} mic;

typedef union {
    	unsigned short addr;
        mic misc;
        bran branch;
        sgl sgl_op;
        reg reg_src;
        dbl dbl_op;
} machine_inst ;

int main()
{
    machine_inst x = {16};

    printf("%0x\n", x.sgl_op.dst_mode);
    return 0;
}

  typedef 定义联合类型,就可以使用各种联合内的字段结构,访问了

相关文章:

  • 2021-05-18
  • 2021-11-23
  • 2021-11-10
  • 2022-12-23
  • 2021-07-21
  • 2021-06-06
  • 2021-05-31
  • 2021-07-14
猜你喜欢
  • 2021-06-02
  • 2021-11-17
  • 2021-09-25
  • 2021-09-17
  • 2021-10-06
  • 2021-07-11
  • 2021-07-10
相关资源
相似解决方案