📄 asm_segment_h.h
字号:
//---------------------------------------------------------------------------
//-------- ASM_Segment_H.h --------------------------------------------------
//---------------------------------------------------------------------------
#ifndef ASM_Segment_H.h // 防止被重复引用
#define ASM_Segment_H.h
//---------------------------------------------------------------------------
#include "Jstring_H.h"
#include "AsmL_H.h"
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// 段中的小片段。
// 说明:如果片段为空,则开始汇编行与结尾汇编行相同。
//---------------------------------------------------------------------------
class SegTriple : public JObject
{ public:
AsmLine* begin; // 指向本片段的开始汇编行。
AsmLine* end; // 指向本片段的结尾汇编行。
SegTriple* next; // 指向本段中的下一个小片段。
// ------ public functions -------
SegTriple(AsmLine* be):next(NULL) { end = begin = be; } // constructor
bool IsNullTrp()const { return (begin == end); } // end IsNullTrp
bool IsNotNullTrp()const { return (begin != end); } // end IsNotNullTrp
// ------- debug functions -------
void show()const;
}; // end SegTriple
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//
// 汇编段
//
//---------------------------------------------------------------------------
class ASM_Segment : public JObject
{ private:
SegTriple* SegTrp; // 指向该段的SegTriple三元结构体链头
SegTriple* TrpTail; // 指向该段的SegTriple三元结构体链尾
int8u RelType; // 再定位类型(0~5)UNIT...
union
{ int8u SegInfoByte; // 段信息 (1,0,0,00,000)
struct
{ int8u SegType :3; // 段类型(0~4) SEG_CODE..... (000)
int8u SREGused :2; // (#0~#3)可覆盖的段能用的寄存器组(00)
int8u OverAble :1; // 此段可覆盖? (false)
int8u :1; // 未用 (0)
int8u SegEmpty :1; // 段空? (true)
}; // end struct
}; // end union
public:
ASM_Segment* next; // 指向链表中的下一段。
Jstring Name; // 段名, 绝对段没有段名。
int16u SegID; // 段ID
int16u SegBase; // 段基址
int16u SegSize; // 段大小
int16u SegLc; // 段地址计数器
// -------- constructors ---------
ASM_Segment(); // constructor 1
ASM_Segment(int8u segtyp); // constructor 2
~ASM_Segment(); // destructor
// ------ public functions -------
bool IsEmpty()const { return SegEmpty; } // 段空?
bool IsOverAble()const { return OverAble; } // 此段可覆盖?
int8u SegInfo()const { return SegInfoByte; } // 段信息包
int8u GetSegType()const { return SegType; } // 得到段类型
int8u GetRelType()const { return RelType ? 'R':'A'; } // 要求SEG_ABS==0
// 初始化片段链头和链尾。
void InitSegTrpHead(AsmLine* line)
{ TrpTail = SegTrp = new SegTriple(line); } // end InitSegTrpHead
// 关闭当前片段。
void CloseCurrentSegTrp(AsmLine* end)
{ TrpTail->end = end; } // end CloseCurrentSegTrp
// 关闭当前片段, 并添加新片段。
void CloseAndAddSegTrp(AsmLine* be)
{ CloseCurrentSegTrp(be); AddSegTrp(be); } // end CloseAndAddSegTrp
// 添加新片段。
void AddSegTrp(AsmLine* be);
// 更新段大小。
void UpdateSegSize();
// ------- debug functions ---------
void show()const;
// ---------------------------------
friend class OBJmodule;
}; // end ASM_Segment
//---------------------------------------------------------------------------
//------ 构造器1 ------------------------------------------------------------
inline ASM_Segment::ASM_Segment()
:SegID(0x0000),
SegBase(0x0000),
SegSize(0x0000),
SegLc(0x0000),
SegInfoByte(0x80),
RelType(SEG_ABS),
next(NULL)
{ TrpTail = SegTrp = NULL; } // end constructor
//---------------------------------------------------------------------------
//------ 构造器2 ------------------------------------------------------------
inline ASM_Segment::ASM_Segment(int8u segtyp)
:SegID(0x0000),
SegBase(0x0000),
SegSize(0x0000),
SegLc(0x0000),
SegInfoByte(0x80),
RelType(SEG_ABS),
next(NULL)
{ TrpTail = SegTrp = NULL; SegType = segtyp; } // end constructor
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// 通过当时的SegLc值更新段大小。
//---------------------------------------------------------------------------
inline void ASM_Segment::UpdateSegSize()
{ if(SegSize < SegLc - SegBase)
{ SegSize = SegLc - SegBase; } // 保存上一段的最大地址
if(SegSize != 0)
{ SegEmpty = false; } // endif
} // end SegInfoByteUpdateSegSize
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// 在尾部插入新块
//---------------------------------------------------------------------------
inline void ASM_Segment::AddSegTrp(AsmLine* be)
{ if(TrpTail == NULL)
{ InitSegTrpHead(be); } // endif
else
{ TrpTail->next = new SegTriple(be);
TrpTail = TrpTail->next;
} // end else
} // end AddSegTrp
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
// Written by JamesyFront. ZLGmcu Dev.Co.Ltd. 2002.
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -