标题中的错误发生在此标题文件中每个类似函数的宏的“#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
答案 0 :(得分:11)
预处理指令(如#define
)由换行符终止,因此它只能是一行。如果需要多行宏定义,则需要转义换行符:
// v Make this the last character on the line
#define NOT() \
( NOT_OP << 28 )
答案 1 :(得分:6)
宏应该写在1行而不是2行。
这是错误的:
#define NOT()
( NOT_OP << 28 )
这是对的:
#define NOT() ( NOT_OP << 28 )
如果你真的想在多行上写它,请使用反斜杠来“转义”新行。像这样:
#define NOT() \
( NOT_OP << 28 )
答案 2 :(得分:2)
嗯...我想你不是把#define
的替换放在另一行,对吗?
#define JMP(address)
( (JMP_OP << 28) | (address) )
应该是
#define JMP(address) ( (JMP_OP << 28) | (address) )
例如,。 #define
声明必须只在一行中,或者在行尾使用\
扩展到下一行。