⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 code_asm.asm

📁 电动车电流流量计显示程序. 单片机根据采样电阻采得电流后通过数码管显示当前电流是多少安培.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
        BLT  addtlow    ;V^N:      /* can be too low */
        BPL  addret1    ;V=0 & N=0
        LDA  #0FFh      ;V=1 & N=1 /* too high */
        LDX  #07Fh
addret1:RTS
addtlow:BMI  addret2    ;V=0 & N=1
        CLRA            ;V=1 & N=0 /* too low */
        LDX  #080h
addret2:RTS


;/*****************************************************************************
;*
;* Module: unsigned char uadd_8uu(unsigned char x, unsigned char y)
;*
;* Description:
;*   The function performs the unsigned addition x+y with overflow control
;*   and saturation. The 8-bit result is set at +255 when overflow occurs,
;*
;* Returns:   x + y
;*
;* Arguments: x (in)
;*            y (in)
;*
;* Range Issues: None
;*
;* Special Issues: The result is saturated
;*
;*****************************************************************************/ 
uadd_8uu:   PSHX
            TSX
            ADD  ,X         ;          /* x + y */
            PULH
            BCC  uad8uuret1 ;C=0
            LDA  #0FFh      ;C=1 /* too high */
uad8uuret1: RTS


;/*****************************************************************************
;*
;* Module: unsigned int uadd_uu(unsigned int x, unsigned int y)
;*
;* Description:
;*   The function performs the addition x+y with overflow control
;*   and saturation. The 16-bit result is set at +65535 when overflow occurs,
;*
;* Returns:   x + y
;*
;* Arguments: x (in)
;*            y (in)
;*
;* Range Issues: None
;*
;* Special Issues: The result is saturated
;*
;*****************************************************************************/

uadd_uu:  ADD  4,SP       ;          /* x + y */
          PSHA
          TXA
          ADC  4,SP
          TAX
          PULA
          BCC  uaduuret1  ;C=0
          LDA  #0FFh      ;C=1 /* too high */
          LDX  #0FFh
uaduuret1:RTS


;/*****************************************************************************
;*
;* Module: SByte sub_8(SByte x, SByte y)
;*
;* Description:
;*   The function performs the subtraction x-y with overflow control
;*   and saturation. The 8-bit result is set at +127 when overflow occurs,
;*   or at -128 when underflow occurs.
;*
;* Returns:   x - y
;*
;* Arguments: x (in)
;*            y (in)
;*
;* Range Issues: None
;*
;* Special Issues: The result is saturated
;*
;*****************************************************************************/
;  /* (V - Overflow Flag, N - Negative flag) */
;  /* V=1 & N=1 too high */
;  /* V=1 & N=0 too low  */ 
sub_8:  PSHX
        TSX
        SUB  ,X         ;x-y
        PULH
        BLT  sb8tlow    ;V^N:      /* can be too low */
        BPL  sb8ret1    ;V=0 & N=0
        LDA  #07Fh      ;V=1 & N=1 /* too high */
sb8ret1:RTS
sb8tlow:BMI  sb8ret2    ;V=0 & N=1
        LDA  #080h      ;V=1 & N=0 /* too low */
sb8ret2:RTS


;/*****************************************************************************
;*
;* Module: signed int sub(signed int x, signed int y)
;*
;* Description:
;*   The function performs the subtraction x-y with overflow control
;*   and saturation. The 16-bit result is set at +32767 when overflow occurs,
;*   or at -32768 when underflow occurs.
;*
;* Returns:   x - y
;*
;* Arguments: x (in)
;*            y (in)
;*
;* Range Issues: None
;*
;* Special Issues: The result is saturated
;*
;*****************************************************************************/
;  /* (V - Overflow Flag, N - Negative flag) */
;  /* V=1 & N=1 too high */
;  /* V=1 & N=0 too low  */ 
sub:    PSHA
        PSHX
        TSX
        LDA  5,X        ;x - y
        SUB  1,X
        PSHA
        LDA  4,X
        SBC  ,X
        TAX
        PULA
        AIS  #2
        BLT  subtlow    ;V^N:      /* can be too low */
        BPL  subret1    ;V=0 & N=0
        LDA  #0FFh      ;V=1 & N=1 /* too high */
        LDX  #07Fh
