/*------------------------------------------------------------ HotC51汇编数组定义头文件(HotAsm.h V1.02) 最初建立时间: 2009.2.18 最近修改时间: 2009.2.26 (正在添加之中,最终将彻底替代嵌入汇编) 增 添原 因: 为全面支持裸奔式实时操作系统HotTask51做准备 并替代年代久远的HotIns.h/c(不在HotTask51下使用) 应 用: 可以用COM接口技术对HotC51汇编数组进行封装 实现比嵌入汇编更为灵活和更非典之用,“汇编数组”的 出现,将程序战场蔓延至整个代码和数据区~~~ -------------------------------------------------------------- HotTask51汇编数组调用函数库(正在添加之中,最后形成“水库”) -------------------------------------------------------------- 第一步:编写汇编数组的“汇编代码” 参见HotIns.h/c -------------------------------------------------------------- HotASM (__reset_comlib__)[] = {//应该在C文件中编写 HotASM_PUSH_DPL(), HotASM_PUSH_DPH(), HotASM_RETI(), HotASM_CLR_A(), HotASM_PUSH_ACC(), HotASM_PUSH_ACC(), HotASM_RETI(), }; -------------------------------------------------------------- 第二步:编写普通C函数,注意它的名字与调用关系不大 -------------------------------------------------------------- void Reset() {//此法只是演示如何替代HotIns.h/c IE=0; DPTR = __reset_comlib__ + 5; _icall_(__reset_comlib__); } void Start() {//此法只是演示如何替代HotIns.h/c IE=0; PSW=0; _icall_(__reset_comlib__ + 4); _icall_(__reset_comlib__ + 4); } --------------------------------------------------- 第三步:编写COM接口,填入需要的C函数, 注意它的名称与调用次序关系很大,名称与调用关系不大 最后在HotAsm.h的接口里: interface { void (*HotAsm_Start)(void); void (*HotAsm_Reset)(void); }IHotCom_AsmVtbl_Interface, *pIHotCom_AsmVtbl_Interface;
则在主程序里的函数名是asmLib.function.HotAsm_Reset(); ---------------------------------------------------------------- IHotCom_Asm_Interface asmLib =//真实的COM接口 { (pHotAsmFunction)Start,// (pHotAsmFunction)Reset, };
#include "hottask51.h" void main() { asmLib.function.HotAsm_Start();//二次RETI(HotC51将做专题) asmLib.function.HotAsm_Reset();//软件复位 HotTaskStart();//此时任务永远不可能启动 } 菜农HotPower@126.com 2008.2.26 于西安大雁塔村农会 ---------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------- HotASM51汇编指令集宏指令定义 Rn(x) Rn(0~7) asm_MOV_A,R0(), asm_MOV_A_Rn(5), mov a,r0;mov a,r5; @ iRn(x) iRn(0~1) asm_MOV_A_iR1(), asm_MOVX_iRn_A(0), mov a,@r1;movx @r0,a; ! BIT(x) BIT(0~0x7f, 0x80~0xff) asm_CLR_BIT(0x30),asm_SETB_P0_0(), clr 30h;setb p0.0; & REG(x) REG(0~0x7f, 0x80~0xff) asm_MOV_REG_A(HotASM_B), mov b,a; # DATA(x) DATA(0~0xff, 0~0xffff) asm_MOV_A_DATA(250), mov a,#250; ---------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------- NOP 指令名称:空操作指令 指令功能:不执行任何操作,常用于产生一个机器周期的时间延迟 操作内容:PC←(PC)+l 字 节 数:1 机器周期:1 HotASM例: HotASM (__HotASM_Fuction__)[] = { asm_NOP(), asm_RET() }; --------------------------------------------------------------------------------------------*/ #define asm_NOP() (HotASM_REG)0x00 /*-------------------------------------------------------------------------------------------- AJMP addr11 指令名称:绝对转移指令 指令功能:构造目的地址,实现程序转移。其方法是以指令提供的11位地址,取代PC的低11位,. 而PC的高5位保持不变。 操作内容:PC←(PC)+2 PCl0~0←addrll 字 节 数:2 机器周期:2 HotASM例: HotASM (__HotASM_Fuction__)[] = { asm_AJMP(0x2500), asm_AJMP(0x2500), asm_RET() }; --------------------------------------------------------------------------------------------*/ #define HotASM_Code_AJMP (HotASM_REG)0x01 #define asm_AJMP(addr11) HotASM_AAREG(HotASM_Code_AJMP, addr11) /*-------------------------------------------------------------------------------------------- LJMP addrl6 指令名称:长转移指令 指令功能:使程序按指定地址进行无条件转移 操作内容:PC←addrl6 字 节 数:1 机器周期:1 HotASM例: HotASM (__HotASM_Fuction__)[] = { asm_LJMP(0x2500), asm_RET() }; --------------------------------------------------------------------------------------------*/ #define HotASM_Code_LJMP (HotASM_REG)0x02 #define asm_LJMP(addrl6) HotASM_Code_LJMP, HotASM_LAREG(addrl6) /*-------------------------------------------------------------------------------------------- RR A 指令名称:循环右移指令 指令功能:累加器内容循环右移一位 操作内容:An←(An+1);n=0~6 A7←(A0) 字 节 数:1 机器周期:1 HotASM例: HotASM (__HotASM_Fuction__)[] = { asm_RR_A(), asm_RET() }; --------------------------------------------------------------------------------------------*/ #define asm_RR_A() (HotASM_REG)0x03 /*-------------------------------------------------------------------------------------------- INC A 指令名称:累加器加1指令 指令功能:累加器内容加1 操作内容:A←(A)+1 字 节 数:1 机器周期:1 HotASM例: HotASM (__HotASM_Fuction__)[] = { asm_INC_A(), asm_RET() }; --------------------------------------------------------------------------------------------*/ #define asm_INC_A() (HotASM_REG)0x04 /*-------------------------------------------------------------------------------------------- INC direct 指令名称:直接寻址单元加1指令 指令功能:内部BAM低128单元或专用寄存器内容加1 操作内容:direct←(direct)+1 字 节 数:2 机器周期:1 HotASM例: HotASM (__HotASM_Fuction__)[] = { asm_INC_ACC(), asm_INC_REG(HotASM_B), asm_RET() }; --------------------------------------------------------------------------------------------*/ #define HotASM_Code_INC_REG (HotASM_REG)0x05 #define asm_INC_REG(direct) HotASM_Code_INC_REG, (HotASM_REG)(direct) #define asm_INC_SP() HotASM_Code_INC_REG, HotASM_SP #define asm_INC_PSW() HotASM_Code_INC_REG, HotASM_PSW #define asm_INC_ACC() HotASM_Code_INC_REG, HotASM_ACC #define asm_INC_B() HotASM_Code_INC_REG, HotASM_B #define asm_INC_DPL() HotASM_Code_INC_REG, HotASM_DPL #define asm_INC_DPH() HotASM_Code_INC_REG, HotASM_DPH
/*-------------------------------------------------------------------------------------------- INC @Ri 指令名称:间接寻址单元加1指令 指令功能:内部RAM低128单元内容加1 操作内容:(Ri)←((Ri))+1;i=0,l 字 节 数:1 机器周期:1 HotASM例: HotASM (__HotASM_Fuction__)[] = { asm_INC_iR0(), asm_INC_iRn(HotASM_R0), asm_INC_iRn(HotASM_R1), asm_RET() }; --------------------------------------------------------------------------------------------*/ #define asm_INC_iRn(Ri) (HotASM_REG)(0x06 + Ri % 1) #define asm_INC_iR0() (HotASM_REG)0x06 #define asm_INC_iR1() (HotASM_REG)0x07 /*-------------------------------------------------------------------------------------------- INC Rn 指令名称:寄存器加1指令 指令功能:寄存器内容加1 操作内容:Rn←(Rn)+1,n=0~7 字 节 数:1 机器周期:1 HotASM例: HotASM (__HotASM_Fuction__)[] = { asm_INC_R3(), asm_INC_Rn(HotASM_R0), asm_INC_Rn(HotASM_R1), asm_RET() }; --------------------------------------------------------------------------------------------*/ #define asm_INC_Rn(Rn) (HotASM_REG)(0x08 + Rn % 8) #define asm_INC_R0() (HotASM_REG)0x08 #define asm_INC_R1() (HotASM_REG)0x09 #define asm_INC_R2() (HotASM_REG)0x0a #define asm_INC_R3() (HotASM_REG)0x0b #define asm_INC_R4() (HotASM_REG)0x0c #define asm_INC_R5() (HotASM_REG)0x0d #define asm_INC_R6() (HotASM_REG)0x0e #define asm_INC_R7() (HotASM_REG)0x0f /*-------------------------------------------------------------------------------------------- JBC bit,rel 指令名称:位条件转移清0指令 指令功能:对指定位的状态进行测试。若为1,则把该位清0并进行转移;否则程序顺序执行 操作内容:若(bit)=1,则PC←(PC)+3+rel,bit←0 若(bit)≠1,则PC←(PC)+3 字 节 数:3 机器周期:2 HotASM例: HotASM (__HotASM_Fuction__)[] = { asm_JBC_BIT(HotASM_24H_1, __HotASM_Fuction__1), asm_RET() }; HotASM (__HotASM_Fuction__1)[] = { asm_JBC_BIT(HotASM_24H_X(0), __HotASM_Fuction__), asm_RET() }; --------------------------------------------------------------------------------------------*/ #define HotASM_Code_JBC (HotASM_REG)0x10 #define asm_JBC_BIT(bit, rel) HotASM_Code_JBC, (bit), (rel) /*-------------------------------------------------------------------------------------------- ACALL addr11 指令名称:绝对调用指令 指令功能:构造目的地址,进行子程序调用。其方法是以指令提供的11位地址(al0~a0), 取代PC的低11位,PC的高5位不变。 操作内容:PC←(PC)+2 SP←(SP)+1 (SP)←(PC)7~0 SP←(SP)+1 (SP)←(PC)15~8 PC10~0←addrl0~0 字 节 数:2 机器周期:2 HotASM例: HotASM (__HotASM_Fuction__)[] = { asm_ACALL(0x250), asm_RET() }; --------------------------------------------------------------------------------------------*/ #define HotASM_Code_ACALL (HotASM_REG)0x11 #define asm_ACALL(addr) HotASM_AAREG(HotASM_Code_ACALL, addr)
|
|