C与指针第十章编程练习

本文介绍了用于计算机程序的机器指令结构,包括单操作数、双操作数、转移和源寄存器指令,以及它们在内存中的表示。展示了C语言中`machine_inst`结构体的定义及其在`main`函数中的使用。
摘要由CSDN通过智能技术生成

struct STeleNum
{
    long lAreaNum; // 区号
    long lSwitchBoard; // 交换台
    long lStationNum; // 站号码
};
struct STeleInfo
{
    char *pchDate; // 日期
    char *pchTime; // 时间
    struct STeleNum UsedNum; // 三个电话号码-使用的那个电话
    struct STeleNum CalledNum; // 三个电话号码-呼叫的那个电话
    struct STeleNum PayNum; // 三个电话号码-付账的那个电话
};

 

struct SInFull // 全额
{
    float fRetail; // 生产厂家建议零售价(manufacturer’s suggested retailprice) float
    float fActual; // 实际售出价格(actual selling price) float
    float fTax; // 营业税(sales tax) float
    float fLicenseFee; // 许可费用(licensing fee) float
};
struct SRent // 租赁
{
    float fRetail; // 生产厂家建议零售价(manufacturer’s suggested retailprice) float
    float fActual; // 实际售出价格(actual selling price) float
    float fDownPayment; // 预付定金(down payment) float
    float fSecurityDep; // 安全抵押(security deposit) float
    float fMonthlyPay; // 月付金额(monthly payment) float
    int iLeaseTerm; // 租赁期限(lease term) int
};
struct SLoan // 贷款
{
    float fRetail; // 生产厂家建议零售价(manufacturer’s suggested retailprice) float
    float fActual; // 实际售出价格(actual selling price) float
    float fTax; // 营业税(sales tax) float
    float fLicenseFee; // 许可费用(licensing fee) float
    float fDownPayment; // 预付定金(doun payment) float
    int iLoanDuration; // 贷款期限(loan duration) int
    float fInterestRate; // 贷款利率(interest rate) float
    float fMonthlyPay; // 月付金额(monthly payment) float
    char chBankName[21]; // 银行名称(name of bank) string(20)
};
struct SCarSale
{
    char chCustomerName[21]; // 顾客名字(customer’s name) string(20)
    char chCustomerAddr[41]; // 顾客地址(customer’s address) string(40)
    char chMode[21]; // 模型(model) string(20)
    int iType; // 三种不同类型的交易:1-全额现金销售、2-贷款销售和3-租赁。
    struct SInFull fullFee;
    struct SRent rentFee;
    struct SLoan loanFee;
};

#include <stdio.h>
#include <stdlib.h>

struct SSingleCmd // 单操作数指令
{
    unsigned short dst_reg;  // 0-2
    unsigned short dst_mode;  // 3-5
    unsigned short opcode;  // 6-15
};

struct SDoubleCmd // 双操作数指令
{
    unsigned short dst_reg;  // 0-2
    unsigned short dst_mode;  // 3-5
    unsigned short src_reg;  // 6-8
    unsigned short src_mode;  // 9-11
    unsigned short opcode;  // 12-15
};
struct STransferCmd // 转移指令
{
    unsigned short offset;  // 0-7
    unsigned short opcode;  // 8-15
};
struct SSourceRegCmd // 源寄存器指令
{
    unsigned short dst_reg;  // 0-2
    unsigned short dst_mode;  // 3-5
    unsigned short src_reg;  // 6-8
    unsigned short opcode;  // 9-15
};
struct SOtherCmd // 其余指令
{
    unsigned short opcode;  // 0-15
};
/*
表达式                  位
x.addr                  0-15
x.misc.opcode           0-15
x.branch.opcode         8-15
x.sgl_op.dst_mode       3-5
x.reg_src.src_reg       6-8
x.dbl__op.opcode        12-15
*/
struct SMachineInst
{
    unsigned short addr; // addr 0-15
    struct SOtherCmd misc; // opcode 0-15
    struct STransferCmd branch; // opcode 8-15
    struct SSingleCmd sgl_op; // dst_mode 3-5
    struct SSourceRegCmd reg_src; // src_reg 6-8
    struct SDoubleCmd dbl__op; // opcode 12-15
};
typedef struct SMachineInst machine_inst;
int main()
{
    machine_inst x;
    system("pause");
    return EXIT_SUCCESS;
}

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值