subret1:RTS
subtlow:BMI  subret2    ;V=0 & N=1
        CLRA            ;V=1 & N=0 /* too low */
        LDX  #080h
subret2:RTS


;/*****************************************************************************
;*
;* Module: unsigned char usub_8uu(unsigned char x, unsigned char y)
;*
;* Description:
;*   The function performs the subtraction x-y with overflow control
;*   and saturation. The 8-bit result is set at 0 when underflow occurs.
;*
;* Returns:   x - y
;*
;* Arguments: x (in)
;*            y (in)
;*
;* Range Issues: None
;*
;* Special Issues: The result is saturated
;*
;*****************************************************************************/
usub_8uu:  PSHX
           TSX
           SUB  ,X         ;x-y
           PULH
           BCC  usb8uuret1 ;C=0
           CLRA            ;C=1 /* too low */      
usb8uuret1:RTS


;/*****************************************************************************
;*
;* Module: unsigned int usub_uu(unsigned int x, unsigned int y)
;*
;* Description:
;*   The function performs the subtraction x-y with overflow control
;*   and saturation. The 16-bit result is set at 0 when underflow occurs.
;*
;* Returns:   x - y
;*
;* Arguments: x (in)
;*            y (in)
;*
;* Range Issues: None
;*
;* Special Issues: The result is saturated
;*
;*****************************************************************************/
usub_uu:   PSHA
           PSHX
           TSX
           LDA  5,X        ;x - y
           SUB  1,X
           PSHA
           LDA  4,X
           SBC  ,X
           TAX
           PULA
           AIS  #2
           BCC  usubuuret1 ;C=0
           CLRA            ;C=1  /* too low */
           CLRX
usubuuret1:RTS


;/*****************************************************************************
;*
;* Module: signed char sub_8uu(unsigned char x, unsigned char y)
;*
;* Description:
;*   The function performs the subtraction x-y with overflow control
;*   and saturation. The 8-bit result is set at +127 when overflow occurs,
;*   or at -128 when underflow occurs.
;*
;* Returns:   x - y
;*
;* Arguments: x (in)
;*            y (in)
;*
;* Range Issues: None
;*
;* Special Issues: The result is saturated
;*
;*****************************************************************************/
sub_8uu:  PSHX
          TSX
          SUB  ,X         ;x-y
          PULH
          BCS  sb8C0      ;C=1             /* can be too low */
          BPL  sb8uuret1  ;C=0 & N=0 
          LDA  #07Fh      ;C=0 & N=1       /* too high */
sb8uuret1:RTS
sb8C0:    BMI  sb8uuret2  ;C=1 & N=1
          LDA  #080h      ;C=1 & N=0       /* too low */
sb8uuret2:RTS


;/*****************************************************************************
;*
;* Module: SByte neg_8(SByte x)
;*
;* Description:
;*   The function performs the negation of x with overflow control
;*   and saturation. The 8-bit result is set at +127 when overflow occurs.
;*
;* Returns:   -x
;*
;* Arguments: x (in)
;*
;* Range Issues: None
;*
;* Special Issues: The result is saturated
;*
;*****************************************************************************/
;  /* (V - Overflow Flag, N - Negative flag) */
;  /* V=1 & N=1 too high */
;  /* Overflow can ocure only if negative x is negated */
neg_8:  
        NEGA           ;        /* x = -x */
        BPL  endneg8   ;N=0     /* x was negative but overflow did not ocure */
        BLT  endneg8   ;N=1 V=0 /* x was positive */
        DECA           ;N=1 V=1 /* to high */
endneg8:RTS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -