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

📄 imul16.s43

📁 msp430F437三相电表DEMO(编译器 IAR 3.42A)
💻 S43
字号:
//--------------------------------------------------------------------------
//
//  Software for MSP430 based e-meters.
//
//  You may not use the Program in non-TI devices.
//
//  File: imul16.c
//
//  Steve Underwood <steve-underwood@ti.com>
//  Texas Instruments Hong Kong Ltd.
//
//  $Id: imul16.c,v 1.2 2003/07/28 10:15:41 XHKJAMES Exp $
//
//--------------------------------------------------------------------------
#include "io.h"

//This routine implements a 16x16->32 2's complement multiplier. If a hardware
//multiplier is available it is used. If no hardware multiplier is available,
//Booth's algorithm is used to directly implement a signed multiplier in software.
//C does not normally express a 16x16->32 operation, and the speedup of achieving
//a 32-bit answer by a full 32x32 multiply is substantial.

;int32_t imul16(register int16_t x, register int16_t y)
    public imul16

    RSEG CODE
imul16
#if defined(RESLO_)  &&  defined(RESHI_)  &&  defined(MPYS_)  &&  defined(OP2_)
    push.w  SR
    dint
    mov     R12,&MPYS_
    mov     R14,&OP2_
    mov     &RESHI_,R13
    mov     &RESLO_,R12
    pop.w   SR
#if defined(__MSP430_HAS_MSP430X_CPU__)
    reta
#else
    ret
#endif
#else
    push.w R10
    push.w R15
    mov     R12,R15
    clr     R13
    mov     R13,R12

    mov     R13,R10
    tst     R15
    jge     booth_2
    mov     #-1,R10
    jmp     booth_2

booth_6
    add     R15,R12
    addc    R10,R13
booth_1
    rla     R15
    rlc     R10
booth_2
    rra     R14
    jc      booth_5
    jne     booth_1
    jmp     booth_4

booth_5
    sub     R15,R12
    subc    R10,R13
booth_3
    rla     R15
    rlc     R10
    rra     R14
    jnc     booth_6
    cmp     #0xFFFF,R14
    jne     booth_3

booth_4
    pop.w   R15
    pop.w   R10
#if defined(__MSP430_HAS_MSP430X_CPU__)
    reta
#else
    ret
#endif
#endif
    end

⌨️ 快捷键说明

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