/*------------------------------------------------------------ HotC51汇编数组定义头文件(HotAsm.h V1.01) 最初建立时间: 2009.2.18 最近修改时间: 2009.2.22 (正在添加之中,最终将彻底替代嵌入汇编) 增 添原 因: 为全面支持裸奔式实时操作系统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.22 于西安大雁塔村农会授权HotC51发布 ---------------------------------------------------------------*/
#include <regx52.h> #include <absacc.h> #include <intrins.h>
#ifndef __HotASM_H__ #define __HotASM_H__
#ifdef __cplusplus extern "C" { #endif
#include "hottask51.h"//裸奔之OS系统链接头文件
/*-------------------------------------------- 汇编数组定义 --------------------------------------------*/ #define HotASM_ARRAY code unsigned char
/*-------------------------------------------- 汇编数组成员数据类型定义 --------------------------------------------*/ #define HotASM_REG volatile unsigned char #define HotASM_IREG volatile unsigned int #define HotASM_AREG(reg) (HotASM_REG)reg #define HOTASM_LAREG(addr) (HotASM_REG)addr / 256, (HotASM_REG)addr % 256
/*-------------------------------------------- 汇编数组"函数" --------------------------------------------*/ #define HotASM(name) HotASM_ARRAY (name)
/*-------------------------------------------- 汇编数组51寄存器定义 --------------------------------------------*/ #define HotASM_REG_P0 (HotASM_REG)0x80 /*-------------------------------------------- 汇编数组P0寄存器位定义 --------------------------------------------*/ #define HotASM_BIT_P0_0 (HotASM_REG)0x80 #define HotASM_BIT_P0_1 (HotASM_REG)0x81 #define HotASM_BIT_P0_2 (HotASM_REG)0x82 #define HotASM_BIT_P0_3 (HotASM_REG)0x83 #define HotASM_BIT_P0_4 (HotASM_REG)0x84 #define HotASM_BIT_P0_5 (HotASM_REG)0x85 #define HotASM_BIT_P0_6 (HotASM_REG)0x86 #define HotASM_BIT_P0_7 (HotASM_REG)0x87 #define HotASM_REG_SP (HotASM_REG)0x81 #define HotASM_REG_DPL (HotASM_REG)0x82 #define HotASM_REG_DPH (HotASM_REG)0x83 #define HotASM_REG_PCON (HotASM_REG)0x87 /*-------------------------------------------- 汇编数组PCON寄存器位定义(不能位寻址) --------------------------------------------*/ #define HotASM_BIT_PCON_IDL (HotASM_REG)0x01 #define HotASM_BIT_PCON_STOP (HotASM_REG)0x02 #define HotASM_BIT_PCON_PD (HotASM_REG)0x03 /* Alternate definition */ #define HotASM_BIT_PCON_GF0 (HotASM_REG)0x08 #define HotASM_BIT_PCON_GF1 (HotASM_REG)0x04
#define HotASM_BIT_PCON_SMOD (HotASM_REG)0x80 #define HotASM_REG_TCON (HotASM_REG)0x88 #define HotASM_BIT_TCON_0 (HotASM_REG)0x88 #define HotASM_BIT_TCON_1 (HotASM_REG)0x89 #define HotASM_BIT_TCON_2 (HotASM_REG)0x8A #define HotASM_BIT_TCON_3 (HotASM_REG)0x8B #define HotASM_BIT_TCON_4 (HotASM_REG)0x8C #define HotASM_BIT_TCON_5 (HotASM_REG)0x8D #define HotASM_BIT_TCON_6 (HotASM_REG)0x8E #define HotASM_BIT_TCON_7 (HotASM_REG)0x8F
#define HotASM_BIT_TCON_IT0 (HotASM_REG)0x88 #define HotASM_BIT_TCON_IE0 (HotASM_REG)0x89 #define HotASM_BIT_TCON_IT1 (HotASM_REG)0x8A #define HotASM_BIT_TCON_IE1 (HotASM_REG)0x8B #define HotASM_BIT_TCON_TR0 (HotASM_REG)0x8C #define HotASM_BIT_TCON_TF0 (HotASM_REG)0x8D #define HotASM_BIT_TCON_TR1 (HotASM_REG)0x8E #define HotASM_BIT_TCON_TF1 (HotASM_REG)0x8F #define HotASM_REG_TMOD (HotASM_REG)0x89 /*-------------------------------------------- 汇编数组TMOD寄存器位定义(不能位寻址) --------------------------------------------*/ #define HotASM_BIT_TMOD_0 (HotASM_REG)0x01 #define HotASM_BIT_TMOD_1 (HotASM_REG)0x02 #define HotASM_BIT_TMOD_2 (HotASM_REG)0x04 #define HotASM_BIT_TMOD_3 (HotASM_REG)0x08 #define HotASM_BIT_TMOD_4 (HotASM_REG)0x10 #define HotASM_BIT_TMOD_5 (HotASM_REG)0x20 #define HotASM_BIT_TMOD_6 (HotASM_REG)0x40 #define HotASM_BIT_TMOD_7 (HotASM_REG)0x80
#define HotASM_REG_TL0 (HotASM_REG)0x8a #define HotASM_REG_TH0 (HotASM_REG)0x8c #define HotASM_REG_TL1 (HotASM_REG)0x8b #define HotASM_REG_TH1 (HotASM_REG)0x8d #define HotASM_REG_P1 (HotASM_REG)0x90 /*-------------------------------------------- 汇编数组P1寄存器位定义 --------------------------------------------*/ #define HotASM_BIT_P1_0 (HotASM_REG)0x90 #define HotASM_BIT_P1_1 (HotASM_REG)0x91 #define HotASM_BIT_P1_2 (HotASM_REG)0x92 #define HotASM_BIT_P1_3 (HotASM_REG)0x93 #define HotASM_BIT_P1_4 (HotASM_REG)0x94 #define HotASM_BIT_P1_5 (HotASM_REG)0x95 #define HotASM_BIT_P1_6 (HotASM_REG)0x96 #define HotASM_BIT_P1_7 (HotASM_REG)0x97 #define HotASM_REG_SCON (HotASM_REG)0x98 #define HotASM_BIT_SCON_0 (HotASM_REG)0x98 #define HotASM_BIT_SCON_1 (HotASM_REG)0x99 #define HotASM_BIT_SCON_2 (HotASM_REG)0x9A #define HotASM_BIT_SCON_3 (HotASM_REG)0x9B #define HotASM_BIT_SCON_4 (HotASM_REG)0x9C #define HotASM_BIT_SCON_5 (HotASM_REG)0x9D #define HotASM_BIT_SCON_6 (HotASM_REG)0x9E #define HotASM_BIT_SCON_7 (HotASM_REG)0x9F
#define HotASM_BIT_SCON_RI (HotASM_REG)0x98 #define HotASM_BIT_SCON_TI (HotASM_REG)0x99 #define HotASM_BIT_SCON_RB8 (HotASM_REG)0x9A #define HotASM_BIT_SCON_TB8 (HotASM_REG)0x9B #define HotASM_BIT_SCON_REN (HotASM_REG)0x9C #define HotASM_BIT_SCON_SM2 (HotASM_REG)0x9D #define HotASM_BIT_SCON_SM1 (HotASM_REG)0x9E #define HotASM_BIT_SCON_SM0 (HotASM_REG)0x9F #define HotASM_REG_SBUF (HotASM_REG)0x99 #define HotASM_REG_P2 (HotASM_REG)0xa0 /*-------------------------------------------- 汇编数组P2寄存器位定义 --------------------------------------------*/ #define HotASM_BIT_P2_0 (HotASM_REG)0xa0 #define HotASM_BIT_P2_1 (HotASM_REG)0xa1 #define HotASM_BIT_P2_2 (HotASM_REG)0xa2 #define HotASM_BIT_P2_3 (HotASM_REG)0xa3 #define HotASM_BIT_P2_4 (HotASM_REG)0xa4 #define HotASM_BIT_P2_5 (HotASM_REG)0xa5 #define HotASM_BIT_P2_6 (HotASM_REG)0xa6 #define HotASM_BIT_P2_7 (HotASM_REG)0xa7 #define HotASM_REG_IE (HotASM_REG)0xa8 #define HotASM_BIT_IE0 (HotASM_REG)0xa8 #define HotASM_BIT_IE1 (HotASM_REG)0xa9 #define HotASM_BIT_IE2 (HotASM_REG)0xaa #define HotASM_BIT_IE3 (HotASM_REG)0xab #define HotASM_BIT_IE4 (HotASM_REG)0xac #define HotASM_BIT_IE5 (HotASM_REG)0xad #define HotASM_BIT_IE6 (HotASM_REG)0xae #define HotASM_BIT_IE7 (HotASM_REG)0xaf
#define HotASM_BIT_EX0 (HotASM_REG)0xa8 #define HotASM_BIT_ET0 (HotASM_REG)0xa9 #define HotASM_BIT_EX1 (HotASM_REG)0xaa #define HotASM_BIT_ET1 (HotASM_REG)0xab #define HotASM_BIT_ES (HotASM_REG)0xac #define HotASM_BIT_ET2 (HotASM_REG)0xad // #define HotASM_BIT_IE6 (HotASM_REG)0xae #define HotASM_BIT_EA (HotASM_REG)0xaf #define HotASM_REG_P3 (HotASM_REG)0xb0 /*-------------------------------------------- 汇编数组P3寄存器位定义 --------------------------------------------*/ #define HotASM_BIT_P3_0 (HotASM_REG)0xb0 #define HotASM_BIT_P3_1 (HotASM_REG)0xb1 #define HotASM_BIT_P3_2 (HotASM_REG)0xb2 #define HotASM_BIT_P3_3 (HotASM_REG)0xb3 #define HotASM_BIT_P3_4 (HotASM_REG)0xb4 #define HotASM_BIT_P3_5 (HotASM_REG)0xb5 #define HotASM_BIT_P3_6 (HotASM_REG)0xb6 #define HotASM_BIT_P3_7 (HotASM_REG)0xb7 #define HotASM_REG_IP (HotASM_REG)0xb8 #define HotASM_BIT_IP_0 (HotASM_REG)0xb8 #define HotASM_BIT_IP_1 (HotASM_REG)0xb9 #define HotASM_BIT_IP_2 (HotASM_REG)0xba #define HotASM_BIT_IP_3 (HotASM_REG)0xbb #define HotASM_BIT_IP_4 (HotASM_REG)0xbc #define HotASM_BIT_IP_5 (HotASM_REG)0xbd #define HotASM_BIT_IP_6 (HotASM_REG)0xbe #define HotASM_BIT_IP_7 (HotASM_REG)0xbf #define HotASM_REG_PSW (HotASM_REG)0xd0 #define HotASM_BIT_PSW_0 (HotASM_REG)0xd0 #define HotASM_BIT_PSW_1 (HotASM_REG)0xd1 #define HotASM_BIT_PSW_2 (HotASM_REG)0xd2 #define HotASM_BIT_PSW_3 (HotASM_REG)0xd3 #define HotASM_BIT_PSW_4 (HotASM_REG)0xd4 #define HotASM_BIT_PSW_5 (HotASM_REG)0xd5 #define HotASM_BIT_PSW_6 (HotASM_REG)0xd6 #define HotASM_BIT_PSW_7 (HotASM_REG)0xd7
#define HotASM_BIT_PSW_PX0 (HotASM_REG)0xd0 #define HotASM_BIT_PSW_PT0 (HotASM_REG)0xd1 #define HotASM_BIT_PSW_PX1 (HotASM_REG)0xd2 #define HotASM_BIT_PSW_PT1 (HotASM_REG)0xd3 #define HotASM_BIT_PSW_PS (HotASM_REG)0xd4 #define HotASM_BIT_PSW_PT2 (HotASM_REG)0xd5 // #define HotASM_BIT_PSW_6 (HotASM_REG)0xd6 // #define HotASM_BIT_PSW_7 (HotASM_REG)0xd7
#define HotASM_BIT_PSW_P (HotASM_REG)0xd0 #define HotASM_BIT_PSW_F1 (HotASM_REG)0xd1 #define HotASM_BIT_PSW_OV (HotASM_REG)0xd2 #define HotASM_BIT_PSW_RS0 (HotASM_REG)0xd3 #define HotASM_BIT_PSW_RS1 (HotASM_REG)0xd4 #define HotASM_BIT_PSW_F0 (HotASM_REG)0xd5 #define HotASM_BIT_PSW_AC (HotASM_REG)0xd6 #define HotASM_BIT_PSW_C (HotASM_REG)0xd7 #define HotASM_REG_T2CON (HotASM_REG)0xc8 #define HotASM_REG_TH2 (HotASM_REG)0xcd #define HotASM_REG_TL2 (HotASM_REG)0xcc #define HotASM_REG_RCAP2H (HotASM_REG)0xcb #define HotASM_REG_RCAP2L (HotASM_REG)0xca #define HotASM_REG_ACC (HotASM_REG)0xe0 /*-------------------------------------------- 汇编数组ACC寄存器位定义 --------------------------------------------*/ #define HotASM_BIT_ACC_0 (HotASM_REG)0xe0 #define HotASM_BIT_ACC_1 (HotASM_REG)0xe1 #define HotASM_BIT_ACC_2 (HotASM_REG)0xe2 #define HotASM_BIT_ACC_3 (HotASM_REG)0xe3 #define HotASM_BIT_ACC_4 (HotASM_REG)0xe4 #define HotASM_BIT_ACC_5 (HotASM_REG)0xe5 #define HotASM_BIT_ACC_6 (HotASM_REG)0xe6 #define HotASM_BIT_ACC_7 (HotASM_REG)0xe7 #define HotASM_REG_B (HotASM_REG)0xf0 /*-------------------------------------------- 汇编数组B寄存器位定义 --------------------------------------------*/ #define HotASM_BIT_B_0 (HotASM_REG)0xf0 #define HotASM_BIT_B_1 (HotASM_REG)0xf1 #define HotASM_BIT_B_2 (HotASM_REG)0xf2 #define HotASM_BIT_B_3 (HotASM_REG)0xf3 #define HotASM_BIT_B_4 (HotASM_REG)0xf4 #define HotASM_BIT_B_5 (HotASM_REG)0xf5 #define HotASM_BIT_B_6 (HotASM_REG)0xf6 #define HotASM_BIT_B_7 (HotASM_REG)0xf7 /*-------------------------------------------- 汇编宏指令操作码定义 --------------------------------------------*/
#define HotASM_Code_LJMP (HotASM_REG)0x02 #define HotASM_Code_SJMP (HotASM_REG)0x80
#define HotASM_Code_LCALL (HotASM_REG)0x12
#define HotASM_Code_PUSH (HotASM_REG)0xc0 #define HotASM_Code_INC (HotASM_REG)0x05 #define HotASM_Code_DEC (HotASM_REG)0x15
#define HotASM_Code_MOV_DPTR (HotASM_REG)0x90
/*-------------------------------------------- 汇编宏指令 --------------------------------------------*/ #define HotASM_NOP() (HotASM_REG)0x00 #define HotASM_RR_A() (HotASM_REG)0x03 #define HotASM_INC_A() (HotASM_REG)0x04
#define HotASM_CLR_A() (HotASM_REG)0xe4
#define HotASM_RET() (HotASM_REG)0x22 #define HotASM_RETI() (HotASM_REG)0x32
#define HotASM_MOV_DPTR(addr) HotASM_Code_MOV_DPTR, HOTASM_LAREG(addr)
#define HotASM_LJMP(addr) HotASM_Code_LJMP, HOTASM_LAREG(addr)
#define HotASM_LCALL(addr) HotASM_Code_LCALL, HOTASM_LAREG(addr) #define HotASM_PUSH_(reg) HotASM_Code_PUSH, HotASM_AREG(reg)
#define HotASM_PUSH_PSW() HotASM_Code_PUSH, HotASM_REG_PSW #define HotASM_PUSH_ACC() HotASM_Code_PUSH, HotASM_REG_ACC #define HotASM_PUSH_B() HotASM_Code_PUSH, HotASM_REG_B #define HotASM_PUSH_DPL() HotASM_Code_PUSH, HotASM_REG_DPL #define HotASM_PUSH_DPH() HotASM_Code_PUSH, HotASM_REG_DPH
#define HotASM_Code_INC_(reg) HotASM_Code_INC,HotASM_AREG(reg) #define HotASM_INC_SP() HotASM_Code_INC, HotASM_REG_SP #define HotASM_Code_DEC_(reg) HotASM_Code_DEC,HotASM_AREG(reg) #define HotASM_DEC_SP() HotASM_Code_DEC, HotASM_REG_SP
/*-------------------------------------- HotTask51汇编数组调用函数接口定义 --------------------------------------*/ #define interface typedef struct//COM接口定义
typedef void (*pHotAsmFunction)(void);//函数指针
interface { void (*HotAsm_Start)(void); void (*HotAsm_Reset)(void); }IHotCom_AsmVtbl_Interface, *pIHotCom_AsmVtbl_Interface;
interface { IHotCom_AsmVtbl_Interface function; }IHotCom_Asm_Interface, *pIHotCom_Asm_Interface;
extern IHotCom_Asm_Interface asmLib;
extern HotASM_ARRAY (__reset_comlib__)[];
/*-------------------------------------- HotTask51汇编数组存放任务表定义 --------------------------------------*/ //extern HotASM_ARRAY HotTaskTable0[]; //extern HotASM_ARRAY HotTaskTable1[];
#ifdef __cplusplus } #endif #endif//__HotASM_H__
|
|
文章评论(0条评论)
登录后参与讨论