“错误:预期的标识符或“(”在数字常量之前”“?

发布于 2024-10-02 17:56:32 字数 2292 浏览 3 评论 0原文

标题中的错误出现在该头文件中每个类似函数的宏的“#define”行上(从第 45 行开始)。我做错了什么吗?

#ifndef ASSEMBLER_H
#define ASSEMBLER_H


/* Ports */
#define   Input    0
#define   Output   15

/* Registers */
#define   Z    0
#define   A    1
#define   B    2
#define   C    3
#define   D    4
#define   E    5
#define   F    6
#define   G    7

/* OP Codes */
    /*-----Control--------*/
#define   HLT_OP    0
#define   JMP_OP    1
#define   CJMP_OP   2
#define   OJMP_OP   3
    /*-----Load/Store-----*/
#define   LOAD_OP   4
#define   STORE_OP  5
#define   LOADI_OP  6
#define   NOP_OP    7
    /*-----Math-----------*/
#define   ADD_OP    8
#define   SUB_OP    9
    /*-----Device I/O-----*/
#define   IN_OP     10
#define   OUT_OP    11
    /*-----Comparison-----*/
#define   EQU_OP    12
#define   LT_OP     13
#define   LTE_OP    14
#define   NOT_OP    15

/* Macros */
    /*-----Control--------*/
#define HLT()
  ( HLT_OP << 28 )
#define JMP(address)
  ( (JMP_OP << 28) | (address) )
#define CJMP(address)
  ( (CJMP_OP << 28) | (address) )
#define OJMP(address)
  ( (OJMP_OP << 28) | (address) )
    /*-----Load/Store-----*/
#define LOAD(dest, value)
  ( (LOAD_OP << 28) | ((dest) << 24) | (value) )
#define STORE(dest, value)
  ( (STORE_OP << 28) | ((dest) << 24) | (value) )
#define LOADI(dest, value)
  ( (LOADI_OP << 28) | ((dest) << 24) | (value) )
#define NOP()
  ( NOP_OP << 28 )
    /*-----Math-----------*/
#define ADD(dest, op1, op2)
  ( (ADD_OP << 28) | ((dest) << 24) | ((op1) << 20) | ((op2) << 16) )
#define SUB(dest, op1, op2)
  ( (SUB_OP << 28) | ((dest) << 24) | ((op1) << 20) | ((op2) << 16) )
    /*-----Device I/O-----*/
#define IN(reg)
  ( (IN_OP << 28) | ((reg) << 24) | (Input) )
#define OUT(reg)
  ( (OUT_OP << 28) | ((reg) << 24) | (Output) )
    /*-----Comparison-----*/
#define EQU(reg1, reg2)
  ( (EQU_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
#    define LT(reg1, reg2)
  ( (LT_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
#define LTE(reg1, reg2)
  ( (LTE_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
#define NOT()
  ( NOT_OP << 28 )



#endif

The error in the title occurs on the '#define' line for every single function-like macro in this header file (starting at line 45). Am I doing something wrong?

#ifndef ASSEMBLER_H
#define ASSEMBLER_H


/* Ports */
#define   Input    0
#define   Output   15

/* Registers */
#define   Z    0
#define   A    1
#define   B    2
#define   C    3
#define   D    4
#define   E    5
#define   F    6
#define   G    7

/* OP Codes */
    /*-----Control--------*/
#define   HLT_OP    0
#define   JMP_OP    1
#define   CJMP_OP   2
#define   OJMP_OP   3
    /*-----Load/Store-----*/
#define   LOAD_OP   4
#define   STORE_OP  5
#define   LOADI_OP  6
#define   NOP_OP    7
    /*-----Math-----------*/
#define   ADD_OP    8
#define   SUB_OP    9
    /*-----Device I/O-----*/
#define   IN_OP     10
#define   OUT_OP    11
    /*-----Comparison-----*/
#define   EQU_OP    12
#define   LT_OP     13
#define   LTE_OP    14
#define   NOT_OP    15

/* Macros */
    /*-----Control--------*/
#define HLT()
  ( HLT_OP << 28 )
#define JMP(address)
  ( (JMP_OP << 28) | (address) )
#define CJMP(address)
  ( (CJMP_OP << 28) | (address) )
#define OJMP(address)
  ( (OJMP_OP << 28) | (address) )
    /*-----Load/Store-----*/
#define LOAD(dest, value)
  ( (LOAD_OP << 28) | ((dest) << 24) | (value) )
#define STORE(dest, value)
  ( (STORE_OP << 28) | ((dest) << 24) | (value) )
#define LOADI(dest, value)
  ( (LOADI_OP << 28) | ((dest) << 24) | (value) )
#define NOP()
  ( NOP_OP << 28 )
    /*-----Math-----------*/
#define ADD(dest, op1, op2)
  ( (ADD_OP << 28) | ((dest) << 24) | ((op1) << 20) | ((op2) << 16) )
#define SUB(dest, op1, op2)
  ( (SUB_OP << 28) | ((dest) << 24) | ((op1) << 20) | ((op2) << 16) )
    /*-----Device I/O-----*/
#define IN(reg)
  ( (IN_OP << 28) | ((reg) << 24) | (Input) )
#define OUT(reg)
  ( (OUT_OP << 28) | ((reg) << 24) | (Output) )
    /*-----Comparison-----*/
#define EQU(reg1, reg2)
  ( (EQU_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
#    define LT(reg1, reg2)
  ( (LT_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
#define LTE(reg1, reg2)
  ( (LTE_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
#define NOT()
  ( NOT_OP << 28 )



#endif

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里°也失望 2024-10-09 17:56:32

预处理指令(如#define)以换行符终止,因此它只能是一行长。如果你想要多行宏定义,你需要转义换行符:

//                  v Make this the last character on the line
#define NOT()       \
  ( NOT_OP << 28 ) 

A preprocessing directive (like #define) is terminated by a newline, so it can only be one line long. If you want a multi-line macro definition, you need to escape the newline:

//                  v Make this the last character on the line
#define NOT()       \
  ( NOT_OP << 28 ) 
分開簡單 2024-10-09 17:56:32

宏应该写在 1 行,而不是 2 行。

这是错误的:

#define NOT()
  ( NOT_OP << 28 )

这是正确的:

#define NOT() ( NOT_OP << 28 )

如果您确实想将其写在多行上,请使用反斜杠来“转义”新行。像这样:

#define NOT() \
  ( NOT_OP << 28 )

Macro's should be written on 1 line, not 2.

This is wrong:

#define NOT()
  ( NOT_OP << 28 )

This is right:

#define NOT() ( NOT_OP << 28 )

If you really want to write it on multiple lines, use a backslash to 'escape' the new line. like this:

#define NOT() \
  ( NOT_OP << 28 )
没有伤那来痛 2024-10-09 17:56:32

嗯...我想您没有将 #define 的替换放在不同的行中,对吗?

#define JMP(address)
( (JMP_OP << 28) | (address) )

应该

#define JMP(address) ( (JMP_OP << 28) | (address) )

例如, 改为。 #define 声明必须仅在一行中,或者在一行末尾使用 \ 扩展至下一行。

Hmmm... I guess you're not putting the subsitution for the #define in a different line, right?

#define JMP(address)
( (JMP_OP << 28) | (address) )

should be

#define JMP(address) ( (JMP_OP << 28) | (address) )

instead, for example. #define declarations have to be in just one line, or use \ at the end of a line to expand to the next.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文