AVR单片机C语言调用汇编指令集的宏
/*************************************
*** AVR单片机C语言调用汇编指令集的宏 ***
*************************************/
#ifndef _ASM_H_
#define _ASM_H_
/********************
*** 算术和逻辑指令 ***
********************/
// ### ADD ### 两个寄存器相加 (dest = dest + src)
#define ASM_ADD(dest, src) asm volatile ("add %0, %1" : "=r" (dest) : "r" (src))
// ### ADC ### 两个寄存器带进位位相加 (dest = dest + src + carry)
#define ASM_ADC(dest, src) asm volatile ("adc %0, %1" : "=r" (dest) : "r" (src))
// ### ADC_zero ### Add Carry To Register dest (dest = dest + carry), Special Form Of ADC
#define ASM_ADCzero(dest) asm volatile ("adc %0, __zero_reg__" : "=r" (dest) :)
// ### ADIW ### 立即数与字相加 (word = word - const)
#define ASM_ADIW(word, const) asm volatile ("adiw %0, %1" : "=w" (word) : "I" (const))
// ### SUB ### 两个寄存器相减 (dest = dest - src)
#define ASM_SUB(dest, src) asm volatile ("sub %0, %1" : "=r" (dest) : "r" (src))
// ### SUBI ### 立即数与寄存器相减 (reg = reg - const)
#define ASM_SUBI(reg, const) asm volatile ("subi %0, %1" : "=d" (reg) : "M" (const))
// ### SBC ### 两个寄存器带进位位相减 (dest = dest - src - carry)
#define ASM_SBC(dest, src) asm volatile ("sbc %0, %1" : "=r" (dest) : "r" (src))
// ### SBC_zero ### Subtract Carry From Register dest (dest = dest - carry), Special Form Of SBC
#define ASM_SBC_zero(dest) asm volatile ("sbc %0, __zero_reg__ " : "=r" (dest) :)
// ### SBIW ### 字与立即数相减 (reg = reg - const)
#define ASM_SBIW(word, const) asm volatile ("sbiw %0, %1" : "=w" (word) : "I" (const))
// ### AND ### 两个寄存器逻辑与 (dest = dest & src)
#define ASM_AND(dest, src) asm volatile ("and %0, %1" : "=r" (dest) : "r" (src))
// ### ANDI ### 寄存器与常数逻辑与 (reg = reg & const)
#define ASM_ANDI(reg, const) asm volatile ("andi %0, %1" : "=d" (reg) : "M" (const))
// ### OR ### 两个寄存器逻辑或 (dest = dest | src)
#define ASM_OR(dest, src) asm volatile ("or %0, %1" : "=r" (dest) : "r" (src))
// ### ORI ### 寄存器与常数逻辑或 (reg = reg | const)
#define ASM_ORI(reg, const) asm volatile ("ori %0, %1" : "=d" (reg) : "M" (const))
// ### EOR ### 两个寄存器异或 (dest = dest ^ src)
#define ASM_EOR(dest, src) asm volatile ("eor %0, %1" : "=r" (dest) : "r" (src))
// ### COM ### 1的补码 (reg = 0xFF - reg)
#define ASM_COM(reg) asm volatile ("com %0" : "=r" (reg) : "0" (reg))
// ### NEG ### 2的补码 (reg = 0x00 - reg)
#define ASM_NEG(reg) asm volatile ("neg %0" : "=r" (reg) : "0" (reg))
// ### SBR ### 寄存器的某些位置位 (reg = reg | mask)
#define ASM_SBR(reg, mask) asm volatile ("sbr %0, %1" : "=d" (reg) : "M" (mask))
// ### CBR ### 寄存器的某些
位清零 (reg = reg & ~mask)
#define ASM_CBR(reg, mask) asm volatile ("sbr %0, %1" : "=d" (reg) : "M" (mask))
// ### INC ### 加一 (reg = reg + 1)
#define ASM_INC(reg) asm volatile ("inc %0" : "=r" (reg) : "0" (reg))
// ### DEC ### 减一Rd ← (reg = reg - 1)
#define ASM_DEC(reg) asm volatile ("dec %0" : "=r" (reg) : "0" (reg))
// ### TST ### 测试为0或负 (reg = reg & reg)
#define ASM_TST(reg) asm volatile ("tst %0" : "=r" (reg) : "0" (reg))
// ### CLR ### 清零寄存器 (reg = reg ^ reg)
#define ASM_CLR(reg) asm volatile ("clr %0" : "=r" (reg) : "0" (reg))
// ### SER ### 置位寄存器 (reg = 0xFF)
#define ASM_SER(reg) asm volatile ("ser %0" : "=r" (reg) : "0" (reg))
// ### MUL ### 无符号数相乘 (r1:r0 = ureg1 * ureg2)
#define ASM_MUL(ureg1, ureg2) asm volatile ("mul %0, %1" :: "r" (ureg1), "r" (ureg2))
// ### MULS ### 有符号数相乘 (r1:r2 = sreg1 * sreg2)
汇编指令有多少个
#define ASM_MULS(sreg1, sreg2) asm volatile ("muls %0, %1" :: "d" (sreg1), "d" (sreg2))
// ### MULSU ### 有符号数与无符号数相乘 (r1:r2 = sreg * ureg)
#define ASM_MULSU(sreg, ureg) asm volatile ("mulsu %0, %1" :: "a" (sreg), "a" (ureg))
// ### FMUL ### 无符号小数相乘 (r1:r2 = (ureg1 * ureg2) << 1)
#define ASM_FMUL(ureg1, ureg2) asm volatile ("fmul %0, %1" :: "a" (ureg1), "a" (ureg2))
// ### FMULS ### 有符号小数相乘 (r1:r2 = (sreg1 * sreg2) << 1)
#define ASM_FMULS(sreg1, sreg2) asm volatile ("fmuls %0, %1" :: "a" (sreg1), "a" (sreg2))
// ### FMULSU ### 无符号小数与有符号小数相乘 (r1:r2 = (sreg * ureg) << 1)
#define ASM_FMULSU(sreg, ureg) asm volatile ("fmulsu %0, %1" :: "a" (sreg), "a" (ureg))
/***************
*** 跳转指令 ***
***************/
// ### ICALL ### 相对调用到(Z) (PC = Z)
#define ASM_ICALL() asm volatile ("icall" :: )
/******************
*** 数据传输指令 ***

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。