📄 lmasmtobi.cpp
字号:
// LmAsmToBi.cpp: implementation of the CLmAsmToBi class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "c02ide.h"
#include "LmAsmToBi.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CLmAsmToBi::CLmAsmToBi()
{
}
CLmAsmToBi::~CLmAsmToBi()
{
}
void CLmAsmToBi::ChangeAsmToBi(CString str_path)
{
if(!fAsm.Open(str_path,CFile::modeRead|CFile::typeText))
return;
CString str_pathbi=_T("");
int n_dunhao=0;
char ch_dunhao='.';
n_dunhao=str_path.ReverseFind(ch_dunhao);
str_pathbi=str_path.Left(n_dunhao);
str_pathbi=str_pathbi+_T("bi.txt");
if(!fBi.Open(str_pathbi,CFile::modeCreate|CFile::typeText))
return;
fBi.Close();
if(!fBi.Open(str_pathbi,CFile::modeWrite|CFile::typeText))
return;
// myFile.Write( szBuffer, sizeof( szBuffer ) );
// myFile.Seek( 0, CFile::begin );
// CCJMDIFrameWnd *pFrame = (CCJMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
// CCJMDIChildWnd *pChild = (CCJMDIChildWnd *) pFrame->GetActiveFrame();
CString str_get=_T("");
//获得当前活动视图
// CCrystalEditView* m_pexpandview=NULL;
// m_pexpandview=(CCrystalEditView*)pChild->GetActiveView();
BOOL m_bend=TRUE;
// CRichEditView *pView = (CRichEditView *)pChild->GetActiveView();
// CRichEditCtrl& m_pctrl=pView->GetRichEditCtrl();
int i_ins;
i_ins=0;
strar_key.RemoveAll();
strAllKeyWord = _T(" LOOP,LD,LW,LB,SD,SW,SB,ADD,ADDD,SUB,SUBD,MULT,MULTD,DIV,DIVD,J,BEQZ,BENZ,");
//nnnnnnnnnnnnnnnnnnnnnnnnn 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
CString strTemp;
int nPosPrior = 0;
int nPos;
nPos = strAllKeyWord.Find(_T(","), nPosPrior);
while(nPos!=-1)
{
strTemp = strAllKeyWord.Mid(nPosPrior+1 , nPos - nPosPrior - 1);
strar_key.Add(strTemp);
nPosPrior = nPos;
nPos = strAllKeyWord.Find(_T(","), nPosPrior + 1);
}
strar_bi.RemoveAll();
strAllBi = _T(" 000000,000001,000010,000011,");
strTemp=_T("");
nPosPrior = 0;
nPos=0;
nPos = strAllBi.Find(_T(","), nPosPrior);
while(nPos!=-1)
{
strTemp = strAllBi.Mid(nPosPrior+1 , nPos - nPosPrior - 1);
strar_bi.Add(strTemp);
nPosPrior = nPos;
nPos = strAllBi.Find(_T(","), nPosPrior + 1);
}
strar_grbi.RemoveAll();
strAllGrBi = _T(" 00000,00001,00010,00011,00100,00101,00110,00111,01000,");
strTemp=_T("");
nPosPrior = 0;
nPos=0;
nPos = strAllGrBi.Find(_T(","), nPosPrior);
while(nPos!=-1)
{
strTemp = strAllGrBi.Mid(nPosPrior+1 , nPos - nPosPrior - 1);
strar_grbi.Add(strTemp);
nPosPrior = nPos;
nPos = strAllGrBi.Find(_T(","), nPosPrior + 1);
}
// CString test=strar_grbi.GetAt(0);
CString str_ins;
do{
m_bend=fAsm.ReadString(str_get);
ChangeOneLine(str_get);
}while(m_bend!=NULL);
fAsm.Close();
fBi.Close();
}
void CLmAsmToBi::ChangeOneLine(CString str_get)
{
str_get.TrimLeft();
str_get.TrimRight();
CString str_ins,str_cutins;
str_ins=_T("");
str_cutins=_T("");
int n_asmkey;
n_asmkey=strar_key.GetSize();
CString str_selectkey=_T("");
CString str_write=_T("");
for(int n_iskey=0;n_iskey<n_asmkey;n_iskey++)
{
str_selectkey=(CString)strar_key.GetAt(n_iskey);
int n_selectkey=0;
int n_cutkey=0;
n_selectkey=str_selectkey.GetLength();
n_cutkey=str_get.GetLength()-n_selectkey;
str_ins=str_get.Left(n_selectkey);
str_cutins=str_get.Right(n_cutkey);
str_cutins.TrimLeft();
if(str_ins==str_selectkey)
{
str_write=strar_bi.GetAt(n_iskey);
int n_douhao=0;
int n_douhao2=0;
int n_reg=0;
int n_zuokuohao=0;
int n_youkuohao=0;
int n_lijizhi=0;
CString str_reg=_T("");
CString str_regto=_T("");
CString str_regso=_T("");
CString str_lijizhi=_T("");
if(n_iskey>=1&&n_iskey<=3)//LD F0,50(R2)
{
n_douhao=str_cutins.Find(',');
str_reg=str_cutins.Left(n_douhao);
n_reg=GetGrNo(str_reg);
if(n_reg==33)
AmsErr(1);
str_reg=strar_grbi.GetAt(n_reg);
str_regto=str_reg;
// str_write=str_write+strar_grbi.GetAt(n_reg);
// int n_aftercutlen=0;
// n_aftercutlen=str_cutins.GetLength();
n_zuokuohao=str_cutins.Find('(');
n_youkuohao=str_cutins.Find(')');
n_zuokuohao++;
str_reg=str_cutins.Mid(n_zuokuohao,n_youkuohao-n_zuokuohao);
n_reg=GetGrNo(str_reg);
if(n_reg==33)
AmsErr(1);
str_reg=strar_grbi.GetAt(n_reg);
str_write=str_write+str_reg+str_regto;
str_lijizhi=str_cutins.Mid(n_douhao+1,n_zuokuohao-1);
n_lijizhi=atoi(str_lijizhi);
//algorism to binary system
str_lijizhi=AlgToBi(n_lijizhi);
str_write=str_write+str_lijizhi;
str_write=str_write+"\r\n";
fBi.WriteString(str_write);
}
if(n_iskey>=4&&n_iskey<=6)//SD 10(R3),F0
{
n_zuokuohao=str_cutins.Find('(');
str_lijizhi=str_cutins.Left(n_douhao);
str_lijizhi.TrimLeft();
str_lijizhi.TrimRight();
n_lijizhi=atoi(str_lijizhi);
//algorism to binary system
str_lijizhi=AlgToBi(n_lijizhi);
n_zuokuohao=str_cutins.Find('(');
n_youkuohao=str_cutins.Find(')');
n_zuokuohao++;
str_reg=str_cutins.Mid(n_zuokuohao,n_youkuohao-n_zuokuohao);
n_reg=GetGrNo(str_reg);
if(n_reg==33)
AmsErr(1);
str_reg=strar_grbi.GetAt(n_reg);
//写入源寄存器
str_write=str_write+str_reg;
n_douhao=str_cutins.Find(',');
str_reg=str_cutins.Mid(n_douhao+1);
n_reg=GetGrNo(str_reg);
if(n_reg==33)
AmsErr(1);
str_reg=strar_grbi.GetAt(n_reg);
str_write=str_write+str_reg;
str_write=str_write+str_lijizhi;
str_write=str_write+"\r\n";
fBi.WriteString(str_write);
}
if(n_iskey>=7&&n_iskey<=14)//ADDD R1,R2,R3
{
n_douhao=str_cutins.Find(',');
str_reg=str_cutins.Left(n_douhao);
n_reg=GetGrNo(str_reg);
if(n_reg==33)
AmsErr(1);
str_reg=strar_grbi.GetAt(n_reg);
str_regto=str_reg;
n_douhao2=str_cutins.ReverseFind(',');
str_reg=str_cutins.Mid(n_douhao+1,n_douhao2-n_douhao-1);
n_reg=GetGrNo(str_reg);
if(n_reg==33)
AmsErr(1);
str_reg=strar_grbi.GetAt(n_reg);
str_write=str_write+str_reg;
str_reg=str_cutins.Mid(n_douhao2+1);
n_reg=GetGrNo(str_reg);
if(n_reg==33)
AmsErr(1);
str_reg=strar_grbi.GetAt(n_reg);
str_write=str_write+str_reg;
str_write=str_write+str_regto;
str_write=str_write+_T("00000000000");
str_write=str_write+"\r\n";
fBi.WriteString(str_write);
}
}
// Ins_stack[i_ins]=n_iskey;
}
}
int CLmAsmToBi::GetGrNo(CString str_grreg)
{
if(str_grreg=="R0"||str_grreg=="F0") return 0;
if(str_grreg=="R1"||str_grreg=="F1") return 1;
if(str_grreg=="R2"||str_grreg=="F2") return 2;
if(str_grreg=="R3"||str_grreg=="F3") return 3;
if(str_grreg=="R4"||str_grreg=="F4") return 4;
if(str_grreg=="R5"||str_grreg=="F5") return 5;
if(str_grreg=="R6"||str_grreg=="F6") return 6;
if(str_grreg=="R7"||str_grreg=="F7") return 7;
if(str_grreg=="R8"||str_grreg=="F8") return 8;
if(str_grreg=="R9"||str_grreg=="F9") return 9;
if(str_grreg=="R10"||str_grreg=="F10") return 10;
if(str_grreg=="R11"||str_grreg=="F11") return 11;
else return 33;
}
void CLmAsmToBi::AmsErr(int i_err)
{
}
CString CLmAsmToBi::AlgToBi(int i_alg)
{
int i_bitnum=0;
int i_left=0;
CString str_result=_T("");
do{
// i_left=i_alg/2;
if(i_alg%2==0)
str_result=_T("0")+str_result;
else
str_result=_T("1")+str_result;
i_alg=i_alg/2;
i_bitnum++;
}while(i_alg!=0);
for(int j=0;j<16-i_bitnum;j++)
str_result=_T("0")+str_result;
return str_result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -