ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Воскресенье
24 ноября
134689 Топик полностью
leon_ (11.10.2008 11:54, просмотров: 358) ответил whale на Поделитесь кодом int x=x*0.8 для меги 128
Варианты. 

#include <mega128.h>
void main(void)
{
int x;
    x = x * 0.8;// Не очень быстро - переводы во флоат и обратно
    x = (x << 3) / 10;      // быстрее
    x = ((x << 3) + 5) / 10;// Правильное округление
}



;==================== ASM ====================================

;CodeVisionAVR C Compiler V1.25.9 Evaluation
;(C) Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
;http://www.hpinfotech.com

;Chip type              : ATmega128
;Program type           : Application
;Clock frequency        : 14,745600 MHz
;Memory model           : Small
;Optimize for           : Speed
;(s)printf features     : int, width
;(s)scanf features      : int, width
;External SRAM size     : 0
;Data Stack size        : 1024 byte(s)
;Heap size              : 0 byte(s)
;Promote char to int    : No
;char is unsigned       : Yes
;8 bit enums            : Yes
;Word align FLASH struct: No
;Enhanced core instructions    : On
;Smart register allocation : On
;Automatic register allocation : On

        #pragma AVRPART ADMIN PART_NAME ATmega128
        #pragma AVRPART MEMORY PROG_FLASH 131072
        #pragma AVRPART MEMORY EEPROM 4096
        #pragma AVRPART MEMORY INT_SRAM SIZE 4096
        #pragma AVRPART MEMORY INT_SRAM START_ADDR 0x100

        .EQU UDRE=0x5
        .EQU RXC=0x7
        .EQU USR=0xB
        .EQU UDR=0xC
        .EQU SPSR=0xE
        .EQU SPDR=0xF
        .EQU EERE=0x0
        .EQU EEWE=0x1
        .EQU EEMWE=0x2
        .EQU EECR=0x1C
        .EQU EEDR=0x1D
        .EQU EEARL=0x1E
        .EQU EEARH=0x1F
        .EQU WDTCR=0x21
        .EQU MCUCR=0x35
        .EQU RAMPZ=0x3B
        .EQU SPL=0x3D
        .EQU SPH=0x3E
        .EQU SREG=0x3F
        .EQU XMCRA=0x6D
        .EQU XMCRB=0x6C

        .DEF R0X0=R0
        .DEF R0X1=R1
        .DEF R0X2=R2
        .DEF R0X3=R3
        .DEF R0X4=R4
        .DEF R0X5=R5
        .DEF R0X6=R6
        .DEF R0X7=R7
        .DEF R0X8=R8
        .DEF R0X9=R9
        .DEF R0XA=R10
        .DEF R0XB=R11
        .DEF R0XC=R12
        .DEF R0XD=R13
        .DEF R0XE=R14
        .DEF R0XF=R15
        .DEF R0X10=R16
        .DEF R0X11=R17
        .DEF R0X12=R18
        .DEF R0X13=R19
        .DEF R0X14=R20
        .DEF R0X15=R21
        .DEF R0X16=R22
        .DEF R0X17=R23
        .DEF R0X18=R24
        .DEF R0X19=R25
        .DEF R0X1A=R26
        .DEF R0X1B=R27
        .DEF R0X1C=R28
        .DEF R0X1D=R29
        .DEF R0X1E=R30
        .DEF R0X1F=R31

        .MACRO __CPD1N
        CPI  R30,LOW(@0)
        LDI  R26,HIGH(@0)
        CPC  R31,R26
        LDI  R26,BYTE3(@0)
        CPC  R22,R26
        LDI  R26,BYTE4(@0)
        CPC  R23,R26
        .ENDM

        .MACRO __CPD2N
        CPI  R26,LOW(@0)
        LDI  R30,HIGH(@0)
        CPC  R27,R30
        LDI  R30,BYTE3(@0)
        CPC  R24,R30
        LDI  R30,BYTE4(@0)
        CPC  R25,R30
        .ENDM

        .MACRO __CPWRR
        CP   R@0,R@2
        CPC  R@1,R@3
        .ENDM

        .MACRO __CPWRN
        CPI  R@0,LOW(@2)
        LDI  R30,HIGH(@2)
        CPC  R@1,R30
        .ENDM

        .MACRO __ADDB1MN
        SUBI R30,LOW(-@0-(@1))
        .ENDM
        .MACRO __ADDB2MN
        SUBI R26,LOW(-@0-(@1))
        .ENDM
        .MACRO __ADDW1MN
        SUBI R30,LOW(-@0-(@1))
        SBCI R31,HIGH(-@0-(@1))
        .ENDM
        .MACRO __ADDW2MN
        SUBI R26,LOW(-@0-(@1))
        SBCI R27,HIGH(-@0-(@1))
        .ENDM
        .MACRO __ADDW1FN
        SUBI R30,LOW(-2*@0-(@1))
        SBCI R31,HIGH(-2*@0-(@1))
        .ENDM
        .MACRO __ADDD1FN
        SUBI R30,LOW(-2*@0-(@1))
        SBCI R31,HIGH(-2*@0-(@1))
        SBCI R22,BYTE3(-2*@0-(@1))
        .ENDM
        .MACRO __ADDD1N
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        SBCI R22,BYTE3(-@0)
        SBCI R23,BYTE4(-@0)
        .ENDM

        .MACRO __ADDD2N
        SUBI R26,LOW(-@0)
        SBCI R27,HIGH(-@0)
        SBCI R24,BYTE3(-@0)
        SBCI R25,BYTE4(-@0)
        .ENDM

        .MACRO __SUBD1N
        SUBI R30,LOW(@0)
        SBCI R31,HIGH(@0)
        SBCI R22,BYTE3(@0)
        SBCI R23,BYTE4(@0)
        .ENDM

        .MACRO __SUBD2N
        SUBI R26,LOW(@0)
        SBCI R27,HIGH(@0)
        SBCI R24,BYTE3(@0)
        SBCI R25,BYTE4(@0)
        .ENDM

        .MACRO __ANDBMNN
        LDS  R30,@0+@1
        ANDI R30,LOW(@2)
        STS  @0+@1,R30
        .ENDM

        .MACRO __ANDWMNN
        LDS  R30,@0+@1
        ANDI R30,LOW(@2)
        STS  @0+@1,R30
        LDS  R30,@0+@1+1
        ANDI R30,HIGH(@2)
        STS  @0+@1+1,R30
        .ENDM

        .MACRO __ANDD1N
        ANDI R30,LOW(@0)
        ANDI R31,HIGH(@0)
        ANDI R22,BYTE3(@0)
        ANDI R23,BYTE4(@0)
        .ENDM

        .MACRO __ORBMNN
        LDS  R30,@0+@1
        ORI  R30,LOW(@2)
        STS  @0+@1,R30
        .ENDM

        .MACRO __ORWMNN
        LDS  R30,@0+@1
        ORI  R30,LOW(@2)
        STS  @0+@1,R30
        LDS  R30,@0+@1+1
        ORI  R30,HIGH(@2)
        STS  @0+@1+1,R30
        .ENDM

        .MACRO __ORD1N
        ORI  R30,LOW(@0)
        ORI  R31,HIGH(@0)
        ORI  R22,BYTE3(@0)
        ORI  R23,BYTE4(@0)
        .ENDM

        .MACRO __DELAY_USB
        LDI  R24,LOW(@0)
__DELAY_USB_LOOP:
        DEC  R24
        BRNE __DELAY_USB_LOOP
        .ENDM

        .MACRO __DELAY_USW
        LDI  R24,LOW(@0)
        LDI  R25,HIGH(@0)
__DELAY_USW_LOOP:
        SBIW R24,1
        BRNE __DELAY_USW_LOOP
        .ENDM

        .MACRO __CLRD1S
        LDI  R30,0
        STD  Y+@0,R30
        STD  Y+@0+1,R30
        STD  Y+@0+2,R30
        STD  Y+@0+3,R30
        .ENDM

        .MACRO __GETD1S
        LDD  R30,Y+@0
        LDD  R31,Y+@0+1
        LDD  R22,Y+@0+2
        LDD  R23,Y+@0+3
        .ENDM

        .MACRO __PUTD1S
        STD  Y+@0,R30
        STD  Y+@0+1,R31
        STD  Y+@0+2,R22
        STD  Y+@0+3,R23
        .ENDM

        .MACRO __PUTD2S
        STD  Y+@0,R26
        STD  Y+@0+1,R27
        STD  Y+@0+2,R24
        STD  Y+@0+3,R25
        .ENDM

        .MACRO __POINTB1MN
        LDI  R30,LOW(@0+@1)
        .ENDM

        .MACRO __POINTW1MN
        LDI  R30,LOW(@0+@1)
        LDI  R31,HIGH(@0+@1)
        .ENDM

        .MACRO __POINTD1M
        LDI  R30,LOW(@0)
        LDI  R31,HIGH(@0)
        LDI  R22,BYTE3(@0)
        LDI  R23,BYTE4(@0)
        .ENDM

        .MACRO __POINTW1FN
        LDI  R30,LOW(2*@0+@1)
        LDI  R31,HIGH(2*@0+@1)
        .ENDM

        .MACRO __POINTD1FN
        LDI  R30,LOW(2*@0+@1)
        LDI  R31,HIGH(2*@0+@1)
        LDI  R22,BYTE3(2*@0+@1)
        LDI  R23,BYTE4(2*@0+@1)
        .ENDM

        .MACRO __POINTB2MN
        LDI  R26,LOW(@0+@1)
        .ENDM

        .MACRO __POINTW2MN
        LDI  R26,LOW(@0+@1)
        LDI  R27,HIGH(@0+@1)
        .ENDM

        .MACRO __POINTBRM
        LDI  R@0,LOW(@1)
        .ENDM

        .MACRO __POINTWRM
        LDI  R@0,LOW(@2)
        LDI  R@1,HIGH(@2)
        .ENDM

        .MACRO __POINTBRMN
        LDI  R@0,LOW(@1+@2)
        .ENDM

        .MACRO __POINTWRMN
        LDI  R@0,LOW(@2+@3)
        LDI  R@1,HIGH(@2+@3)
        .ENDM

        .MACRO __POINTWRFN
        LDI  R@0,LOW(@2*2+@3)
        LDI  R@1,HIGH(@2*2+@3)
        .ENDM

        .MACRO __GETD1N
        LDI  R30,LOW(@0)
        LDI  R31,HIGH(@0)
        LDI  R22,BYTE3(@0)
        LDI  R23,BYTE4(@0)
        .ENDM

        .MACRO __GETD2N
        LDI  R26,LOW(@0)
        LDI  R27,HIGH(@0)
        LDI  R24,BYTE3(@0)
        LDI  R25,BYTE4(@0)
        .ENDM

        .MACRO __GETD2S
        LDD  R26,Y+@0
        LDD  R27,Y+@0+1
        LDD  R24,Y+@0+2
        LDD  R25,Y+@0+3
        .ENDM

        .MACRO __GETB1MN
        LDS  R30,@0+@1
        .ENDM

        .MACRO __GETB1HMN
        LDS  R31,@0+@1
        .ENDM

        .MACRO __GETW1MN
        LDS  R30,@0+@1
        LDS  R31,@0+@1+1
        .ENDM

        .MACRO __GETD1MN
        LDS  R30,@0+@1
        LDS  R31,@0+@1+1
        LDS  R22,@0+@1+2
        LDS  R23,@0+@1+3
        .ENDM

        .MACRO __GETBRMN
        LDS  R@0,@1+@2
        .ENDM

        .MACRO __GETWRMN
        LDS  R@0,@2+@3
        LDS  R@1,@2+@3+1
        .ENDM

        .MACRO __GETWRZ
        LDD  R@0,Z+@2
        LDD  R@1,Z+@2+1
        .ENDM

        .MACRO __GETD2Z
        LDD  R26,Z+@0
        LDD  R27,Z+@0+1
        LDD  R24,Z+@0+2
        LDD  R25,Z+@0+3
        .ENDM

        .MACRO __GETB2MN
        LDS  R26,@0+@1
        .ENDM

        .MACRO __GETW2MN
        LDS  R26,@0+@1
        LDS  R27,@0+@1+1
        .ENDM

        .MACRO __GETD2MN
        LDS  R26,@0+@1
        LDS  R27,@0+@1+1
        LDS  R24,@0+@1+2
        LDS  R25,@0+@1+3
        .ENDM

        .MACRO __PUTB1MN
        STS  @0+@1,R30
        .ENDM

        .MACRO __PUTW1MN
        STS  @0+@1,R30
        STS  @0+@1+1,R31
        .ENDM

        .MACRO __PUTD1MN
        STS  @0+@1,R30
        STS  @0+@1+1,R31
        STS  @0+@1+2,R22
        STS  @0+@1+3,R23
        .ENDM

        .MACRO __PUTBR0MN
        STS  @0+@1,R0
        .ENDM

        .MACRO __PUTDZ2
        STD  Z+@0,R26
        STD  Z+@0+1,R27
        STD  Z+@0+2,R24
        STD  Z+@0+3,R25
        .ENDM

        .MACRO __PUTBMRN
        STS  @0+@1,R@2
        .ENDM

        .MACRO __PUTWMRN
        STS  @0+@1,R@2
        STS  @0+@1+1,R@3
        .ENDM

        .MACRO __PUTBZR
        STD  Z+@1,R@0
        .ENDM

        .MACRO __PUTWZR
        STD  Z+@2,R@0
        STD  Z+@2+1,R@1
        .ENDM

        .MACRO __GETW1R
        MOV  R30,R@0
        MOV  R31,R@1
        .ENDM

        .MACRO __GETW2R
        MOV  R26,R@0
        MOV  R27,R@1
        .ENDM

        .MACRO __GETWRN
        LDI  R@0,LOW(@2)
        LDI  R@1,HIGH(@2)
        .ENDM

        .MACRO __PUTW1R
        MOV  R@0,R30
        MOV  R@1,R31
        .ENDM

        .MACRO __PUTW2R
        MOV  R@0,R26
        MOV  R@1,R27
        .ENDM

        .MACRO __ADDWRN
        SUBI R@0,LOW(-@2)
        SBCI R@1,HIGH(-@2)
        .ENDM

        .MACRO __ADDWRR
        ADD  R@0,R@2
        ADC  R@1,R@3
        .ENDM

        .MACRO __SUBWRN
        SUBI R@0,LOW(@2)
        SBCI R@1,HIGH(@2)
        .ENDM

        .MACRO __SUBWRR
        SUB  R@0,R@2
        SBC  R@1,R@3
        .ENDM

        .MACRO __ANDWRN
        ANDI R@0,LOW(@2)
        ANDI R@1,HIGH(@2)
        .ENDM

        .MACRO __ANDWRR
        AND  R@0,R@2
        AND  R@1,R@3
        .ENDM

        .MACRO __ORWRN
        ORI  R@0,LOW(@2)
        ORI  R@1,HIGH(@2)
        .ENDM

        .MACRO __ORWRR
        OR   R@0,R@2
        OR   R@1,R@3
        .ENDM

        .MACRO __EORWRR
        EOR  R@0,R@2
        EOR  R@1,R@3
        .ENDM

        .MACRO __GETWRS
        LDD  R@0,Y+@2
        LDD  R@1,Y+@2+1
        .ENDM

        .MACRO __PUTWSR
        STD  Y+@2,R@0
        STD  Y+@2+1,R@1
        .ENDM

        .MACRO __MOVEWRR
        MOV  R@0,R@2
        MOV  R@1,R@3
        .ENDM

        .MACRO __INWR
        IN   R@0,@2
        IN   R@1,@2+1
        .ENDM

        .MACRO __OUTWR
        OUT  @2+1,R@1
        OUT  @2,R@0
        .ENDM

        .MACRO __CALL1MN
        LDS  R30,@0+@1
        LDS  R31,@0+@1+1
        ICALL
        .ENDM

        .MACRO __CALL1FN
        LDI  R30,LOW(2*@0+@1)
        LDI  R31,HIGH(2*@0+@1)
        CALL __GETW1PF
        ICALL
        .ENDM

        .MACRO __CALL2EN
        LDI  R26,LOW(@0+@1)
        LDI  R27,HIGH(@0+@1)
        CALL __EEPROMRDW
        ICALL
        .ENDM

        .MACRO __GETW1STACK
        IN   R26,SPL
        IN   R27,SPH
        ADIW R26,@0+1
        LD   R30,X+
        LD   R31,X
        .ENDM

        .MACRO __NBST
        BST  R@0,@1
        IN   R30,SREG
        LDI  R31,0x40
        EOR  R30,R31
        OUT  SREG,R30
        .ENDM


        .MACRO __PUTB1SN
        LDD  R26,Y+@0
        LDD  R27,Y+@0+1
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        ST   X,R30
        .ENDM

        .MACRO __PUTW1SN
        LDD  R26,Y+@0
        LDD  R27,Y+@0+1
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        ST   X+,R30
        ST   X,R31
        .ENDM

        .MACRO __PUTD1SN
        LDD  R26,Y+@0
        LDD  R27,Y+@0+1
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        CALL __PUTDP1
        .ENDM

        .MACRO __PUTB1SNS
        LDD  R26,Y+@0
        LDD  R27,Y+@0+1
        ADIW R26,@1
        ST   X,R30
        .ENDM

        .MACRO __PUTW1SNS
        LDD  R26,Y+@0
        LDD  R27,Y+@0+1
        ADIW R26,@1
        ST   X+,R30
        ST   X,R31
        .ENDM

        .MACRO __PUTD1SNS
        LDD  R26,Y+@0
        LDD  R27,Y+@0+1
        ADIW R26,@1
        CALL __PUTDP1
        .ENDM

        .MACRO __PUTB1PMN
        LDS  R26,@0
        LDS  R27,@0+1
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        ST   X,R30
        .ENDM

        .MACRO __PUTW1PMN
        LDS  R26,@0
        LDS  R27,@0+1
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        ST   X+,R30
        ST   X,R31
        .ENDM

        .MACRO __PUTD1PMN
        LDS  R26,@0
        LDS  R27,@0+1
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        CALL __PUTDP1
        .ENDM

        .MACRO __PUTB1PMNS
        LDS  R26,@0
        LDS  R27,@0+1
        ADIW R26,@1
        ST   X,R30
        .ENDM

        .MACRO __PUTW1PMNS
        LDS  R26,@0
        LDS  R27,@0+1
        ADIW R26,@1
        ST   X+,R30
        ST   X,R31
        .ENDM

        .MACRO __PUTD1PMNS
        LDS  R26,@0
        LDS  R27,@0+1
        ADIW R26,@1
        CALL __PUTDP1
        .ENDM

        .MACRO __PUTB1RN
        MOVW R26,R@0
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        ST   X,R30
        .ENDM

        .MACRO __PUTW1RN
        MOVW R26,R@0
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        ST   X+,R30
        ST   X,R31
        .ENDM

        .MACRO __PUTD1RN
        MOVW R26,R@0
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        CALL __PUTDP1
        .ENDM

        .MACRO __PUTB1RNS
        MOVW R26,R@0
        ADIW R26,@1
        ST   X,R30
        .ENDM

        .MACRO __PUTW1RNS
        MOVW R26,R@0
        ADIW R26,@1
        ST   X+,R30
        ST   X,R31
        .ENDM

        .MACRO __PUTD1RNS
        MOVW R26,R@0
        ADIW R26,@1
        CALL __PUTDP1
        .ENDM

        .MACRO __PUTB1RON
        MOV  R26,R@0
        MOV  R27,R@1
        SUBI R26,LOW(-@2)
        SBCI R27,HIGH(-@2)
        ST   X,R30
        .ENDM

        .MACRO __PUTW1RON
        MOV  R26,R@0
        MOV  R27,R@1
        SUBI R26,LOW(-@2)
        SBCI R27,HIGH(-@2)
        ST   X+,R30
        ST   X,R31
        .ENDM

        .MACRO __PUTD1RON
        MOV  R26,R@0
        MOV  R27,R@1
        SUBI R26,LOW(-@2)
        SBCI R27,HIGH(-@2)
        CALL __PUTDP1
        .ENDM

        .MACRO __PUTB1RONS
        MOV  R26,R@0
        MOV  R27,R@1
        ADIW R26,@2
        ST   X,R30
        .ENDM

        .MACRO __PUTW1RONS
        MOV  R26,R@0
        MOV  R27,R@1
        ADIW R26,@2
        ST   X+,R30
        ST   X,R31
        .ENDM

        .MACRO __PUTD1RONS
        MOV  R26,R@0
        MOV  R27,R@1
        ADIW R26,@2
        CALL __PUTDP1
        .ENDM


        .MACRO __GETB1SX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        LD   R30,Z
        .ENDM

        .MACRO __GETB1HSX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        LD   R31,Z
        .ENDM

        .MACRO __GETW1SX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        LD   R0,Z+
        LD   R31,Z
        MOV  R30,R0
        .ENDM

        .MACRO __GETD1SX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        LD   R0,Z+
        LD   R1,Z+
        LD   R22,Z+
        LD   R23,Z
        MOVW R30,R0
        .ENDM

        .MACRO __GETB2SX
        MOVW R26,R28
        SUBI R26,LOW(-@0)
        SBCI R27,HIGH(-@0)
        LD   R26,X
        .ENDM

        .MACRO __GETW2SX
        MOVW R26,R28
        SUBI R26,LOW(-@0)
        SBCI R27,HIGH(-@0)
        LD   R0,X+
        LD   R27,X
        MOV  R26,R0
        .ENDM

        .MACRO __GETD2SX
        MOVW R26,R28
        SUBI R26,LOW(-@0)
        SBCI R27,HIGH(-@0)
        LD   R0,X+
        LD   R1,X+
        LD   R24,X+
        LD   R25,X
        MOVW R26,R0
        .ENDM

        .MACRO __GETBRSX
        MOVW R30,R28
        SUBI R30,LOW(-@1)
        SBCI R31,HIGH(-@1)
        LD   R@0,Z
        .ENDM

        .MACRO __GETWRSX
        MOVW R30,R28
        SUBI R30,LOW(-@2)
        SBCI R31,HIGH(-@2)
        LD   R@0,Z+
        LD   R@1,Z
        .ENDM

        .MACRO __LSLW8SX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        LD   R31,Z
        CLR  R30
        .ENDM

        .MACRO __PUTB1SX
        MOVW R26,R28
        SUBI R26,LOW(-@0)
        SBCI R27,HIGH(-@0)
        ST   X,R30
        .ENDM

        .MACRO __PUTW1SX
        MOVW R26,R28
        SUBI R26,LOW(-@0)
        SBCI R27,HIGH(-@0)
        ST   X+,R30
        ST   X,R31
        .ENDM

        .MACRO __PUTD1SX
        MOVW R26,R28
        SUBI R26,LOW(-@0)
        SBCI R27,HIGH(-@0)
        ST   X+,R30
        ST   X+,R31
        ST   X+,R22
        ST   X,R23
        .ENDM

        .MACRO __CLRW1SX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        CLR  R0
        ST   Z+,R0
        ST   Z,R0
        .ENDM

        .MACRO __CLRD1SX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        CLR  R0
        ST   Z+,R0
        ST   Z+,R0
        ST   Z+,R0
        ST   Z,R0
        .ENDM

        .MACRO __PUTB2SX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        ST   Z,R26
        .ENDM

        .MACRO __PUTW2SX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        ST   Z+,R26
        ST   Z,R27
        .ENDM

        .MACRO __PUTD2SX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        ST   Z+,R26
        ST   Z+,R27
        ST   Z+,R24
        ST   Z,R25
        .ENDM

        .MACRO __PUTBSRX
        MOVW R30,R28
        SUBI R30,LOW(-@0)
        SBCI R31,HIGH(-@0)
        ST   Z,R@1
        .ENDM

        .MACRO __PUTWSRX
        MOVW R30,R28
        SUBI R30,LOW(-@2)
        SBCI R31,HIGH(-@2)
        ST   Z+,R@0
        ST   Z,R@1
        .ENDM

        .MACRO __PUTB1SNX
        MOVW R26,R28
        SUBI R26,LOW(-@0)
        SBCI R27,HIGH(-@0)
        LD   R0,X+
        LD   R27,X
        MOV  R26,R0
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        ST   X,R30
        .ENDM

        .MACRO __PUTW1SNX
        MOVW R26,R28
        SUBI R26,LOW(-@0)
        SBCI R27,HIGH(-@0)
        LD   R0,X+
        LD   R27,X
        MOV  R26,R0
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        ST   X+,R30
        ST   X,R31
        .ENDM

        .MACRO __PUTD1SNX
        MOVW R26,R28
        SUBI R26,LOW(-@0)
        SBCI R27,HIGH(-@0)
        LD   R0,X+
        LD   R27,X
        MOV  R26,R0
        SUBI R26,LOW(-@1)
        SBCI R27,HIGH(-@1)
        ST   X+,R30
        ST   X+,R31
        ST   X+,R22
        ST   X,R23
        .ENDM

        .MACRO __MULBRR
        MULS R@0,R@1
        MOVW R30,R0
        .ENDM

        .MACRO __MULBRRU
        MUL  R@0,R@1
        MOVW R30,R0
        .ENDM

        .MACRO __MULBRR0
        MULS R@0,R@1
        .ENDM

        .MACRO __MULBRRU0
        MUL  R@0,R@1
        .ENDM

        .MACRO __MULBNWRU
        LDI  R26,@2
        MUL  R26,R@0
        MOVW R30,R0
        MUL  R26,R@1
        ADD  R31,R0
        .ENDM

        .CSEG
        .ORG 0

        .INCLUDE "1.vec"
        .INCLUDE "1.inc"

__RESET:
        CLI
        CLR  R30
        OUT  EECR,R30

;INTERRUPT VECTORS ARE PLACED
;AT THE START OF FLASH
        LDI  R31,1
        OUT  MCUCR,R31
        OUT  MCUCR,R30
        STS  XMCRB,R30

;DISABLE WATCHDOG
        LDI  R31,0x18
        OUT  WDTCR,R31
        OUT  WDTCR,R30

;CLEAR R2-R14
        LDI  R24,13
        LDI  R26,2
        CLR  R27
__CLEAR_REG:
        ST   X+,R30
        DEC  R24
        BRNE __CLEAR_REG

;CLEAR SRAM
        LDI  R24,LOW(0x1000)
        LDI  R25,HIGH(0x1000)
        LDI  R26,LOW(0x100)
        LDI  R27,HIGH(0x100)
__CLEAR_SRAM:
        ST   X+,R30
        SBIW R24,1
        BRNE __CLEAR_SRAM

        OUT  RAMPZ,R24

;GLOBAL VARIABLES INITIALIZATION
        LDI  R30,LOW(__GLOBAL_INI_TBL*2)
        LDI  R31,HIGH(__GLOBAL_INI_TBL*2)
__GLOBAL_INI_NEXT:
        LPM  R24,Z+
        LPM  R25,Z+
        SBIW R24,0
        BREQ __GLOBAL_INI_END
        LPM  R26,Z+
        LPM  R27,Z+
        LPM  R0,Z+
        LPM  R1,Z+
        MOVW R22,R30
        MOVW R30,R0
__GLOBAL_INI_LOOP:
        LPM  R0,Z+
        ST   X+,R0
        SBIW R24,1
        BRNE __GLOBAL_INI_LOOP
        MOVW R30,R22
        RJMP __GLOBAL_INI_NEXT
__GLOBAL_INI_END:

;STACK POINTER INITIALIZATION
        LDI  R30,LOW(0x10FF)
        OUT  SPL,R30
        LDI  R30,HIGH(0x10FF)
        OUT  SPH,R30

;DATA STACK POINTER INITIALIZATION
        LDI  R28,LOW(0x500)
        LDI  R29,HIGH(0x500)

        JMP  _main

        .ESEG
        .ORG 0

        .DSEG
        .ORG 0x500
;          1 #include <mega128.h>
;          2         #ifndef __SLEEP_DEFINED__
        #ifndef __SLEEP_DEFINED__
;          3         #define __SLEEP_DEFINED__
        #define __SLEEP_DEFINED__
;          4         .EQU __se_bit=0x20
        .EQU __se_bit=0x20
;          5         .EQU __sm_mask=0x1C
        .EQU __sm_mask=0x1C
;          6         .EQU __sm_powerdown=0x10
        .EQU __sm_powerdown=0x10
;          7         .EQU __sm_powersave=0x18
        .EQU __sm_powersave=0x18
;          8         .EQU __sm_standby=0x14
        .EQU __sm_standby=0x14
;          9         .EQU __sm_ext_standby=0x1C
        .EQU __sm_ext_standby=0x1C
;         10         .EQU __sm_adc_noise_red=0x08
        .EQU __sm_adc_noise_red=0x08
;         11         .SET power_ctrl_reg=mcucr
        .SET power_ctrl_reg=mcucr
;         12         #endif
        #endif
;         13 void main(void)
;         14 {

        .CSEG
_main:
;         15 int x;
;         16     x = x * 0.8;                // Не очень быстро - переводы во флоат и обратно
;        x -> R16,R17
        MOVW R30,R16
        CALL __CWD1
        CALL __CDF1
        __GETD2N 0x3F4CCCCD
        CALL __MULF12
        CALL __CFD1
        MOVW R16,R30
;         17     x = (x << 3) / 10;          // быстрее
        MOVW R30,R16
        CALL __LSLW3
        MOVW R26,R30
        LDI  R30,LOW(10)
        LDI  R31,HIGH(10)
        CALL __DIVW21
        MOVW R16,R30
;         18     x = ((x << 3) + 5) / 10;    // Правильное округление
        MOVW R30,R16
        CALL __LSLW3
        ADIW R30,5
        MOVW R26,R30
        LDI  R30,LOW(10)
        LDI  R31,HIGH(10)
        CALL __DIVW21
        MOVW R16,R30
;         19 }
_0x3:
        RJMP _0x3


__ANEGW1:
        NEG  R31
        NEG  R30
        SBCI R31,0
        RET

__ANEGD1:
        COM  R31
        COM  R22
        COM  R23
        NEG  R30
        SBCI R31,-1
        SBCI R22,-1
        SBCI R23,-1
        RET

__LSLW3:
        LSL  R30
        ROL  R31
__LSLW2:
        LSL  R30
        ROL  R31
        LSL  R30
        ROL  R31
        RET

__CWD1:
        MOV  R22,R31
        ADD  R22,R22
        SBC  R22,R22
        MOV  R23,R22
        RET

__DIVW21U:
        CLR  R0
        CLR  R1
        LDI  R25,16
__DIVW21U1:
        LSL  R26
        ROL  R27
        ROL  R0
        ROL  R1
        SUB  R0,R30
        SBC  R1,R31
        BRCC __DIVW21U2
        ADD  R0,R30
        ADC  R1,R31
        RJMP __DIVW21U3
__DIVW21U2:
        SBR  R26,1
__DIVW21U3:
        DEC  R25
        BRNE __DIVW21U1
        MOVW R30,R26
        MOVW R26,R0
        RET

__DIVW21:
        RCALL __CHKSIGNW
        RCALL __DIVW21U
        BRTC __DIVW211
        RCALL __ANEGW1
__DIVW211:
        RET

__CHKSIGNW:
        CLT
        SBRS R31,7
        RJMP __CHKSW1
        RCALL __ANEGW1
        SET
__CHKSW1:
        SBRS R27,7
        RJMP __CHKSW2
        COM  R26
        COM  R27
        ADIW R26,1
        BLD  R0,0
        INC  R0
        BST  R0,0
__CHKSW2:
        RET

__ROUND_REPACK:
        TST  R21
        BRPL __REPACK
        CPI  R21,0x80
        BRNE __ROUND_REPACK0
        SBRS R30,0
        RJMP __REPACK
__ROUND_REPACK0:
        ADIW R30,1
        ADC  R22,R25
        ADC  R23,R25
        BRVS __REPACK1

__REPACK:
        LDI  R21,0x80
        EOR  R21,R23
        BRNE __REPACK0
        PUSH R21
        RJMP __ZERORES
__REPACK0:
        CPI  R21,0xFF
        BREQ __REPACK1
        LSL  R22
        LSL  R0
        ROR  R21
        ROR  R22
        MOV  R23,R21
        RET
__REPACK1:
        PUSH R21
        TST  R0
        BRMI __REPACK2
        RJMP __MAXRES
__REPACK2:
        RJMP __MINRES

__UNPACK:
        LDI  R21,0x80
        MOV  R1,R25
        AND  R1,R21
        LSL  R24
        ROL  R25
        EOR  R25,R21
        LSL  R21
        ROR  R24

__UNPACK1:
        LDI  R21,0x80
        MOV  R0,R23
        AND  R0,R21
        LSL  R22
        ROL  R23
        EOR  R23,R21
        LSL  R21
        ROR  R22
        RET

__CFD1U:
        SET
        RJMP __CFD1U0
__CFD1:
        CLT
__CFD1U0:
        PUSH R21
        RCALL __UNPACK1
        CPI  R23,0x80
        BRLO __CFD10
        CPI  R23,0xFF
        BRCC __CFD10
        RJMP __ZERORES
__CFD10:
        LDI  R21,22
        SUB  R21,R23
        BRPL __CFD11
        NEG  R21
        CPI  R21,8
        BRTC __CFD19
        CPI  R21,9
__CFD19:
        BRLO __CFD17
        SER  R30
        SER  R31
        SER  R22
        LDI  R23,0x7F
        BLD  R23,7
        RJMP __CFD15
__CFD17:
        CLR  R23
        TST  R21
        BREQ __CFD15
__CFD18:
        LSL  R30
        ROL  R31
        ROL  R22
        ROL  R23
        DEC  R21
        BRNE __CFD18
        RJMP __CFD15
__CFD11:
        CLR  R23
__CFD12:
        CPI  R21,8
        BRLO __CFD13
        MOV  R30,R31
        MOV  R31,R22
        MOV  R22,R23
        SUBI R21,8
        RJMP __CFD12
__CFD13:
        TST  R21
        BREQ __CFD15
__CFD14:
        LSR  R23
        ROR  R22
        ROR  R31
        ROR  R30
        DEC  R21
        BRNE __CFD14
__CFD15:
        TST  R0
        BRPL __CFD16
        RCALL __ANEGD1
__CFD16:
        POP  R21
        RET

__CDF1U:
        SET
        RJMP __CDF1U0
__CDF1:
        CLT
__CDF1U0:
        SBIW R30,0
        SBCI R22,0
        SBCI R23,0
        BREQ __CDF10
        CLR  R0
        BRTS __CDF11
        TST  R23
        BRPL __CDF11
        COM  R0
        RCALL __ANEGD1
__CDF11:
        MOV  R1,R23
        LDI  R23,30
        TST  R1
__CDF12:
        BRMI __CDF13
        DEC  R23
        LSL  R30
        ROL  R31
        ROL  R22
        ROL  R1
        RJMP __CDF12
__CDF13:
        MOV  R30,R31
        MOV  R31,R22
        MOV  R22,R1
        PUSH R21
        RCALL __REPACK
        POP  R21
__CDF10:
        RET

__ZERORES:
        CLR  R30
        CLR  R31
        CLR  R22
        CLR  R23
        POP  R21
        RET

__MINRES:
        SER  R30
        SER  R31
        LDI  R22,0x7F
        SER  R23
        POP  R21
        RET

__MAXRES:
        SER  R30
        SER  R31
        LDI  R22,0x7F
        LDI  R23,0x7F
        POP  R21
        RET

__MULF12:
        PUSH R21
        RCALL __UNPACK
        CPI  R23,0x80
        BREQ __ZERORES
        CPI  R25,0x80
        BREQ __ZERORES
        EOR  R0,R1
        SEC
        ADC  R23,R25
        BRVC __MULF124
        BRLT __ZERORES
__MULF125:
        TST  R0
        BRMI __MINRES
        RJMP __MAXRES
__MULF124:
        PUSH R0
        PUSH R17
        PUSH R18
        PUSH R19
        PUSH R20
        CLR  R17
        CLR  R18
        CLR  R25
        MUL  R22,R24
        MOVW R20,R0
        MUL  R24,R31
        MOV  R19,R0
        ADD  R20,R1
        ADC  R21,R25
        MUL  R22,R27
        ADD  R19,R0
        ADC  R20,R1
        ADC  R21,R25
        MUL  R24,R30
        RCALL __MULF126
        MUL  R27,R31
        RCALL __MULF126
        MUL  R22,R26
        RCALL __MULF126
        MUL  R27,R30
        RCALL __MULF127
        MUL  R26,R31
        RCALL __MULF127
        MUL  R26,R30
        ADD  R17,R1
        ADC  R18,R25
        ADC  R19,R25
        ADC  R20,R25
        ADC  R21,R25
        MOV  R30,R19
        MOV  R31,R20
        MOV  R22,R21
        MOV  R21,R18
        POP  R20
        POP  R19
        POP  R18
        POP  R17
        POP  R0
        TST  R22
        BRMI __MULF122
        LSL  R21
        ROL  R30
        ROL  R31
        ROL  R22
        RJMP __MULF123
__MULF122:
        INC  R23
        BRVS __MULF125
__MULF123:
        RCALL __ROUND_REPACK
        POP  R21
        RET

__MULF127:
        ADD  R17,R0
        ADC  R18,R1
        ADC  R19,R25
        RJMP __MULF128
__MULF126:
        ADD  R18,R0
        ADC  R19,R1
__MULF128:
        ADC  R20,R25
        ADC  R21,R25
        RET

;END OF CODE MARKER
__END_OF_CODE: