;USB to USART bridge
;Compiled by LUFA
;Disassembly By H. Stamp

; AT90USB162
; assembled by AVR STUDIO

.NoList

.include	"usb162def.inc"
.List
.Org 0x0000
         JMP       Start     	;Internal Interrupt Request 0
.Org 0x0002
         JMP       Reset     	;External Interrupt Request 0
.Org 0x0004   
		 JMP       Reset     	;External Interrupt Request 1
.Org 0x0006  
		 JMP       Reset     	;External Interrupt Request 2
.Org 0x0008   
		 JMP       Reset     	;External Interrupt Request 3
.Org 0x000A   
		 JMP       Reset     	;External Interrupt Request 4
.Org 0x000C
		 JMP       Reset     	;External Interrupt Request 5
.Org 0x000E   
		 JMP       Reset     	;External Interrupt Request 6
.Org 0x0010 
         JMP       Reset     	;External Interrupt Request 7
.Org 0x0012   
		 JMP       Reset     	;Pin Change Interrupt Request 0
.Org 0x0014  
		 JMP       Reset     	;Pin Change Interrupt Request 1
.Org 0x0016   
		 JMP       __Vector_11  ;USB General Interrupt Request
.Org 0x0018   
		 JMP       Reset     	;USB Endpoint/Pipe Interrupt Communication Request
.Org 0x001A   
		 JMP       Reset     	;Watchdog Time-out Interrupt
.Org 0x001C   
		 JMP       Reset     	;Timer/Counter2 Capture Event
.Org 0x001E   
		 JMP       Reset     	;Timer/Counter2 Compare Match A
.Org 0x0020   
		 JMP       Reset     	;Timer/Counter2 Compare Match B
.Org 0x0022
		 JMP       Reset     	;Timer/Counter2 Compare Match C
.Org 0x0024
		 JMP       Reset     	;Timer/Counter1 Overflow
.Org 0x0026
		 JMP       Reset     	;Timer/Counter0 Compare Match A
.Org 0x0028
		 JMP       Reset     	;Timer/Counter0 Compare Match B
.Org 0x002A
  		 JMP       Reset     	;Timer/Counter0 Overflow
.Org 0x002C
		 JMP       Reset     	;SPI Serial Transfer Complete
.Org 0x002E
		 JMP       Reset     	;USART1, Rx Complete
.Org 0x0030
		 JMP       Reset     	;USART1 Data register Empty
.Org 0x0032
		 JMP       Reset     	;USART1, Tx Complete
.Org 0x0034
		 JMP       Reset     	;Analog Comparator
.Org 0x0036
		 JMP       Reset     	;EEPROM Ready
.Org 0x0038
		 JMP       Reset     	;Store Program Memory Read


;Table Device Descriptor: 0000003A:
	   	 .DW 0x0112        
         .DW 0x0200   ;bcdUSB:  0x0200
         .DW 0x0002   ;bDeviceClass:   0x02 (Communications and CDC Control)
                      ;bDeviceSubClass:0x00
		 .DW 0x2000   ;bMaxPacketSize0:0x20 (32)     
                      ;bDeviceProtocol:0x00
         .DW 0x03EB   ;idVendor:  0x03EB (Atmel Corporation) 
         .DW 0x2018   ;idProduct: 0x2018      
         .DW 0x1000   ;bcdDevice:      0x1000     
         .DW 0x0000   ;iProduct:       0x00    
                      ;iManufacturer:  0x00
         .DW 0x0100   ;bNumConfigurations: 0x01
                      ;iSerialNumber:      0x00
;Table ConnectionStatus:         
         .DW 0x0209        
         
		 .DW 0x0043   ;wTotalLength:       0x0043     
         .DW 0x0102   ;bNumInterfaces:       0x02    
                      ;bConfigurationValue:  0x01
		 
		 .DW 0x8000   ;iConfiguration:       0x00     
         			  ;bmAttributes:         0x80 (Bus Powered )
		 .DW 0x0932   ;MaxPower:             0x32 (100 Ma)       
                      ;0x09
		 .DW 0x0004        
         .DW 0x0100        
         .DW 0x0202        
         .DW 0x0001        
		 .DW 0x2405  
		 .DW 0x1000        
		 .DW 0x0501      
         .DW 0x0124        
         .DW 0x0103        
         .DW 0x2404        
         .DW 0x0602        
         .DW 0x2405        
         .DW 0x0006        
         .DW 0x0701        
         .DW 0x8305        
         .DW 0x2003        
         .DW 0xFF00        
         .DW 0x0409       
         .DW 0x0001       
         .DW 0x0A02      
         .DW 0x0000       
         .DW 0x0700        
         .DW 0x8105        
         .DW 0x2002        
         .DW 0x0000        
         .DW 0x0507        
         .DW 0x0202        
         .DW 0x0020        
         .DW 0x0C00        
 ;ATMEL" AVR USB CDC DEMO 1.0.0       
	 .DW 0x4103   ;A     
         .DW 0x5400   ;T     
         .DW 0x4D00   ;M     
         .DW 0x4500   ;E       
         .DW 0x4C00   ;L   
         .DW 0x2200   ;"    
         .DW 0x4103   ;A   
         .DW 0x5600   ;V     
         .DW 0x5200   ;R
         .DW 0x2000   ;Space    
         .DW 0x5500   ;U     
         .DW 0x5300   ;S     
         .DW 0x4200   ;B    
         .DW 0x2000   ;Space     
         .DW 0x4300   ;C     
         .DW 0x4400   ;D    
         .DW 0x4300   ;C    
         .DW 0x2000   ;Space     
         .DW 0x4400   ;D      
         .DW 0x4500   ;E      
         .DW 0x4D00   ;M      
         .DW 0x4F00   ;O      
         .DW 0x0C00   ;      
         .DW 0x3103   ;1     
         .DW 0x2E00   ;.      
         .DW 0x3000   ;0      
         .DW 0x2E00   ;.      
         .DW 0x3000   ;0      
;         
		 .DW 0x0400        
         .DW 0x0903        
         .DW 0x0004        

Start: 
         ;Clear Staus Register 
		 CLR       R1             ;Clear Register R1=0x00
         OUT       SREG,R1        ;Out 0x00 to 0x3F=I=0 T=0 H=0 S=0 V N Z C
         ;Set Stack 02FF
		 SER       R28            ;R28=FF
         LDI       R29,0x02       ;R29=0x02
         OUT       SPH,R29        ;Out to =SP15 SP14 SP13 SP12 SP11 SP10 SP9 SP8
         OUT       SPL,R28        ;Out to =SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0
         ;Load Data from JoyStick Table 
		 LDI       R17,0x01       ;Load immediate
         LDI       R26,0x00       ;Load immediate XL=00
         LDI       R27,0x01       ;Load immediate XH=01
         ;Set Z for JoyStick Table 
	 	 Ldi	   ZH,HIGH(JoyStickTbl*2)
		 Ldi	   ZL,Low(JoyStickTbl*2)
	 	 RJMP      PC+0x0003      ;
	     
		 LPM       R0,Z+          ;Load program memory From Table and postincrement
         ST        X+,R0          ;Store indirect 0x0100 and postincrement 
         ;Test for Table length 
		 CPI       R26,0x70       ;Compare count 0f 0x70 hex
         CPC       R27,R17        ;Compare with carry
         BRNE      PC-0x04        ;Get another Byte
         ;Done with JoyStick Table
		 LDI       R17,0x01       ;Load immediate
         LDI       R26,0x70       ;Load immediate XL=00
         LDI       R27,0x01       ;Load immediate XH=01
         RJMP      PC+0x0002      ;Relative jump
         ;Clear Memeory 0x0170-0x193
		 ST        X+,R1          ;Store R1=0x00 indirect and postincrement
         CPI       R26,0x94       ;Compare with immediate
         CPC       R27,R17        ;Compare with carry
         BRNE      PC-0x03        ;Branch if not equal
         CALL      Main			  ;
         JMP       Global_Interrupt_Disable 
Reset:
         JMP       0x0000         ; 
      
USB_User_Get_Descriptor:    ;usb_specific_request.c 
         LDI       R24,0x00       ;Load immediate
         RET                      ;Subroutine return

CDC_Get_Line_Coding:
;               Usb_ack_receive_setup();
         LDS       R24,0x00E8     ;Load direct from data space UEINTX=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         ANDI      R24,0xF7       ;Logical AND with immediate 1111 0111
         STS       UEINTX,R24     ;Store direct to 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI=0 RXOUTI STALLEDI TXINI

;            	Usb_write_byte(LSB0(line_coding.dwDTERate));
         LDS       R24,0x0179     ;Load direct from data space
         STS       UEDATX,R24     ;Store direct to 0x00F1= DAT7:0

;            	Usb_write_byte(LSB1(line_coding.dwDTERate));
         LDS       R24,0x017A     ;Load direct from data space
         STS       UEDATX,R24     ;Store direct to 0x00F1=DAT7:0

;            	Usb_write_byte(LSB2(line_coding.dwDTERate));
         LDS       R24,0x017B     ;Load direct from data space
         STS       UEDATX,R24     ;Store direct to 0x00F1=DAT7:0

;            	Usb_write_byte(LSB3(line_coding.dwDTERate));
         LDS       R24,0x017C     ;Load direct from data space
         STS       UEDATX,R24     ;Store direct to 0x00F1=DAT7:0

;            	Usb_write_byte(line_coding.bCharFormat);
         LDS       R24,0x017D     ;Load direct from data space
         STS       UEDATX,R24     ;Store direct to 0x00F1=DAT7:0

;            	Usb_write_byte(line_coding.bParityType);
         LDS       R24,0x017E     ;Load direct from data space
         STS       UEDATX,R24     ;Store direct to 0x00F1=DAT7:0

;            	Usb_write_byte(line_coding.bDataBits);
         LDS       R24,0x017F     ;Load direct from data space
         STS       UEDATX,R24     ;Store direct to 0x00F1=DAT7:0

;            	Usb_send_control_in();
         LDS       R24,UEINTX     ;Load direct from 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         ANDI      R24,0xFE       ;Logical AND with immediate
         STS       UEINTX,R24     ;Store direct to 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI

;            	while(!(Is_usb_read_control_enabled()));
         LDS       R24,UEINTX     ;Load direct from 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump

;             while(!Is_usb_receive_out());
         LDS       R24,UEINTX     ;Load direct from 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         SBRS      R24,2          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump

;             Usb_ack_receive_out();
         LDS       R24,UEINTX     ;Load direct from 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         ANDI      R24,0xFB       ;Logical AND with immediate FB=11111011
         STS       UEINTX,R24     ;Store direct to 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         LDS       R24,UEINTX     ;Load direct from 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         ANDI      R24,0x7F       ;Logical AND with immediate 7F=01111111
         STS       UEINTX,R24     ;Store direct to 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
;          }
         RET                      ;Subroutine return

CDC_Set_Line_Coding:
;             Usb_ack_receive_setup();
         LDS       R24,UEINTX     ;Load direct from 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       UEINTX,R24     ;Store direct to 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI

;             while (!(Is_usb_receive_out()));
         LDS       R24,UEINTX     ;Load direct from 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         SBRS      R24,2          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump

;          	LSB0(line_coding.dwDTERate) = Usb_read_byte();
         LDS       R24,UEDATX     ;Load direct from 0x00F1= DAT7:0
         STS       0x0179,R24     ;Store direct to data space

;             LSB1(line_coding.dwDTERate) = Usb_read_byte();
         LDS       R24,UEDATX     ;Load direct from 0x00F1= DAT7:0
         STS       0x017A,R24     ;Store direct to data space

;             LSB2(line_coding.dwDTERate) = Usb_read_byte();
         LDS       R24,UEDATX     ;Load direct from 0x00F1= DAT7:0
         STS       0x017B,R24     ;Store direct to data space

;             LSB3(line_coding.dwDTERate) = Usb_read_byte();
         LDS       R24,UEDATX     ;Load direct from 0x00F1= DAT7:0
         STS       0x017C,R24     ;Store direct to data space

;             line_coding.bCharFormat = Usb_read_byte();
         LDS       R24,UEDATX     ;Load direct from 0x00F1= DAT7:0
         STS       0x017D,R24     ;Store direct to data space

;             line_coding.bParityType = Usb_read_byte();
         LDS       R24,UEDATX     ;Load direct from 0x00F1= DAT7:0
         STS       0x017E,R24     ;Store direct to data space

;             line_coding.bDataBits = Usb_read_byte();
         LDS       R24,UEDATX     ;Load direct from 0x00F1= DAT7:0
         STS       0x017F,R24     ;Store direct to data space

;            	Usb_ack_receive_out();
         LDS       R24,UEINTX     ;Load direct from 0x00E8= FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         ANDI      R24,0xFB       ;Logical AND with immediate FB=1111 1011
         STS       UEINTX,R24     ;Store direct to 0x00E8= FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI=0 STALLEDI TXINI
         LDS       R24,UEINTX     ;Load direct from 0x00E8= FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         ANDI      R24,0x7F       ;Logical AND with immediate FB=01111111
         STS       UEINTX,R24     ;Store direct to 0x00E8= FIFOCON=0 NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI

;            	Usb_send_control_in();                // send a ZLP for STATUS phase
         LDS       R24,UEINTX     ;Load direct from data space 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         ANDI      R24,0xFE       ;Logical AND with immediate FE=11111110
         STS       UEINTX,R24     ;Store direct to data space 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI=0

;            	while(!(Is_usb_read_control_enabled()));
         LDS       R24,UEINTX    ;Load direct from data space 0x00E8 
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump

;          	Uart_set_baudrate((line_coding.dwDTERate)/2);
         LDS       R18,0x0179     ;Load direct from data space
         LDS       R19,0x017A     ;Load direct from data space
         LDS       R20,0x017B     ;Load direct from data space
         LDS       R21,0x017C     ;Load direct from data space
         LSR       R21            ;Logical shift right
         ROR       R20            ;Rotate right through carry
         ROR       R19            ;Rotate right through carry
         ROR       R18            ;Rotate right through carry
         LDI       R24,0x04       ;Load immediate
         LSL       R18            ;Logical Shift Left
         ROL       R19            ;Rotate Left Through Carry
         ROL       R20            ;Rotate Left Through Carry
         ROL       R21            ;Rotate Left Through Carry
         DEC       R24            ;Decrement
         BRNE      PC-0x05        ;Branch if not equal
         LDI       R22,0x00       ;Load immediate
         LDI       R23,0x12       ;Load immediate
         LDI       R24,0x7A       ;Load immediate
         LDI       R25,0x00       ;Load immediate
         CALL      SubA0674       ;Call subroutine SubA0674
         SUBI      R18,0x01       ;Subtract immediate
         SBCI      R19,0x00       ;Subtract immediate with carry
         STS       0x00CD,R19     ;Store direct to data space UBRR1H - - - - USART1 Baud Rate Register High Byte
         STS       0x00CC,R18     ;Store direct to data space UBRR1L - - - - USART1 Baud Rate Register Low Byte
         RET                      ;return

CDC_Set_Control_Line_State:
;            	Usb_ack_receive_setup();
         LDS       R24,UEINTX     ;Load direct from data space 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         ANDI      R24,0xF7       ;Logical AND with immediate 1111 0111
         STS       UEINTX,R24     ;Store direct to data space 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI=0 RXOUTI STALLEDI TXINI
;          	Usb_send_control_in();
         LDS       R24,UEINTX     ;Load direct from data space 
         ANDI      R24,0xFE       ;Logical AND with immediate FE=11111110
         STS       UEINTX,R24     ;Store direct to data space 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI=0
;            	while(!(Is_usb_read_control_enabled()));
         LDS       R24,UEINTX     ;Load direct from data space 0x00E8=FIFOCON NAKINI RWAL NAKOUTI RXSTPI RXOUTI STALLEDI TXINI
         SBRS      R24,0          ;Skip if bit0 in register set 
         RJMP      PC-0x0003      ;Relative jump
;          }
         RET                      ;Subroutine return

USB_User_Read_Request:
;             string_type     = Usb_read_byte();
         LDS       R24,UEDATX     ;Load direct from data space 0x00F1=DAT7:0
;          	descriptor_type = Usb_read_byte();
         LDS       R24,UEDATX     ;Load direct from data space 0x00F1=DAT7:0
;          	switch(request)
         CPI       R22,0x21       ;Compare with immediate 0x21=00100001
         BREQ      PC+0x07        ;Branch if equal
         CPI       R22,0x22       ;Compare with immediate 0x22=00100010
         BREQ      PC+0x0C        ;Branch if equal
         CPI       R22,0x20       ;Compare with immediate 0x20=00100000
         BREQ      PC+0x06        ;Branch if equal
         LDI       R24,0x00       ;Load immediate 0x00
         RET                      ;Subroutine return
;          			cdc_get_line_coding();
         CALL      CDC_Get_Line_Coding 	;A00A5 ;Call subroutine
         RJMP      PC+0x0003      ;Relative jump
;          			cdc_set_line_coding();
         CALL      CDC_Set_Line_Coding 	;A00DE     ;Call subroutine
         LDI       R24,0x01       ;Load immediate
         RET                      ;Subroutine return
;          			cdc_set_control_line_state();
         CALL      CDC_Set_Control_Line_State	;A0136     ;Call subroutine
         LDI       R24,0x01       ;Load immediate
;          }
         RET                      ;Subroutine return
USB_User_Endpoint_Init:
;          {
         PUSH      R15            ;Push register on stack
         PUSH      R16            ;Push register on stack
         PUSH      R17            ;Push register on stack
;            usb_configure_endpoint(INT_EP,      \
         LDI       R16,UENUM       ;Load immediate 0xE9 UENUM= - - - - - EPNUM2 EPNUM1=2 EPNUM0=1
         LDI       R17,0x00       ;Load immediate 
         LDI       R24,0x03       ;Load immediate 0x03
         MOVW      R30,R16        ;Copy register pair r16:r17=>R30,R31=Zl:ZH =0x00E9
         STD       Z+0,R24        ;Store indirect with displacement 0x03@0x00E9
         LDI       R24,0xC1       ;Load immediate
         LDI       R22,0x20       ;Load immediate
         CALL      USB_Config_Ep  ;Call subroutine A0246
;            usb_configure_endpoint(TX_EP,      \
         LDI       R24,0x01       ;Load immediate
         MOVW      R30,R16        ;Copy register pair
         STD       Z+0,R24        ;Store indirect with displacement
         LDI       R24,0x81       ;Load immediate
         LDI       R22,0x20       ;Load immediate
         CALL      USB_Config_Ep  ;Call subroutine A0246
;            usb_configure_endpoint(RX_EP,      \
         LDI       R18,0x02       ;Load immediate
         MOV       R15,R18        ;Copy register
         MOVW      R30,R16        ;Copy register pair
         STD       Z+0,R15        ;Store indirect with displacement
         LDI       R24,0x80       ;Load immediate
         LDI       R22,0x20       ;Load immediate
         CALL      USB_Config_Ep  ;Call subroutine A0246
;            Usb_reset_endpoint(INT_EP);
         LDI       R30,0xEA       ;Load immediate
         LDI       R31,0x00       ;Load immediate
         LDI       R24,0x08       ;Load immediate
         STD       Z+0,R24        ;Store indirect with displacement
         STD       Z+0,R1         ;Store indirect with displacement
;            Usb_reset_endpoint(TX_EP);
         STD       Z+0,R15        ;Store indirect with displacement
         STD       Z+0,R1         ;Store indirect with displacement
;            Usb_reset_endpoint(RX_EP);
         LDI       R24,0x04       ;Load immediate
         STD       Z+0,R24        ;Store indirect with displacement
         STD       Z+0,R1         ;Store indirect with displacement
;          }
         POP       R17            ;Pop register from stack
         POP       R16            ;Pop register from stack
         POP       R15            ;Pop register from stack
         RET                      ;Subroutine return

SOF_Action:
;---- C:\Atmel\at90usb162-cdc-1_0_1\at90usb162\demo\cdc\cdc_task.c ---------------------------------
;          {
         LDS       R24,0x0180     ;Load direct from data space
         SUBI      R24,0xFF       ;Subtract immediate
         STS       0x0180,R24     ;Store direct to data space
;          }
         RET                      ;Subroutine return

CDC_Task:
;          {
         PUSH      R17            ;Push register on stack
;             if(Is_device_enumerated()) //Enumeration processs OK ?
         LDS       R24,0x0184     ;Load direct from data space
         TST       R24            ;Test for Zero or Minus
         BRNE      PC+0x02        ;Branch if not equal
         RJMP      PC+0x005D      ;Relative jump
;                if(cpt_sof>=NB_MS_BEFORE_FLUSH && tx_counter!=0 )  //Flush buffer in Timeout
         LDS       R24,0x0180     ;Load direct from data space
         CPI       R24,0x32       ;Compare with immediate
         BRCS      PC+0x09        ;Branch if carry set
         LDS       R24,0x0188     ;Load direct from data space
         TST       R24            ;Test for Zero or Minus
         BREQ      PC+0x05        ;Branch if equal
;             	   cpt_sof=0;
         STS       0x0180,R1      ;Store direct to data space
;          		   uart_usb_flush();
         CALL      Usb_Select_Endpoint ;Call subroutine A0669 
;          	   if (uart_test_hit())    //Something on USART ?
         CALL      Uart_Test_Hit  ;Call subroutine A05D1
         TST       R24            ;Test for Zero or Minus
         BREQ      PC+0x0C        ;Branch if equal
;            		   uart_usb_putchar(uart_getchar());   // Loop back, USART to USB
         CALL      Uart_GetChar   ;Call subroutine A05F3
         CLR       R25            ;Clear Register
         SBRC      R24,7          ;Skip if bit in register cleared
         COM       R25            ;One's complement
         CALL      Uart_Usb_PutChar ;Call subroutine A0648 
;                   Led0_toggle();
         IN        R24,0x0B       ;In from I/O location
         LDI       R25,0x01       ;Load immediate
         EOR       R24,R25        ;Exclusive OR
         OUT       0x0B,R24       ;Out to I/O location
;                if (Uart_tx_ready())    //USART free ?
         LDS       R24,0x00C8     ;Load direct from data space
         SBRS      R24,5          ;Skip if bit in register set
         RJMP      PC+0x0016      ;Relative jump
;                   if (uart_usb_test_hit())   // Something received from the USB ?
         CALL      Uart_USB_Test_Hit ;Call subroutine A05FF     
         TST       R24            ;Test for Zero or Minus
         BRNE      PC+0x0D        ;Branch if not equal
         RJMP      PC+0x0011      ;Relative jump
;          			      uart_putchar(uart_usb_getchar());   // loop back USB to USART
         CALL      Uart_USB_GetChar  ;Call subroutine A061F
         CLR       R25            ;Clear Register
         SBRC      R24,7          ;Skip if bit in register cleared
         COM       R25            ;One's complement
         CALL      Uart_PutChar   ;Call subroutine A05EA
;                         Led3_toggle();
         IN        R24,0x0B       ;In from I/O location
         EOR       R24,R17        ;Exclusive OR
         OUT       0x0B,R24       ;Out to I/O location
         RJMP      PC+0x0002      ;Relative jump
         LDI       R17,0x20       ;Load immediate
;          	 	      while (rx_counter)
         LDS       R24,0x0189     ;Load direct from data space
         TST       R24            ;Test for Zero or Minus
         BRNE      PC-0x0F        ;Branch if not equal
;                if ( cpt_sof>=REPEAT_KEY_PRESSED)   //Debounce joystick events
         LDS       R24,0x0180     ;Load direct from data space
         CPI       R24,0x64       ;Compare with immediate
         BRCS      PC+0x25        ;Branch if carry set
;                   if (Is_joy_select())
         SBIC      0x03,0         ;Skip if bit in I/O register cleared
         RJMP      PC+0x0005      ;Relative jump
;                   printf ("Select Pressed !\r\n");
         LDI       R24,0x00       ;Load immediate
         LDI       R25,0x01       ;Load immediate
         CALL      Print_F        ;Call subroutine A06E2
;                   if (Is_joy_right())
         SBIC      0x03,6         ;Skip if bit in I/O register cleared
         RJMP      PC+0x0005      ;Relative jump
;                   printf ("Right Pressed !\r\n");
         LDI       R24,0x12       ;Load immediate
         LDI       R25,0x01       ;Load immediate
         CALL      Print_F        ;Call subroutine A06E2
;                   if (Is_joy_left())
         SBIC      0x03,4         ;Skip if bit in I/O register cleared
         RJMP      PC+0x0005      ;Relative jump
;                   printf ("Left Pressed !\r\n");
         LDI       R24,0x23       ;Load immediate
         LDI       R25,0x01       ;Load immediate
         CALL      Print_F        ;Call subroutine A06E2
;                   if (Is_joy_down())
         SBIC      0x03,7         ;Skip if bit in I/O register cleared
         RJMP      PC+0x0005      ;Relative jump
;                   printf ("Down Pressed !\r\n");
         LDI       R24,0x33       ;Load immediate
         LDI       R25,0x01       ;Load immediate
         CALL      Print_F        ;Call subroutine A06E2
;                   if (Is_joy_up())
         SBIC      0x03,5         ;Skip if bit in I/O register cleared
         RJMP      PC+0x0005      ;Relative jump
;                   printf ("Up Pressed !\r\n");
         LDI       R24,0x43       ;Load immediate
         LDI       R25,0x01       ;Load immediate
         CALL      Print_F        ;Call subroutine A06E2
;                   if(Is_hwb())
         SBIC      0x09,7         ;Skip if bit in I/O register cleared
         RJMP      PC+0x0005      ;Relative jump
;                   printf("Hello from AT90USBXXX !\r\n");
         LDI       R24,0x51       ;Load immediate
         LDI       R25,0x01       ;Load immediate
         CALL      Print_F        ;Call subroutine A06E2

         POP       R17            ;Pop register from stack
         RET                      ;Subroutine return

CDC_Task_Init:
;             uart_init();
         CALL      Uart_Init      ;Initize UART
;             Leds_init(); 
         ;Data Direction PD0-PD7
		 IN        R24,DDRD       ;In from I/O location 0x0A=DDRD 
         ORI       R24,0x33       ;Logical OR with immediate 00110011= DDD7=0 DDD6=0 DDD5=0 DDD4 DDD3 DDD2 DDD1 DDD0
         OUT       DDRD,R24       ;Out to I/O location 0x0A=DDRD  
         
		 IN        R24,PORTD       ;In from I/O location 0x0B=PORTD7 PORTD6=0 PORTD5 PORTD4 PORTD3 PORTD2=0 PORTD1 PORTD0
         ANDI      R24,0xCC       ;Logical AND with immediate 1011 1011 PORTD6 & PORTD2 are set to INput 
         OUT       PORTD,R24       ;Out to I/O location0x0B 
;             Joy_init();
         IN        R24,DDRB       ;In from I/O location 0x04 DDRB=DDB7 DDB6 DDB5 DDB4 DDB3 DDB2 DDB1 DDB0
         ANDI      R24,0x0E       ;Logical AND with immediate 0000 1110
         OUT       DDRB,R24       ;Out to I/O location
         ;Set PortB
		 IN        R24,PORTB      ;In from I/O location PORTB 0x05
         ORI       R24,0xF1       ;Logical OR with immediate 1111 0001 
         OUT       PORTB,R24       ;Out to I/O location
;             Hwb_button_init();
         CBI       DDRD,7         ;Clear bit in I/O register 0x0A DDRD=DDD7=0 DDD6 DDD5 DDD4 DDD3 DDD2 DDD1 DDD0
;             Usb_enable_sof_interrupt();
         LDI       R30,UDIEN      ;Load immediate ZL =E2
         LDI       R31,0x00       ;Load immediate ZH =00
         LDD       R24,Z+0        ;Load indirect 00E2 UDIEN= - UPRSME EORSME WAKEUPE EORSTE SOFE - SUSPE with displacement
         ORI       R24,0x04       ;Logical OR with immediate 0000 0100 UDIEN= - UPRSME EORSME WAKEUPE EORSTE SOFE=1 - SUSPE
         STD       Z+0,R24        ;Store indirect with displacement
;           	fdevopen(uart_usb_putchar,uart_usb_getchar); //for printf redirection 
         LDI       R24,0x48       ;Load immediate
         LDI       R25,0x06       ;Load immediate
         LDI       R22,0x1F       ;Load immediate
         LDI       R23,0x06       ;Load immediate
         CALL      SubA0696   	  ;Call subroutine A0696  
;          }
         RET                      ;Subroutine return
     
Main:    
         ;disable 3.3V regulator control register
		 LDI       R30,REGCR      ;Load immediate ZL=0x63
         LDI       R31,0x00       ;Load immediate ZH=0x00
         LDD       R24,Z+0        ;Load 0x0063 indirect with displacement
         ANDI      R24,0xFE       ;Logical AND with immediate FE=1111 1110
         STD       Z+0,R24        ;Store indirect with displacement  REGCR - - - - - - - REGDIS
;             wdt_reset();
         WDR                      ;Watchdog reset
;             Wdt_clear_flag()=>MCU Status Register
         LDI       R24,0xF7       ;Load immediate 11110111
         OUT       MCUSR,R24       ;Out to I/O location 0x34= - - USBRF - WDRF BORF EXTRF PORF 
;             Wdt_change_enable();
         LDI       R30,WDTCSR     ;Load immediate ZL=0x60
         LDI       R31,0x00       ;Load immediate ZH=0x00 0060
         LDD       R24,Z+0        ;Load R24 with WDTCSR(0x60)= WDIF WDIE WDP3 WDCE WDE WDP2 WDP1 WDP0
         ORI       R24,0x18       ;Logical OR with immediate 18 00011000 
         STD       Z+0,R24        ;Store 0x18 indirect with displacement WDTCSR(0x60)
;             Wdt_stop();
         STD       Z+0,R1         ;Store indirect with displacement
;             Clear_Clock Prescaler();CLKPR(0x61)=CLKPCE - - - CLKPS3 CLKPS2 CLKPS1 CLKPS0
         LDI       R30,CLKPR       ;Load immediate ZL=0x61
         LDI       R31,0x00       ;Load immediate ZH=0x00
         LDI       R24,0x80       ;Load immediate R24=10000000
         STD       Z+0,R24        ;Store indirect with displacement CLKPR
         STD       Z+0,R1         ;Store indirect with displacement CLKPR
;             scheduler();
         CALL      Scheduler      ;
;          }
         LDI       R24,0x00       ;Load immediate
         LDI       R25,0x00       ;Load immediate
         RET                      ;Subroutine return

Set_Power_Down_Mode: ;SMCR=Sleep Mode Control Register
         OUT       SMCR,R1        ;Out to I/O location (0x53) 0x33 SMCR= - - - - SM2 SM1 SM0 SE
         IN        R24,SMCR       ;In from I/O location 0x33 
         ORI       R24,0x05       ;Logical OR with immediate ORI 05(Power Down)  0000 0101  - - - - SM2=0 SM1=1 SM0=0 SE=1
         OUT       SMCR ,R24      ;Out to I/O location 0x33
         SLEEP                    ;Sleep
         RET                      ;Subroutine return

Set_Idle_Mode:;Setup_idle_mode();
         OUT       0x33,R1        ;Out to I/O location
         IN        R24,SMCR       ;In from I/O location 0x33 
         ORI       R24,0x01       ;Logical OR with immediate 0000 0001
         OUT       SMCR,R24       ;Out to I/O location 0x33
         SLEEP                    ;Sleep
         RET                      ;Subroutine return

Set_Adc_Noise_Reduction_Mode:;Setup_adc_noise_reduction_mode();
         OUT       SMCR,R1        ;Out to I/O location 0x33
         IN        R24,SMCR       ;In from I/O location 0x33
         ORI       R24,0x03       ;Logical OR with immediate
         OUT       SMCR,R24       ;Out to I/O location 0x33
         SLEEP                    ;Sleep
         RET                      ;Subroutine return

Set_Power_Save_Mode:;Setup_power_save_mode();
         OUT       SMCR,R1        ;Out to I/O location 0x33
         IN        R24,SMCR      ;In from I/O location 0x33 
         ORI       R24,0x07       ;Logical OR with immediate
         OUT       SMCR,R24       ;Out to I/O location 0x33
         SLEEP                    ;Sleep
         RET                      ;Subroutine return

Set_Standby_Mode:;Setup_standby_mode();
         OUT       SMCR,R1        ;Out to I/O location 0x33
         IN        R24,SMCR       ;In from I/O location 0x33 
         ORI       R24,0x0D       ;Logical OR with immediate
         OUT       SMCR,R24       ;Out to I/O location 0x33
         SLEEP                    ;Sleep
         RET                      ;Subroutine return

Set_Ext_Standby_Mode: ;Setup_ext_standby_mode();
         OUT       SMCR,R1        ;Out to I/O location 0x33
         IN        R24,SMCR       ;In from I/O location 0x33
         ORI       R24,0x0F       ;Logical OR with immediate
         OUT       SMCR,R24       ;Out to I/O location 0x33 
         SLEEP                    ;Sleep
         RET                      ;Subroutine return

USB_Config_Ep:
         LDS       R25,UECONX     ;Load direct from data space 0x00EB UECONX= - - STALLRQ STALLRQC RSTDT - - EPEN
         ORI       R25,0x01       ;Logical OR with immediate 00000001
         STS       UECONX,R25     ;Store direct to data space UECONX 0x00EB= - - STALLRQ=0 STALLRQC=0 RSTDT=0 - - EPEN=1
;              UECFG0X = config0;
         STS       UECFG0X,R24     ;Store direct to data space 0x00EC UECFG0X EPTYPE1:0 - - - - - EPDIR
;              UECFG1X = (UECFG1X & (1<<ALLOC)) | config1;
         LDS       R24,UECFG1X     ;Load direct from data space 0x00ED UECFG1X= - EPSIZE2=0  EPSIZE1=0 EPSIZE0=0 EPBK1=0 EPBK0=0 ALLOC=1 -=0
         ANDI      R24,0x02       ;Logical AND with immediate 0000 0010
         OR        R24,R22        ;Logical OR
         STS       UECFG1X,R24     ;Store direct to data space
;              Usb_allocate_memory();
         LDS       R24,UECFG1X     ;Load direct from data space 0x00ED UECFG1X= - EPSIZE2=0  EPSIZE1=0 EPSIZE0=0 EPBK1=0 EPBK0=0 ALLOC=1 -=0
         ORI       R24,0x02       ;Logical OR with immediate 0000 0010
         STS       UECFG1X,R24     ;Store direct to data space 
;              return (Is_endpoint_configured());
         LDS       R24,UESTA0X    ;Load direct from data space 0x00EE UESTA0X=CFGOK OVERFI UNDERFI - DTSEQ1:0 NBUSYBK1:0
         ROL       R24            ;Rotate Left Through Carry
         CLR       R24            ;Clear Register
         ROL       R24            ;Rotate Left Through Carry
         RET                      ;Subroutine return

USB_Select_Enpoint_Interrupt:
;             interrupt_flags = Usb_interrupt_flags();
         LDS       R25,0x00F4     ;Load direct from data space
         LDI       R24,0x00       ;Load immediate
;                if (interrupt_flags & 1)
         SBRC      R25,0          ;Skip if bit in register cleared
         RJMP      PC+0x0007      ;Relative jump
;                   ep_num++;
         SUBI      R24,0xFF       ;Subtract immediate
;             while(ep_num < MAX_EP_NB)
         CPI       R24,0x07       ;Compare with immediate
         BREQ      PC+0x03        ;Branch if equal
;                   interrupt_flags = interrupt_flags >> 1;
         LSR       R25            ;Logical shift right
         RJMP      PC-0x0006      ;Relative jump
         LDI       R24,0x00       ;Load immediate
;          }
         RET                      ;Subroutine return

USB_Send_Packet:
;         {
         MOVW      R30,R22        ;Copy register pair
;            Usb_select_endpoint(ep_num);
         STS       0x00E9,R24     ;Store direct to data space
         RJMP      PC+0x0005      ;Relative jump
;                Usb_write_byte(*tbuf);
         LD        R24,Z+         ;Load indirect and postincrement
         STS       0x00F1,R24     ;Store direct to data space
;                remaining_length--;
         SUBI      R20,0x01       ;Subtract immediate
;             while(Is_usb_write_enabled() && (0 != remaining_length))
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,5          ;Skip if bit in register set
         RJMP      PC+0x0003      ;Relative jump
         TST       R20            ;Test for Zero or Minus
         BRNE      PC-0x09        ;Branch if not equal
;          }
         MOV       R24,R20        ;Copy register
         RET                      ;Subroutine return

USB_Read_Packet:
;          {
         MOVW      R30,R22        ;Copy register pair
;             Usb_select_endpoint(ep_num);
         STS       0x00E9,R24     ;Store direct to data space
         RJMP      PC+0x0005      ;Relative jump
;                *rbuf = Usb_read_byte();
         LDS       R24,0x00F1     ;Load direct from data space
         ST        Z+,R24         ;Store indirect and postincrement
;                remaining_length--;
         SUBI      R20,0x01       ;Subtract immediate
;             while(Is_usb_read_enabled() && (0 != remaining_length))
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,5          ;Skip if bit in register set
         RJMP      PC+0x0003      ;Relative jump
         TST       R20            ;Test for Zero or Minus
         BRNE      PC-0x09        ;Branch if not equal
;          }
         MOV       R24,R20        ;Copy register
         RET                      ;Subroutine return

USB_Halt_Endpoint:
;             Usb_select_endpoint(ep_num);
         STS       0x00E9,R24     ;Store direct to data space
;             Usb_enable_stall_handshake();
         LDI       R30,0xEB       ;Load immediate
         LDI       R31,0x00       ;Load immediate
         LDD       R24,Z+0        ;Load indirect with displacement
         ORI       R24,0x20       ;Logical OR with immediate
         STD       Z+0,R24        ;Store indirect with displacement
;          }
         RET                      ;Subroutine return

USB_Init_Device:
;                Usb_select_endpoint(EP_CONTROL);
         STS       UENUM,R1       ;Store direct to UENUM 0x00E9= - - - - - EPNUM2:0data space
;                if(!Is_usb_endpoint_enabled())
         LDS       R24,UECONX     ;Load direct from data space 0x00EB  UECONX= - - STALLRQ STALLRQC RSTDT - - EPEN
         SBRS      R24,0          ;Skip if EPEN bit in register set 
         RJMP      PC+0x0003      ;Relative jump
         LDI       R24,0x00       ;Load immediate
         RET                      ;Subroutine return
;                   return usb_configure_endpoint(EP_CONTROL,    \
         STS       UENUM,R1       ;Store direct to data space 0x00E9 UENUM - - - - - EPNUM2:0
         LDI       R24,0x02       ;Load immediate
         LDI       R22,0x20       ;Load immediate
         CALL      USB_Config_Ep  ;Call subroutine A0246
;          }
         RET                      ;Subroutine return

 __Vector_11:
         PUSH      R1             ;Push register on stack
         PUSH      R0             ;Push register on stack
         IN        R0,0x3F        ;In from I/O location
         PUSH      R0             ;Push register on stack
         CLR       R1             ;Clear Register
         PUSH      R18            ;Push register on stack
         PUSH      R19            ;Push register on stack
         PUSH      R20            ;Push register on stack
         PUSH      R21            ;Push register on stack
         PUSH      R22            ;Push register on stack
         PUSH      R23            ;Push register on stack
         PUSH      R24            ;Push register on stack
         PUSH      R25            ;Push register on stack
         PUSH      R26            ;Push register on stack
         PUSH      R27            ;Push register on stack
         PUSH      R30            ;Push register on stack
         PUSH      R31            ;Push register on stack
;             if (Is_usb_sof() && Is_sof_interrupt_enabled())
         LDS       R24,0x00E1     ;Load direct from data space
         SBRS      R24,2          ;Skip if bit in register set
         RJMP      PC+0x000A      ;Relative jump
         LDS       R24,0x00E2     ;Load direct from data space
         SBRS      R24,2          ;Skip if bit in register set
         RJMP      PC+0x0006      ;Relative jump
;                Usb_ack_sof();
         LDI       R24,0xFB       ;Load immediate
         STS       0x00E1,R24     ;Store direct to data space
;                Usb_sof_action();
         CALL      SOF_Action      ;A0185 Call subroutine
;             if (Is_usb_suspend() && Is_suspend_interrupt_enabled())
         LDS       R24,0x00E1     ;Load direct from data space
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC+0x001E      ;Relative jump
         LDS       R24,0x00E2     ;Load direct from data space
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC+0x001A      ;Relative jump
;                Usb_enable_wake_up_interrupt();
         LDS       R24,0x00E2     ;Load direct from data space
         ORI       R24,0x10       ;Logical OR with immediate
         STS       0x00E2,R24     ;Store direct to data space
;                Usb_ack_wake_up();                 // clear wake up to detect next event
         LDI       R24,0xEF       ;Load immediate
         STS       0x00E1,R24     ;Store direct to data space
;                Usb_freeze_clock();
         LDS       R24,0x00D8     ;Load direct from data space
         ORI       R24,0x20       ;Logical OR with immediate
         STS       0x00D8,R24     ;Store direct to data space
;                Usb_send_event(EVT_USB_SUSPEND);
         LDS       R24,0x0170     ;Load direct from data space
         LDS       R25,0x0171     ;Load direct from data space
         ORI       R24,0x20       ;Logical OR with immediate
         STS       0x0171,R25     ;Store direct to data space
         STS       0x0170,R24     ;Store direct to data space
;                Usb_ack_suspend();  // must be executed last (after Usb_suspend_action()) to allow upstream resume
         LDI       R24,0xFE       ;Load immediate
         STS       0x00E1,R24     ;Store direct to data space
;    :         if (Is_usb_wake_up() && Is_swake_up_interrupt_enabled())
         LDS       R24,0x00E1     ;Load direct from data space
         SBRS      R24,4          ;Skip if bit in register set
         RJMP      PC+0x001B      ;Relative jump
         LDS       R24,0x00E2     ;Load direct from data space
         SBRS      R24,4          ;Skip if bit in register set
         RJMP      PC+0x0017      ;Relative jump
;                Usb_unfreeze_clock();
         LDS       R24,0x00D8     ;Load direct from data space
         ANDI      R24,0xDF       ;Logical AND with immediate
         STS       0x00D8,R24     ;Store direct to data space
;                Usb_ack_wake_up();
         LDI       R24,0xEF       ;Load immediate
         STS       0x00E1,R24     ;Store direct to data space
;                Usb_disable_wake_up_interrupt();
         LDS       R24,0x00E2     ;Load direct from data space
         ANDI      R24,0xEF       ;Logical AND with immediate
         STS       0x00E2,R24     ;Store direct to data space
;                Usb_send_event(EVT_USB_WAKE_UP);
         LDS       R24,0x0170     ;Load direct from data space
         LDS       R25,0x0171     ;Load direct from data space
         ORI       R24,0x40       ;Logical OR with immediate
         STS       0x0171,R25     ;Store direct to data space
         STS       0x0170,R24     ;Store direct to data space
;             if (Is_usb_resume() && Is_resume_interrupt_enabled())
         LDS       R24,0x00E1     ;Load direct from data space
         SBRS      R24,5          ;Skip if bit in register set
         RJMP      PC+0x001B      ;Relative jump
         LDS       R24,0x00E2     ;Load direct from data space
         SBRS      R24,5          ;Skip if bit in register set
         RJMP      PC+0x0017      ;Relative jump
;                Usb_disable_wake_up_interrupt();
         LDS       R24,0x00E2     ;Load direct from data space
         ANDI      R24,0xEF       ;Logical AND with immediate
         STS       0x00E2,R24     ;Store direct to data space
;                Usb_ack_resume();
         LDI       R24,0xDF       ;Load immediate
         STS       0x00E1,R24     ;Store direct to data space
;                Usb_disable_resume_interrupt();
         LDS       R24,0x00E2     ;Load direct from data space
         ANDI      R24,0xDF       ;Logical AND with immediate
         STS       0x00E2,R24     ;Store direct to data space
;                Usb_send_event(EVT_USB_RESUME);
         LDS       R24,0x0170     ;Load direct from data space
         LDS       R25,0x0171     ;Load direct from data space
         ORI       R24,0x80       ;Logical OR with immediate
         STS       0x0171,R25     ;Store direct to data space
         STS       0x0170,R24     ;Store direct to data space
;             if (Is_usb_reset()&& Is_reset_interrupt_enabled())
         LDS       R24,0x00E1     ;Load direct from data space
         SBRS      R24,3          ;Skip if bit in register set
         RJMP      PC+0x0013      ;Relative jump
         LDS       R24,0x00E2     ;Load direct from data space
         SBRS      R24,3          ;Skip if bit in register set
         RJMP      PC+0x000F      ;Relative jump
;                Usb_ack_reset();
         LDI       R24,0xF7       ;Load immediate
         STS       0x00E1,R24     ;Store direct to data space
;                usb_init_device();
         CALL      USB_Init_Device;Call subroutine A0292
;                Usb_send_event(EVT_USB_RESET);
         LDS       R24,0x0170     ;Load direct from data space
         LDS       R25,0x0171     ;Load direct from data space
         ORI       R25,0x01       ;Logical OR with immediate
         STS       0x0171,R25     ;Store direct to data space
         STS       0x0170,R24     ;Store direct to data space
;          }
         POP       R31            ;Pop register from stack
         POP       R30            ;Pop register from stack
         POP       R27            ;Pop register from stack
         POP       R26            ;Pop register from stack
         POP       R25            ;Pop register from stack
         POP       R24            ;Pop register from stack
         POP       R23            ;Pop register from stack
         POP       R22            ;Pop register from stack
         POP       R21            ;Pop register from stack
         POP       R20            ;Pop register from stack
         POP       R19            ;Pop register from stack
         POP       R18            ;Pop register from stack
         POP       R0             ;Pop register from stack
         OUT       0x3F,R0        ;Out to I/O location
         POP       R0             ;Pop register from stack
         POP       R1             ;Pop register from stack
         RETI                     ;Interrupt return

USB_Task:;             usb_device_task();
         CALL      USB_Device_Task;Call subroutine
         RET                      ;Subroutine return

USB_Task_Init:;        usb_device_task_init();
         CALL      USB_Device_Task_Init ;Call subroutine A0564 
         RET                      ;Subroutine return

USB_Process_Request:
         PUSH      R29            ;Push register on stack
         PUSH      R28            ;Push register on stack
         RCALL     PC+0x0001      ;Relative call subroutine
         IN        R28,0x3D       ;In from I/O location SPL=SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0 
         IN        R29,0x3E       ;In from I/O location SPH=SP15 SP14 SP13 SP12 SP11 SP10 SP9 SP8
;             UEINTX &= ~(1<<RXOUTI);
         LDS       R24,UEINTX     ;Load direct from data space 0x00E8 UEINTX=FIFOCON=1 NAKINI=1 RWAL NAKOUTI RXSTPI RXOUTI=0 STALLEDI TXINI
         ANDI      R24,0xFB       ;Logical AND with immediate 1111 1011
         STS       UEINTX,R24     ;Store direct to data space 0x00E8
;             bmRequestType = Usb_read_byte();
         LDS       R25,UEDATX     ;Load direct from data space 0x00F1 UEDATX= DAT7:0
         STS       0x0177,R25     ;Store direct to data space 0177
;             bmRequest     = Usb_read_byte();
         LDS       R22,UEDATX     ;Load direct from data spac0x00F1 UEDATX= DAT7:0e 
;             switch (bmRequest)
         CPI       R22,0x06       ;Compare with immediate
         BREQ      PC+0x20        ;Branch if equal
         
		 CPI       R22,0x07       ;Compare with immediate
         BRCC      PC+0x0E        ;Branch if carry cleared
         
		 CPI       R22,0x01       ;Compare with immediate
         BRNE      PC+0x02        ;Branch if not equal
         RJMP      PC+0x011D      ;Relative jump
         
		 CPI       R22,0x01       ;Compare with immediate
         BRCC      PC+0x02        ;Branch if carry cleared
         RJMP      PC+0x018A      ;Relative jump
         
		 CPI       R22,0x03       ;Compare with immediate
         BRNE      PC+0x02        ;Branch if not equal
         RJMP      PC+0x0150      ;Relative jump
         
		 CPI       R22,0x05       ;Compare with immediate
         BREQ      PC+0x02        ;Branch if equal
         RJMP      PC+0x01E8      ;Relative jump
         RJMP      PC+0x00D7      ;Relative jump
         
		 CPI       R22,0x09       ;Compare with immediate
         BRNE      PC+0x02        ;Branch if not equal
         RJMP      PC+0x00F6      ;Relative jump
         
		 CPI       R22,0x0A       ;Compare with immediate
         BRCC      PC+0x05        ;Branch if carry cleared
         
		 CPI       R22,0x08       ;Compare with immediate
         BREQ      PC+0x02        ;Branch if equal
         RJMP      PC+0x01DF      ;Relative jump
         RJMP      PC+0x00B1      ;Relative jump
         
		 CPI       R22,0x0A       ;Compare with immediate
         BRNE      PC+0x02        ;Branch if not equal
         RJMP      PC+0x01AC      ;Relative jump
         
		 CPI       R22,0x0B       ;Compare with immediate
         BREQ      PC+0x02        ;Branch if equal
         RJMP      PC+0x01D8      ;Relative jump
         RJMP      PC+0x01C6      ;Relative jump
;                   if (0x80 == bmRequestType) { usb_get_descriptor(); }
         CPI       R25,0x80       ;Compare with immediate
         BREQ      PC+0x02        ;Branch if equal
         RJMP      PC+0x00A4      ;Relative jump
;             zlp             = FALSE;                  /* no zero length packet */
         STS       0x0172,R1      ;Store direct to data space
;             string_type     = Usb_read_byte();        /* read LSB of wValue    */
         LDS       R22,0x00F1     ;Load direct from data space
;             descriptor_type = Usb_read_byte();        /* read MSB of wValue    */
         LDS       R24,0x00F1     ;Load direct from data space
;             switch (descriptor_type)
         CPI       R24,0x01       ;Compare with immediate
         BREQ      PC+0x04        ;Branch if equal
         CPI       R24,0x02       ;Compare with immediate
         BRNE      PC+0x12        ;Branch if not equal
         RJMP      PC+0x0007      ;Relative jump
;                data_to_transfer = Usb_get_dev_desc_length(); //!< sizeof (usb_user_device_descriptor);
         LDI       R24,0x12       ;Load immediate
         STS       0x0185,R24     ;Store direct to data space
;                pbuffer          = Usb_get_dev_desc_pointer();
         LDI       R24,0x74       ;Load immediate
         LDI       R25,0x00       ;Load immediate
         RJMP      PC+0x0006      ;Relative jump
;                data_to_transfer = Usb_get_conf_desc_length(); //!< sizeof (usb_user_configuration_descriptor);
         LDI       R24,0x43       ;Load immediate
         STS       0x0185,R24     ;Store direct to data space
;                pbuffer          = Usb_get_conf_desc_pointer();
         LDI       R24,0x86       ;Load immediate
         LDI       R25,0x00       ;Load immediate
         STS       0x0187,R25     ;Store direct to data space
         STS       0x0186,R24     ;Store direct to data space
         RJMP      PC+0x0006      ;Relative jump
;                if( usb_user_get_descriptor(descriptor_type, string_type)==FALSE )
         CALL      USB_User_Get_Descriptor ;Call subroutine A00A3
         TST       R24            ;Test for Zero or Minus
         BRNE      PC+0x02        ;Branch if not equal
         RJMP      PC+0x01B9      ;Relative jump
;             dummy = Usb_read_byte();                     //!< don't care of wIndex field
         LDS       R24,0x00F1     ;Load direct from data space
;             dummy = Usb_read_byte();
         LDS       R24,0x00F1     ;Load direct from data space
;             LSB(wLength) = Usb_read_byte();              //!< read wLength
         LDS       R24,0x00F1     ;Load direct from data space
         STD       Y+1,R24        ;Store indirect with displacement
;             MSB(wLength) = Usb_read_byte();
         LDS       R24,0x00F1     ;Load direct from data space
         STD       Y+2,R24        ;Store indirect with displacement
;             Usb_ack_receive_setup() ;                  //!< clear the receive setup flag
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             if (wLength > data_to_transfer)
         LDD       R18,Y+1        ;Load indirect with displacement
         LDD       R19,Y+2        ;Load indirect with displacement
         LDS       R24,0x0185     ;Load direct from data space
         LDI       R25,0x00       ;Load immediate
         CP        R24,R18        ;Compare
         CPC       R25,R19        ;Compare with carry
         BRCC      PC+0x0C        ;Branch if carry cleared
;                if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; }
         ANDI      R24,0x1F       ;Logical AND with immediate
         ANDI      R25,0x00       ;Logical AND with immediate
         OR        R24,R25        ;Logical OR
         BRNE      PC+0x05        ;Branch if not equal
         LDI       R24,0x01       ;Load immediate
         STS       0x0172,R24     ;Store direct to data space
         RJMP      PC+0x0006      ;Relative jump
;                else { zlp = FALSE; }                   //!< no need of zero length packet
         STS       0x0172,R1      ;Store direct to data space
         RJMP      PC+0x0003      ;Relative jump
;                data_to_transfer = (U8)wLength;         //!< send only requested number of data
         STS       0x0185,R18     ;Store direct to data space
;             Usb_ack_nak_out();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xEF       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
         LDS       R18,0x0186     ;Load direct from data space
         LDS       R19,0x0187     ;Load direct from data space
         LDS       R20,0x0185     ;Load direct from data space
         RJMP      PC+0x0023      ;Relative jump
;                  if (Is_usb_nak_out_sent())
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,4          ;Skip if bit in register set
         RJMP      PC+0x0004      ;Relative jump
         MOVW      R30,R18        ;Copy register pair
         LDI       R25,0x00       ;Load immediate
         RJMP      PC+0x0010      ;Relative jump
;                while(!Is_usb_read_control_enabled())
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC-0x000A      ;Relative jump
         RJMP      PC-0x0007      ;Relative jump
         MOV       R21,R20        ;Copy register
         SUBI      R21,0x01       ;Subtract immediate
;                   if(nb_byte++==EP_CONTROL_LENGTH) //!< Check endpoint 0 size
         CPI       R25,0x20       ;Compare with immediate
         BREQ      PC+0x0A        ;Branch if equal
         SUBI      R25,0xFF       ;Subtract immediate
;                   Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++));
         LPM       R24,Z          ;Load program memory
         STS       0x00F1,R24     ;Store direct to data space
         ADIW      R30,0x01       ;Add immediate to word
         MOV       R20,R21        ;Copy register
         MOVW      R18,R30        ;Copy register pair
;                while(data_to_transfer != 0)        //!< Send data until necessary
         TST       R20            ;Test for Zero or Minus
         BRNE      PC-0x0C        ;Branch if not equal
;                if (Is_usb_nak_out_sent())
         LDS       R24,0x00E8     ;Load direct from data space
         SBRC      R24,4          ;Skip if bit in register cleared
         RJMP      PC+0x0013      ;Relative jump
;                  Usb_send_control_in();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFE       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             while((data_to_transfer != 0) && (!Is_usb_nak_out_sent()))
         TST       R20            ;Test for Zero or Minus
         BRNE      PC+0x08        ;Branch if not equal
         STS       0x0186,R18     ;Store direct to data space
         STS       0x0187,R19     ;Store direct to data space
         STS       0x0185,R1      ;Store direct to data space
         RJMP      PC+0x000B      ;Relative jump
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,4          ;Skip if bit in register set
         RJMP      PC-0x0027      ;Relative jump
         STS       0x0186,R18     ;Store direct to data space
         STS       0x0187,R19     ;Store direct to data space
         STS       0x0185,R20     ;Store direct to data space
;             if((zlp == TRUE) && (!Is_usb_nak_out_sent()))
         LDS       R24,0x0172     ;Load direct from data space
         CPI       R24,0x01       ;Compare with immediate
         BRNE      PC+0x0E        ;Branch if not equal
         LDS       R24,0x00E8     ;Load direct from data space
         SBRC      R24,4          ;Skip if bit in register cleared
         RJMP      PC+0x000A      ;Relative jump
;               while(!Is_usb_read_control_enabled());
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump
;               Usb_send_control_in();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFE       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             while (!(Is_usb_nak_out_sent()));
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,4          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump
;             Usb_ack_nak_out();       // clear NAKOUTI
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xEF       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             UEINTX &= ~(1<<RXOUTI);  // clear RXOUTI
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFB       ;Logical AND with immediate
         RJMP      PC+0x013E      ;Relative jump
;                   else                       { usb_user_read_request(bmRequestType, bmRequest); }
         MOV       R24,R25        ;Copy register
         LDI       R22,0x06       ;Load immediate
         RJMP      PC+0x011A      ;Relative jump
;                   if (0x80 == bmRequestType) { usb_get_configuration(); }
         CPI       R25,0x80       ;Compare with immediate
         BRNE      PC+0x19        ;Branch if not equal
;             Usb_ack_receive_setup();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             Usb_write_byte(usb_configuration_nb);
         LDS       R24,0x0184     ;Load direct from data space
         STS       0x00F1,R24     ;Store direct to data space
;             Usb_ack_in_ready();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFE       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0x7F       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             while( !Is_usb_receive_out() );
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,2          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump
         RJMP      PC+0x00F5      ;Relative jump
;                   else                       { usb_user_read_request(bmRequestType, bmRequest); }
         MOV       R24,R25        ;Copy register
         LDI       R22,0x08       ;Load immediate
         RJMP      PC+0x00FD      ;Relative jump
;                   if (0x00 == bmRequestType) { usb_set_address(); }
         TST       R25            ;Test for Zero or Minus
         BRNE      PC+0x1E        ;Branch if not equal
;             Usb_configure_address(Usb_read_byte());
         LDS       R25,0x00E3     ;Load direct from data space
         LDS       R24,0x00F1     ;Load direct from data space
         ANDI      R24,0x7F       ;Logical AND with immediate
         ANDI      R25,0x80       ;Logical AND with immediate
         OR        R24,R25        ;Logical OR
         STS       0x00E3,R24     ;Store direct to data space
;             Usb_ack_receive_setup();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             Usb_send_control_in();                    //!< send a ZLP for STATUS phase
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFE       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             while(!Is_usb_in_ready());                //!< waits for status phase done
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump
;             Usb_enable_address();
         LDS       R24,0x00E3     ;Load direct from data space
         ORI       R24,0x80       ;Logical OR with immediate
         STS       0x00E3,R24     ;Store direct to data space
         RJMP      PC+0x0101      ;Relative jump
;                   else                       { usb_user_read_request(bmRequestType, bmRequest); }
         MOV       R24,R25        ;Copy register
         LDI       R22,0x05       ;Load immediate
         RJMP      PC+0x00DB      ;Relative jump
;                   if (0x00 == bmRequestType) { usb_set_configuration(); }
         TST       R25            ;Test for Zero or Minus
         BRNE      PC+0x16        ;Branch if not equal
;             configuration_number = Usb_read_byte();
         LDS       R25,0x00F1     ;Load direct from data space
;             if (configuration_number <= NB_CONFIGURATION)
         CPI       R25,0x02       ;Compare with immediate
         BRCS      PC+0x02        ;Branch if carry set
         RJMP      PC+0x00ED      ;Relative jump
;                Usb_ack_receive_setup();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;                usb_configuration_nb = configuration_number;
         STS       0x0184,R25     ;Store direct to data space
;             Usb_send_control_in();                    //!< send a ZLP for STATUS phase
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFE       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             usb_user_endpoint_init(usb_configuration_nb);  //!< endpoint configuration
         MOV       R24,R25        ;Copy register
         CALL      USB_User_Endpoint_Init ;Call subroutine A015C
         RJMP      PC+0x00E7      ;Relative jump
;                   else                       { usb_user_read_request(bmRequestType, bmRequest); }
         MOV       R24,R25        ;Copy register
         LDI       R22,0x09       ;Load immediate
         RJMP      PC+0x00C1      ;Relative jump
;                   if (0x02 >= bmRequestType) { usb_clear_feature(); }
         CPI       R25,0x03       ;Compare with immediate
         BRCC      PC+0x35        ;Branch if carry cleared
;             if (bmRequestType == ZERO_TYPE)
         TST       R25            ;Test for Zero or Minus
         BREQ      PC+0x3A        ;Branch if equal
;             else if (bmRequestType == INTERFACE_TYPE)
         CPI       R25,0x01       ;Compare with immediate
         BRNE      PC+0x02        ;Branch if not equal
         RJMP      PC+0x00D3      ;Relative jump
;                wValue = Usb_read_byte();
         LDS       R24,0x00F1     ;Load direct from data space
;                dummy  = Usb_read_byte();                //!< dummy read
         LDS       R25,0x00F1     ;Load direct from data space
;                if (wValue == FEATURE_ENDPOINT_HALT)
         TST       R24            ;Test for Zero or Minus
         BREQ      PC+0x02        ;Branch if equal
         RJMP      PC+0x00CC      ;Relative jump
;                   wIndex = (Usb_read_byte() & MSK_EP_DIR);
         LDS       R30,0x00F1     ;Load direct from data space
         ANDI      R30,0x7F       ;Logical AND with immediate
;                   Usb_select_endpoint(wIndex);
         STS       0x00E9,R30     ;Store direct to data space
;                   if(Is_usb_endpoint_enabled())
         LDS       R24,0x00EB     ;Load direct from data space
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC+0x0054      ;Relative jump
;                      if(wIndex != EP_CONTROL)
         TST       R30            ;Test for Zero or Minus
         BREQ      PC+0x17        ;Branch if equal
;                         Usb_disable_stall_handshake();
         LDS       R24,0x00EB     ;Load direct from data space
         ORI       R24,0x10       ;Logical OR with immediate
         STS       0x00EB,R24     ;Store direct to data space
;                         Usb_reset_endpoint(wIndex);
         LDI       R24,0x01       ;Load immediate
         LDI       R25,0x00       ;Load immediate
         MOV       R0,R30         ;Copy register
         RJMP      PC+0x0003      ;Relative jump
         LSL       R24            ;Logical Shift Left
         ROL       R25            ;Rotate Left Through Carry
         DEC       R0             ;Decrement
         BRPL      PC-0x03        ;Branch if plus
         STS       0x00EA,R24     ;Store direct to data space
         STS       0x00EA,R1      ;Store direct to data space
;                         Usb_reset_data_toggle();
         LDS       R24,0x00EB     ;Load direct from data space
         ORI       R24,0x08       ;Logical OR with immediate
         STS       0x00EB,R24     ;Store direct to data space
;                      Usb_select_endpoint(EP_CONTROL);
         STS       0x00E9,R1      ;Store direct to data space
;                      endpoint_status[wIndex] = 0x00;
         LDI       R31,0x00       ;Load immediate
         SUBI      R30,0x8D       ;Subtract immediate
         SBCI      R31,0xFE       ;Subtract immediate with carry
         STD       Z+0,R1         ;Store indirect with displacement
         RJMP      PC+0x002C      ;Relative jump
;                   else                       { usb_user_read_request(bmRequestType, bmRequest); }
         MOV       R24,R25        ;Copy register
         LDI       R22,0x01       ;Load immediate
         RJMP      PC+0x0088      ;Relative jump
;                   if (0x02 >= bmRequestType) { usb_set_feature(); }
         CPI       R25,0x03       ;Compare with immediate
         BRCC      PC+0x33        ;Branch if carry cleared
;             if (bmRequestType == ZERO_TYPE)
         TST       R25            ;Test for Zero or Minus
         BRNE      PC+0x04        ;Branch if not equal
;               wValue = Usb_read_byte();
         LDS       R24,0x00F1     ;Load direct from data space
         RJMP      PC+0x009A      ;Relative jump
;             else if (bmRequestType == INTERFACE_TYPE)
         CPI       R25,0x01       ;Compare with immediate
         BRNE      PC+0x02        ;Branch if not equal
         RJMP      PC+0x0097      ;Relative jump
;                wValue = Usb_read_byte();
         LDS       R24,0x00F1     ;Load direct from data space
;                dummy    = Usb_read_byte();                //!< dummy read
         LDS       R25,0x00F1     ;Load direct from data space
;                if (wValue == FEATURE_ENDPOINT_HALT)
         TST       R24            ;Test for Zero or Minus
         BREQ      PC+0x02        ;Branch if equal
         RJMP      PC+0x0090      ;Relative jump
;                   wIndex = (Usb_read_byte() & MSK_EP_DIR);
         LDS       R30,0x00F1     ;Load direct from data space
         ANDI      R30,0x7F       ;Logical AND with immediate
;                   if (wIndex == EP_CONTROL)
         BRNE      PC+0x02        ;Branch if not equal
         RJMP      PC+0x008B      ;Relative jump
;                   Usb_select_endpoint(wIndex);
         STS       0x00E9,R30     ;Store direct to data space
;                   if(Is_usb_endpoint_enabled())
         LDS       R24,0x00EB     ;Load direct from data space
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC+0x0016      ;Relative jump
;                      Usb_enable_stall_handshake();
         LDS       R24,0x00EB     ;Load direct from data space
         ORI       R24,0x20       ;Logical OR with immediate
         STS       0x00EB,R24     ;Store direct to data space
;                      Usb_select_endpoint(EP_CONTROL);
         STS       0x00E9,R1      ;Store direct to data space
;                      endpoint_status[wIndex] = 0x01;
         LDI       R31,0x00       ;Load immediate
         SUBI      R30,0x8D       ;Subtract immediate
         SBCI      R31,0xFE       ;Subtract immediate with carry
         LDI       R24,0x01       ;Load immediate
         STD       Z+0,R24        ;Store indirect with displacement
;                      Usb_ack_receive_setup();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;                      Usb_send_control_in();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFE       ;Logical AND with immediate
         RJMP      PC+0x0078      ;Relative jump
;                      Usb_select_endpoint(EP_CONTROL);
         STS       0x00E9,R1      ;Store direct to data space
         RJMP      PC+0x006D      ;Relative jump
;                   else                       { usb_user_read_request(bmRequestType, bmRequest); }
         MOV       R24,R25        ;Copy register
         LDI       R22,0x03       ;Load immediate
         RJMP      PC+0x0051      ;Relative jump
;                   if ((0x7F < bmRequestType) & (0x82 >= bmRequestType))
         MOV       R24,R25        ;Copy register
         SUBI      R24,0x80       ;Subtract immediate
         CPI       R24,0x03       ;Compare with immediate
         BRCC      PC+0x2F        ;Branch if carry cleared
;             dummy    = Usb_read_byte();                 //!< dummy read
         LDS       R24,0x00F1     ;Load direct from data space
;             dummy    = Usb_read_byte();                 //!< dummy read
         LDS       R24,0x00F1     ;Load direct from data space
;             wIndex = Usb_read_byte();
         LDS       R30,0x00F1     ;Load direct from data space
;             switch(bmRequestType)
         CPI       R25,0x81       ;Compare with immediate
         BREQ      PC+0x06        ;Branch if equal
         CPI       R25,0x82       ;Compare with immediate
         BREQ      PC+0x0C        ;Branch if equal
         CPI       R25,0x80       ;Compare with immediate
         BREQ      PC+0x02        ;Branch if equal
         RJMP      PC+0x0059      ;Relative jump
;              case REQUEST_INTERFACE_STATUS: Usb_ack_receive_setup();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;                                             Usb_write_byte(INTERFACE_STATUS);
         STS       0x00F1,R1      ;Store direct to data space
         RJMP      PC+0x000E      ;Relative jump
;              case REQUEST_ENDPOINT_STATUS:  Usb_ack_receive_setup();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;                                             Usb_write_byte(endpoint_status[wIndex]);
         LDI       R31,0x00       ;Load immediate
         ANDI      R30,0x7F       ;Logical AND with immediate
         ANDI      R31,0x00       ;Logical AND with immediate
         SUBI      R30,0x8D       ;Subtract immediate
         SBCI      R31,0xFE       ;Subtract immediate with carry
         LDD       R24,Z+0        ;Load indirect with displacement
         STS       0x00F1,R24     ;Store direct to data space
;             Usb_write_byte(0x00);
         STS       0x00F1,R1      ;Store direct to data space
;             Usb_send_control_in();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFE       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             while( !Is_usb_receive_out() );
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,2          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump
         RJMP      PC+0x0014      ;Relative jump
;                   else                       { usb_user_read_request(bmRequestType, bmRequest); }
         MOV       R24,R25        ;Copy register
         LDI       R22,0x00       ;Load immediate
         RJMP      PC+0x001C      ;Relative jump
;                    if (bmRequestType == 0x81) { usb_get_interface(); }
         CPI       R25,0x81       ;Compare with immediate
         BRNE      PC+0x18        ;Branch if not equal
;             Usb_ack_receive_setup();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             Usb_send_control_in();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFE       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;             while( !Is_usb_receive_out() );
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,2          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump
;             Usb_ack_receive_out();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFB       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0x7F       ;Logical AND with immediate
         RJMP      PC+0x0024      ;Relative jump
;                    else { usb_user_read_request(bmRequestType, bmRequest); }
         MOV       R24,R25        ;Copy register
         LDI       R22,0x0A       ;Load immediate
         CALL      USB_User_Read_Request ;Call subroutine A0145
         RJMP      PC+0x0021      ;Relative jump
;                if (bmRequestType == 0x01) {usb_set_interface();}
         CPI       R25,0x01       ;Compare with immediate
         BRNE      PC+0x1F        ;Branch if not equal
;            Usb_ack_receive_setup();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;            Usb_send_control_in();                    //!< send a ZLP for STATUS phase
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFE       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;            while(!Is_usb_in_ready());
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump
         RJMP      PC+0x0010      ;Relative jump
;                   if(usb_user_read_request(bmRequestType, bmRequest) == FALSE)
         MOV       R24,R25        ;Copy register
         CALL      USB_User_Read_Request ;Call subroutine A0145 
         TST       R24            ;Test for Zero or Minus
         BRNE      PC+0x0B        ;Branch if not equal
;                      Usb_enable_stall_handshake();
         LDS       R24,0x00EB     ;Load direct from data space
         ORI       R24,0x20       ;Logical OR with immediate
         STS       0x00EB,R24     ;Store direct to data space
;                      Usb_ack_receive_setup();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xF7       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;          }
         POP       R0             ;Pop register from stack
         POP       R0             ;Pop register from stack
         POP       R28            ;Pop register from stack
         POP       R29            ;Pop register from stack
         RET                      ;Subroutine return

USB_Device_Task_Init:
         LDI       R30,USBCON     ;Load immediate ZL=0xD8
         LDI       R31,0x00       ;Load immediate ZH=0x00 USBCON=USBE=0 - FRZCLK - - - - -
         LDD       R24,Z+0        ;Load indirect 0x00D8 with displacement
         ANDI      R24,0x7F       ;Logical AND with immediate 01111111
         STD       Z+0,R24        ;Store indirect with displacement
;             Usb_enable();
         LDD       R24,Z+0        ;Load indirect USBCON with displacement
         ORI       R24,0x80       ;Logical OR with immediate 1000 0000
         STD       Z+0,R24        ;Store indirect USBCON with displacement
;          }
         RET                      ;Subroutine return

USB_Start_Device:
;             Usb_freeze_clock();
         LDS       R24,USBCON     ;Load direct from data space 0x00D8 
         ORI       R24,0x20       ;Logical OR with immediate USBCON=USBE - FRZCLK=1 - - - - -
         STS       0x00D8,R24     ;Store direct to data space 0x00D8 USBCON
;             Pll_start_auto();
         LDI       R24,0x02       ;Load immediate 0000 0010
         OUT       PLLCSR,R24     ;Out to I/O location PLLCSR0 - - - PLLP2=0 PLLP1=0 PLLP0=0 PLLE=2 PLOCK=0
;             Wait_pll_ready();
         IN        R0,PLLCSR      ;In from I/O location 0x29= - - - PLLP2 PLLP1 PLLP0 PLLE PLOCK
         SBRS      R0,0           ;Skip if bit in register set
         RJMP      PC-0x0002      ;Relative jump
;             Usb_unfreeze_clock();
         LDS       R24,USBCON     ;Load direct from data space 0x00D8
         ANDI      R24,0xDF       ;Logical AND with immediate 1101 1111  
         STS       USBCON,R24     ;Store direct to data space  0x00D8 USBCON = USBE - FRZCLK=0 - - - - -
;             Usb_unfreeze_clock();
         LDS       R24,USBCON     ;Load direct from data space 0x00D8
         ANDI      R24,0xDF       ;Logical AND with immediate
         STS       USBCON,R24     ;Store direct to data space
;             Usb_attach();
         LDS       R24,UDCON      ;Load direct from data space 0x00E0
         ANDI      R24,0xFE       ;Logical AND with immediate 1111 1110
         STS       UDCON,R24      ;Store direct to data space UDCON= - - - - - RSTCPU=1 RMWKUP=1 DETACH=0
;             Usb_reset_macro_only();
         LDS       R24,UDCON      ;Load direct from data space
         ANDI      R24,0xFB       ;Logical AND with immediate 1111 1011
         STS       UDCON,R24      ;Store direct to data space UDCON= - - - - - RSTCPU=0 RMWKUP=1 DETACH=1
;             Usb_enable_suspend_interrupt();
         LDS       R24,UDIEN      ;Load direct from data space 0x00E2
         ORI       R24,0x01       ;Logical OR with immediate 0000 0001
         STS       0x00E2,R24     ;Store direct to data space UDIEN=0 -=0 UPRSME=0 EORSME=0 WAKEUPE=0 EORSTE=0 SOFE=0 -=1 SUSPE=1 
;             Usb_enable_reset_interrupt();
         LDS       R24,UDIEN     ;Load direct from data space 0x00E2
         ORI       R24,0x08       ;Logical OR with immediate 00001000
         STS       UDIEN,R24     ;Store direct to data space 
;             Enable_interrupt();UDIEN= -=0 UPRSME=0 EORSME=0 WAKEUPE=0 EORSTE=1 SOFE=0 -=0 SUSPE=0 
         SEI                      ;Global Interrupt Enable
;             usb_init_device();         // configure the USB controller EP0
         CALL      USB_Init_Device ;Call subroutine A0292
         RET                      ;Subroutine return

USB_Device_Task:
;             if (usb_connected == FALSE)
         LDS       R24,0x0178     ;Load direct from data space
         TST       R24            ;Test for Zero or Minus
         BRNE      PC+0x06        ;Branch if not equal
;               usb_connected = TRUE;    // attach if application is not self-powered
         LDI       R24,0x01       ;Load immediate
         STS       0x0178,R24     ;Store direct to data space
;               usb_start_device();
         CALL      USB_Start_Device  ;Call subroutine 
;             if(Is_usb_event(EVT_USB_RESET))
         LDS       R24,0x0170     ;Load direct from data space
         LDS       R25,0x0171     ;Load direct from data space
         SBRS      R25,0          ;Skip if bit in register set
         RJMP      PC+0x0011      ;Relative jump
;                Usb_ack_event(EVT_USB_RESET);
         LDS       R24,0x0170     ;Load direct from data space
         LDS       R25,0x0171     ;Load direct from data space
         ANDI      R25,0xFE       ;Logical AND with immediate 1111 1110
         STS       0x0171,R25     ;Store direct to data space
         STS       0x0170,R24     ;Store direct to data space
;                Usb_reset_endpoint(0);
         LDI       R24,0x01       ;Load immediate
         STS       UERST,R24     ;Store direct to data space 0x00EA UERST= - - - EPRST4 EPRST3 EPRST2 EPRST1 EPRST0
         STS       UERST,R1      ;Store direct to data space
;                usb_configuration_nb=0;
         STS       0x0184,R1      ;Store direct to data space
;             Usb_select_endpoint(EP_CONTROL);
         STS       UENUM,R1      ;Store direct to data space 0x00E9 UENUM= - - - - - EPNUM2:0
;             if (Is_usb_receive_setup())
         LDS       R24,UEINTX     ;Load direct from data space 0x00E8 UEINTX= FIFOCON NAKINI RWAL NAKOUTI RXSTPI=1 RXOUTI STALLEDI TXINI
         SBRS      R24,3          ;Skip if bit in register set RXSTPI=1
         RJMP      PC+0x0003      ;Relative jump to Return
;                usb_process_request();
         CALL      USB_Process_Request;Call subroutine A0349     
         RET                      ;Subroutine return
;          {
         RET                      ;Subroutine return

Scheduler_Tasks:
         CALL      USB_Task       ;Call subroutine A0343
;                   Scheduler_task_2();
         CALL      CDC_Task       ;Call subroutine A018B
         RJMP      PC-0x0004      ;Relative jump

Scheduler_Init:
;                Scheduler_task_1_init();  
         CALL      USB_Task_Init   ;Call subroutine A0346
;                Scheduler_task_2_init();  
         CALL      CDC_Task_Init   ;Call subroutine A01EF 
         RET                      ;Subroutine return

Scheduler:
;             scheduler_init();
         CALL      Scheduler_Init   ;Call subroutine A05C7 
;             scheduler_tasks();
         CALL      Scheduler_Tasks  ;Call subroutine A05C2 
         RET                      ;Subroutine return

Uart_Test_Hit:
         LDS       R24,0x00C8     ;Load direct from data space
         ANDI      R24,0x80       ;Logical AND with immediate
         RET                      ;Subroutine return

Uart_Init:
;            Uart_set_baudrate(BAUDRATE/2);
         LDI       R24,0x19       ;Load immediate 0x0019
         LDI       R25,0x00       ;Load immediate
         STS       UBRR1H,R25     ;Store direct to data space 0x00CD UBRR1H - - - - USART1 Baud Rate Register High Byte
         STS       UBRR1L,R24     ;Store direct to data space 0x00CC UBRR1L USART1 Baud Rate Register Low Byte

;            Uart_double_bdr(); 
         LDI       ZL,UCSR1A     ;Load immediate 0x00C8
         LDI       ZH,0x00       ;Load immediate
         LDD       R24,Z+0        ;Load indirect with displacement 0x00C8 UCSR1A= RXC1 TXC1 UDRE1 FE1 DOR1 PE1 U2X1=1 MPCM1 
         ORI       R24,0x02       ;Logical OR with immediate 0000 0010
         STD       Z+0,R24        ;Store indirect with displacement
;            Uart_hw_init(UART_CONFIG);
         LDI       R24,0x06       ;Load immediate 0x06=0000 0110
         STS       UCSR1C,R24     ;Store direct to data space 0x00CA UCSR1C UMSEL11 UMSEL10 UPM11 UPM10 USBS1 UCSZ11=1 UCSZ10=1 UCPOL1
;            Uart_enable();
         LDI       ZL,UCSR1B        ;Load immediate 0xC9
         LDI       ZH,0x00        ;Load immediate 0x00C9
         LDD       R24,Z+0        ;Load indirect with displacement
         ORI       R24,0x18       ;Logical OR with immediate 0001 1000
         STD       Z+0,R24        ;Store indirect UCSR1B=RXCIE1 TXCIE1 UDRIE1 RXEN1=1 TXEN1=1 UCSZ12 RXB81 TXB81 with displacement
;          }
         LDI       R24,0x01       ;Load immediate
         RET                      ;Subroutine return

Uart_PutChar:
;          {
         MOV       R18,R24        ;Copy register
;            while(!Uart_tx_ready());
         LDS       R24,0x00C8     ;Load direct from data space
         SBRS      R24,5          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump
;            Uart_send_byte(ch);
         STS       0x00CE,R18     ;Store direct to data space
;          }
         MOV       R24,R18        ;Copy register
         RET                      ;Subroutine return

Uart_GetChar:
;            while(!Uart_rx_ready());
         LDS       R24,0x00C8     ;Load direct from data space
         SBRS      R24,7          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump
;            c = Uart_get_byte();
         LDS       R24,0x00CE     ;Load direct from data space
;          }
         RET                      ;Subroutine return

Uart_USB_Init:
;---- C:\Atmel\at90usb162-cdc-1_0_1\at90usb162\demo\cdc\uart_usb_lib.c -----------------------------
;          {
         STS       0x0188,R1      ;Store direct to data space
;            rx_counter = 0;
         STS       0x0189,R1      ;Store direct to data space
;          }
         RET                      ;Subroutine return

Uart_USB_Test_Hit:
;            if (!rx_counter)
         LDS       R24,0x0189     ;Load direct from data space
         TST       R24            ;Test for Zero or Minus
         BRNE      PC+0x18        ;Branch if not equal
;              Usb_select_endpoint(RX_EP);
         LDI       R24,0x02       ;Load immediate
         STS       0x00E9,R24     ;Store direct to data space
;              if (Is_usb_receive_out())
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,2          ;Skip if bit in register set
         RJMP      PC+0x0011      ;Relative jump
;                rx_counter = Usb_byte_counter();
         LDS       R24,0x00F2     ;Load direct from data space
         STS       0x0189,R24     ;Store direct to data space
;                if (!rx_counter)
         TST       R24            ;Test for Zero or Minus
         BRNE      PC+0x0B        ;Branch if not equal
;                  Usb_ack_receive_out();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFB       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0x7F       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
         LDS       R24,0x0189     ;Load direct from data space
         CPSE      R24,R1         ;Compare, skip if equal
         LDI       R24,0x01       ;Load immediate
;          }
         RET                      ;Subroutine return

Uart_USB_GetChar:
;            Usb_select_endpoint(RX_EP);
         LDI       R24,0x02       ;Load immediate
         STS       0x00E9,R24     ;Store direct to data space
;            if (!rx_counter) while (!uart_usb_test_hit());
         LDS       R24,0x0189     ;Load direct from data space
         TST       R24            ;Test for Zero or Minus
         BRNE      PC+0x04        ;Branch if not equal
         CALL      Uart_USB_Test_Hit ;Call subroutine A05FF 
         RJMP      PC-0x0004      ;Relative jump
;            data_rx=Usb_read_byte();
         LDS       R25,0x00F1     ;Load direct from data space
;            rx_counter--;
         LDS       R24,0x0189     ;Load direct from data space
         SUBI      R24,0x01       ;Subtract immediate
         STS       0x0189,R24     ;Store direct to data space
;            if (!rx_counter) Usb_ack_receive_out();
         TST       R24            ;Test for Zero or Minus
         BRNE      PC+0x0B        ;Branch if not equal
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0xFB       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0x7F       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;          }
         MOV       R24,R25        ;Copy register
         RET                      ;Subroutine return
;            if (!Is_usb_write_enabled())
         LDS       R24,0x00E8     ;Load direct from data space
         LDI       R25,0x00       ;Load immediate
         LDI       R18,0x05       ;Load immediate
         LSR       R25            ;Logical shift right
         ROR       R24            ;Rotate right through carry
         DEC       R18            ;Decrement
         BRNE      PC-0x03        ;Branch if not equal
;          }
         ANDI      R24,0x01       ;Logical AND with immediate
         RET                      ;Subroutine return

Uart_Usb_PutChar:
;          {
         MOV       R18,R24        ;Copy register
;            	Usb_select_endpoint(TX_EP);
         LDI       R24,0x01       ;Load immediate
         STS       0x00E9,R24     ;Store direct to data space
;            if (!Is_usb_write_enabled())
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,5          ;Skip if bit in register set
         RJMP      PC-0x0003      ;Relative jump
         RJMP      PC+0x000D      ;Relative jump
;             Usb_select_endpoint(TX_EP);
         LDI       R24,0x01       ;Load immediate
         STS       0x00E9,R24     ;Store direct to data space
;             Usb_send_in();
         LDS       R24,0x00E8     ;Load direct from data space
         ANDI      R24,0x7F       ;Logical AND with immediate
         STS       0x00E8,R24     ;Store direct to data space
;          	tx_counter = 0;
         STS       0x0188,R1      ;Store direct to data space
;          }
         MOV       R24,R18        ;Copy register
         RET                      ;Subroutine return
;          	Usb_write_byte(data_to_send);
         STS       0x00F1,R18     ;Store direct to data space
;          	tx_counter++;
         LDS       R24,0x0188     ;Load direct from data space
         SUBI      R24,0xFF       ;Subtract immediate
         STS       0x0188,R24     ;Store direct to data space
;             	if(!Is_usb_write_enabled()) //If Endpoint full -> flush
         LDS       R24,0x00E8     ;Load direct from data space
         SBRS      R24,5          ;Skip if bit in register set
         RJMP      PC-0x0016      ;Relative jump
         RJMP      PC-0x000D      ;Relative jump

Usb_Select_Endpoint:
;             Usb_select_endpoint(TX_EP);
         LDI       R24,0x01       ;Load immediate
         STS       0x00E9,R24     ;Store direct to data space
;             Usb_send_in();
         LDI       R30,0xE8       ;Load immediate
         LDI       R31,0x00       ;Load immediate
         LDD       R24,Z+0        ;Load indirect with displacement
         ANDI      R24,0x7F       ;Logical AND with immediate
         STD       Z+0,R24        ;Store indirect with displacement
;             tx_counter = 0;
         STS       0x0188,R1      ;Store direct to data space
;           }
         RET                      ;Subroutine return

SubA0674: 
         LDI       R26,0x21       ;Load immediate
         MOV       R1,R26         ;Copy register
         SUB       R26,R26        ;Subtract without carry
         SUB       R27,R27        ;Subtract without carry
         MOVW      R30,R26        ;Copy register pair
         RJMP      PC+0x000E      ;Relative jump
         ROL       R26            ;Rotate Left Through Carry
         ROL       R27            ;Rotate Left Through Carry
         ROL       R30            ;Rotate Left Through Carry
         ROL       R31            ;Rotate Left Through Carry
         CP        R26,R18        ;Compare
         CPC       R27,R19        ;Compare with carry
         CPC       R30,R20        ;Compare with carry
         CPC       R31,R21        ;Compare with carry
         BRCS      PC+0x05        ;Branch if carry set
         SUB       R26,R18        ;Subtract without carry
         SBC       R27,R19        ;Subtract with carry
         SBC       R30,R20        ;Subtract with carry
         SBC       R31,R21        ;Subtract with carry
         ROL       R22            ;Rotate Left Through Carry
         ROL       R23            ;Rotate Left Through Carry
         ROL       R24            ;Rotate Left Through Carry
         ROL       R25            ;Rotate Left Through Carry
         DEC       R1             ;Decrement
         BRNE      PC-0x12        ;Branch if not equal
         COM       R22            ;One's complement
         COM       R23            ;One's complement
         COM       R24            ;One's complement
         COM       R25            ;One's complement
         MOVW      R18,R22        ;Copy register pair
         MOVW      R20,R24        ;Copy register pair
         MOVW      R22,R26        ;Copy register pair
         MOVW      R24,R30        ;Copy register pair
         RET                      ;Subroutine return

SubA0696:
         PUSH      R16            ;Push register on stack
         PUSH      R17            ;Push register on stack
         PUSH      R28            ;Push register on stack
         PUSH      R29            ;Push register on stack
         MOVW      R16,R24        ;Copy register pair
         MOVW      R28,R22        ;Copy register pair
         SBIW      R24,0x00       ;Subtract immediate from word
         BRNE      PC+0x07        ;Branch if not equal
         CP        R22,R1         ;Compare
         CPC       R23,R1         ;Compare with carry
         BRNE      PC+0x04        ;Branch if not equal
         LDI       R18,0x00       ;Load immediate
         LDI       R19,0x00       ;Load immediate
         RJMP      PC+0x0039      ;Relative jump
         LDI       R24,0x01       ;Load immediate
         LDI       R25,0x00       ;Load immediate
         LDI       R22,0x0E       ;Load immediate
         LDI       R23,0x00       ;Load immediate
         CALL      SubA0717       ;Call subroutine A0717
         MOVW      R30,R24        ;Copy register pair
         MOVW      R18,R24        ;Copy register pair
         SBIW      R24,0x00       ;Subtract immediate from word
         BREQ      PC+0x2F        ;Branch if equal
         LDI       R24,0x80       ;Load immediate
         STD       Z+3,R24        ;Store indirect with displacement
         SBIW      R28,0x00       ;Subtract immediate from word
         BREQ      PC+0x0F        ;Branch if equal
         STD       Z+11,R29       ;Store indirect with displacement
         STD       Z+10,R28       ;Store indirect with displacement
         LDI       R24,0x81       ;Load immediate
         STD       Z+3,R24        ;Store indirect with displacement
         LDS       R24,0x018A     ;Load direct from 0x018A data space
         LDS       R25,0x018B     ;Load direct from 0x018B data space
         OR        R24,R25        ;Logical OR
         BRNE      PC+0x05        ;Branch if not equal
         STS       0x018B,R31     ;Store direct to data space
         STS       0x018A,R30     ;Store direct to data space
         CP        R16,R1         ;Compare
         CPC       R17,R1         ;Compare with carry
         BREQ      PC+0x1A        ;Branch if equal
         STD       Z+9,R17        ;Store indirect with displacement
         STD       Z+8,R16        ;Store indirect with displacement
         LDD       R24,Z+3        ;Load indirect with displacement
         ORI       R24,0x02       ;Logical OR with immediate
         STD       Z+3,R24        ;Store indirect with displacement
         LDS       R24,0x018C     ;Load direct from data space
         LDS       R25,0x018D     ;Load direct from data space
         OR        R24,R25        ;Logical OR
         BRNE      PC+0x0F        ;Branch if not equal
         STS       0x018D,R31     ;Store direct to data space
         STS       0x018C,R30     ;Store direct to data space
         LDS       R24,0x018E     ;Load direct from data space
         LDS       R25,0x018F     ;Load direct from data space
         OR        R24,R25        ;Logical OR
         BRNE      PC+0x05        ;Branch if not equal
         STS       0x018F,R31     ;Store direct to data space
         STS       0x018E,R30     ;Store direct to data space
         MOVW      R24,R18        ;Copy register pair
         POP       R29            ;Pop register from stack
         POP       R28            ;Pop register from stack
         POP       R17            ;Pop register from stack
         POP       R16            ;Pop register from stack
         RET                      ;Subroutine return

Print_F:
         PUSH      R16            ;Push register on stack
         PUSH      R17            ;Push register on stack
         PUSH      R28            ;Push register on stack
         PUSH      R29            ;Push register on stack
         MOVW      R16,R24        ;Copy register pair
         LDS       R30,0x018C     ;Load direct from data space
         LDS       R31,0x018D     ;Load direct from data space
         LDD       R24,Z+3        ;Load indirect with displacement
         SBRS      R24,1          ;Skip if bit in register set
         RJMP      PC+0x0022      ;Relative jump
         LDI       R28,0x00       ;Load immediate
         LDI       R29,0x00       ;Load immediate
         RJMP      PC+0x000E      ;Relative jump
         LDS       R30,0x018C     ;Load direct from data space
         LDS       R31,0x018D     ;Load direct from data space
         LDD       R18,Z+8        ;Load indirect with displacement
         LDD       R19,Z+9        ;Load indirect with displacement
         MOVW      R22,R30        ;Copy register pair
         MOVW      R30,R18        ;Copy register pair
         ICALL                    ;Indirect call to (Z)
         OR        R24,R25        ;Logical OR
         BREQ      PC+0x03        ;Branch if equal
         SER       R28            ;Set Register
         SER       R29            ;Set Register
         MOVW      R30,R16        ;Copy register pair
         LD        R24,Z+         ;Load indirect and postincrement
         MOVW      R16,R30        ;Copy register pair
         TST       R24            ;Test for Zero or Minus
         BRNE      PC-0x11        ;Branch if not equal
         LDS       R30,0x018C     ;Load direct from data space
         LDS       R31,0x018D     ;Load direct from data space
         LDD       R18,Z+8        ;Load indirect with displacement
         LDD       R19,Z+9        ;Load indirect with displacement
         LDI       R24,0x0A       ;Load immediate
         MOVW      R22,R30        ;Copy register pair
         MOVW      R30,R18        ;Copy register pair
         ICALL                    ;Indirect call to (Z)
         OR        R24,R25        ;Logical OR
         BREQ      PC+0x03        ;Branch if equal
         SER       R28            ;Set Register
         SER       R29            ;Set Register
         MOVW      R24,R28        ;Copy register pair
         POP       R29            ;Pop register from stack
         POP       R28            ;Pop register from stack
         POP       R17            ;Pop register from stack
         POP       R16            ;Pop register from stack
         RET                      ;Subroutine return

SubA0717:
         PUSH      R16            ;Push register on stack
   		 PUSH      R17            ;Push register on stack
         PUSH      R28            ;Push register on stack
         PUSH      R29            ;Push register on stack
         MOVW      R18,R24        ;Copy register pair
         MOVW      R24,R22        ;Copy register pair
         MOVW      R22,R18        ;Copy register pair
         CALL      SubA083F       ;Call subroutine A083F
         MOV       R17,R24        ;Copy register
         MOV       R16,R25        ;Copy register
         CALL      SubA0733       ;Call subroutine A0733
         MOVW      R28,R24        ;Copy register pair
         SBIW      R24,0x00       ;Subtract immediate from word
         BREQ      PC+0x07        ;Branch if equal
         LDI       R22,0x00       ;Load immediate
         LDI       R23,0x00       ;Load immediate
         MOV       R20,R17        ;Copy register
         MOV       R21,R16        ;Copy register
         CALL      SubA0838       ;Call subroutine A0838
         MOVW      R24,R28        ;Copy register pair
         POP       R29            ;Pop register from stack
         POP       R28            ;Pop register from stack
         POP       R17            ;Pop register from stack
         POP       R16            ;Pop register from stack
         RET                      ;Subroutine return

SubA0733:
         PUSH      R28            ;Push register on stack
         PUSH      R29            ;Push register on stack
         MOVW      R22,R24        ;Copy register pair
         CPI       R24,0x02       ;Compare with immediate
         CPC       R25,R1         ;Compare with carry
         BRCC      PC+0x03        ;Branch if carry cleared
         LDI       R22,0x02       ;Load immediate
         LDI       R23,0x00       ;Load immediate
         LDS       R26,0x0192     ;Load direct from data space
         LDS       R27,0x0193     ;Load direct from data space
         MOVW      R28,R26        ;Copy register pair
         LDI       R30,0x00       ;Load immediate
         LDI       R31,0x00       ;Load immediate
         LDI       R20,0x00       ;Load immediate
         LDI       R21,0x00       ;Load immediate
         RJMP      PC+0x0022      ;Relative jump
         LDD       R24,Y+0        ;Load indirect with displacement
         LDD       R25,Y+1        ;Load indirect with displacement
         CP        R24,R22        ;Compare
         CPC       R25,R23        ;Compare with carry
         BRNE      PC+0x0E        ;Branch if not equal
         LDD       R24,Y+2        ;Load indirect with displacement
         LDD       R25,Y+3        ;Load indirect with displacement
         SBIW      R30,0x00       ;Subtract immediate from word
         BREQ      PC+0x04        ;Branch if equal
         STD       Z+3,R25        ;Store indirect with displacement
         STD       Z+2,R24        ;Store indirect with displacement
         RJMP      PC+0x0005      ;Relative jump
         STS       0x0193,R25     ;Store direct to data space
         STS       0x0192,R24     ;Store direct to data space
         MOVW      R30,R28        ;Copy register pair
         RJMP      PC+0x0035      ;Relative jump
         CP        R22,R24        ;Compare
         CPC       R23,R25        ;Compare with carry
         BRCC      PC+0x08        ;Branch if carry cleared
         CP        R20,R1         ;Compare
         CPC       R21,R1         ;Compare with carry
         BREQ      PC+0x04        ;Branch if equal
         CP        R24,R20        ;Compare
         CPC       R25,R21        ;Compare with carry
         BRCC      PC+0x02        ;Branch if carry cleared
         MOVW      R20,R24        ;Copy register pair
         MOVW      R30,R28        ;Copy register pair
         LDD       R24,Y+2        ;Load indirect with displacement
         LDD       R25,Y+3        ;Load indirect with displacement
         MOVW      R18,R24        ;Copy register pair
         MOVW      R28,R18        ;Copy register pair
         SBIW      R28,0x00       ;Subtract immediate from word
         BRNE      PC-0x22        ;Branch if not equal
         CP        R20,R1         ;Compare
         CPC       R21,R1         ;Compare with carry
         BREQ      PC+0x36        ;Branch if equal
         MOVW      R24,R20        ;Copy register pair
         SUB       R24,R22        ;Subtract without carry
         SBC       R25,R23        ;Subtract with carry
         SBIW      R24,0x04       ;Subtract immediate from word
         BRCC      PC+0x02        ;Branch if carry cleared
         MOVW      R22,R20        ;Copy register pair
         LDI       R30,0x00       ;Load immediate
         LDI       R31,0x00       ;Load immediate
         RJMP      PC+0x002B      ;Relative jump
         LD        R24,X+         ;Load indirect and postincrement
         LD        R25,X          ;Load indirect
         SBIW      R26,0x01       ;Subtract immediate from word
         CP        R24,R20        ;Compare
         CPC       R25,R21        ;Compare with carry
         BRNE      PC+0x20        ;Branch if not equal
         CP        R22,R20        ;Compare
         CPC       R23,R21        ;Compare with carry
         BRNE      PC+0x11        ;Branch if not equal
         ADIW      R26,0x02       ;Add immediate to word
         LD        R24,X+         ;Load indirect and postincrement
         LD        R25,X          ;Load indirect
         SBIW      R26,0x03       ;Subtract immediate from word
         SBIW      R30,0x00       ;Subtract immediate from word
         BREQ      PC+0x04        ;Branch if equal
         STD       Z+3,R25        ;Store indirect with displacement
         STD       Z+2,R24        ;Store indirect with displacement
         RJMP      PC+0x0005      ;Relative jump
         STS       0x0193,R25     ;Store direct to data space
         STS       0x0192,R24     ;Store direct to data space
         MOVW      R30,R26        ;Copy register pair
         ADIW      R30,0x02       ;Add immediate to word
         RJMP      PC+0x0050      ;Relative jump
         MOVW      R24,R20        ;Copy register pair
         SUB       R24,R22        ;Subtract without carry
         SBC       R25,R23        ;Subtract with carry
         MOVW      R30,R26        ;Copy register pair
         ADD       R30,R24        ;Add without carry
         ADC       R31,R25        ;Add with carry
         ST        Z+,R22         ;Store indirect and postincrement
         ST        Z+,R23         ;Store indirect and postincrement
         SBIW      R24,0x02       ;Subtract immediate from word
         ST        X+,R24         ;Store indirect and postincrement
         ST        X,R25          ;Store indirect
         RJMP      PC+0x0044      ;Relative jump
         MOVW      R30,R26        ;Copy register pair
         LDD       R24,Z+2        ;Load indirect with displacement
         LDD       R25,Z+3        ;Load indirect with displacement
         MOVW      R18,R24        ;Copy register pair
         MOVW      R26,R18        ;Copy register pair
         SBIW      R26,0x00       ;Subtract immediate from word
         BRNE      PC-0x2B        ;Branch if not equal
         LDS       R24,0x0190     ;Load direct from data space
         LDS       R25,0x0191     ;Load direct from data space
         OR        R24,R25        ;Logical OR
         BRNE      PC+0x09        ;Branch if not equal
         LDS       R24,0x016C     ;Load direct from data space
         LDS       R25,0x016D     ;Load direct from data space
         STS       0x0191,R25     ;Store direct to data space
         STS       0x0190,R24     ;Store direct to data space
         LDS       R20,0x016E     ;Load direct from data space
         LDS       R21,0x016F     ;Load direct from data space
         CP        R20,R1         ;Compare
         CPC       R21,R1         ;Compare with carry
         BRNE      PC+0x09        ;Branch if not equal
         IN        R20,0x3D       ;In from I/O location
         IN        R21,0x3E       ;In from I/O location
         LDS       R24,0x016A     ;Load direct from data space
         LDS       R25,0x016B     ;Load direct from data space
         SUB       R20,R24        ;Subtract without carry
         SBC       R21,R25        ;Subtract with carry
         LDS       R18,0x0190     ;Load direct from data space
         LDS       R19,0x0191     ;Load direct from data space
         CP        R18,R20        ;Compare
         CPC       R19,R21        ;Compare with carry
         BRCC      PC+0x17        ;Branch if carry cleared
         MOVW      R24,R20        ;Copy register pair
         SUB       R24,R18        ;Subtract without carry
         SBC       R25,R19        ;Subtract with carry
         CP        R24,R22        ;Compare
         CPC       R25,R23        ;Compare with carry
         BRCS      PC+0x11        ;Branch if carry set
         MOVW      R20,R22        ;Copy register pair
         SUBI      R20,0xFE       ;Subtract immediate
         SBCI      R21,0xFF       ;Subtract immediate with carry
         CP        R24,R20        ;Compare
         CPC       R25,R21        ;Compare with carry
         BRCS      PC+0x0B        ;Branch if carry set
         ADD       R20,R18        ;Add without carry
         ADC       R21,R19        ;Add with carry
         STS       0x0191,R21     ;Store direct to data space
         STS       0x0190,R20     ;Store direct to data space
         MOVW      R30,R18        ;Copy register pair
         ST        Z+,R22         ;Store indirect and postincrement
         ST        Z+,R23         ;Store indirect and postincrement
         RJMP      PC+0x0003      ;Relative jump
         LDI       R30,0x00       ;Load immediate
         LDI       R31,0x00       ;Load immediate
         MOVW      R24,R30        ;Copy register pair
         POP       R29            ;Pop register from stack
         POP       R28            ;Pop register from stack
         RET                      ;Subroutine return


SubA07E0:
         PUSH      R28            ;Push register on stack
         PUSH      R29            ;Push register on stack
         SBIW      R24,0x00       ;Subtract immediate from word
         BRNE      PC+0x02        ;Branch if not equal
         RJMP      PC+0x0051      ;Relative jump
         MOVW      R28,R24        ;Copy register pair
         SBIW      R28,0x02       ;Subtract immediate from word
         STD       Y+3,R1         ;Store indirect with displacement
         STD       Y+2,R1         ;Store indirect with displacement
         LDS       R26,0x0192     ;Load direct from data space
         LDS       R27,0x0193     ;Load direct from data space
         SBIW      R26,0x00       ;Subtract immediate from word
         BREQ      PC+0x22        ;Branch if equal
         LDI       R20,0x00       ;Load immediate
         LDI       R21,0x00       ;Load immediate
         CP        R26,R28        ;Compare
         CPC       R27,R29        ;Compare with carry
         BRCS      PC+0x22        ;Branch if carry set
         STD       Y+3,R27        ;Store indirect with displacement
         STD       Y+2,R26        ;Store indirect with displacement
         MOVW      R30,R28        ;Copy register pair
         LD        R18,Z+         ;Load indirect and postincrement
         LD        R19,Z+         ;Load indirect and postincrement
         ADD       R30,R18        ;Add without carry
         ADC       R31,R19        ;Add with carry
         CP        R26,R30        ;Compare
         CPC       R27,R31        ;Compare with carry
         BRNE      PC+0x10        ;Branch if not equal
         LD        R24,X+         ;Load indirect and postincrement
         LD        R25,X          ;Load indirect
         SBIW      R26,0x01       ;Subtract immediate from word
         ADD       R18,R24        ;Add without carry
         ADC       R19,R25        ;Add with carry
         SUBI      R18,0xFE       ;Subtract immediate
         SBCI      R19,0xFF       ;Subtract immediate with carry
         STD       Y+1,R19        ;Store indirect with displacement
         STD       Y+0,R18        ;Store indirect with displacement
         ADIW      R26,0x02       ;Add immediate to word
         LD        R24,X+         ;Load indirect and postincrement
         LD        R25,X          ;Load indirect
         SBIW      R26,0x03       ;Subtract immediate from word
         STD       Y+3,R25        ;Store indirect with displacement
         STD       Y+2,R24        ;Store indirect with displacement
         CP        R20,R1         ;Compare
         CPC       R21,R1         ;Compare with carry
         BRNE      PC+0x0F        ;Branch if not equal
         STS       0x0193,R29     ;Store direct to data space
         STS       0x0192,R28     ;Store direct to data space
         RJMP      PC+0x0021      ;Relative jump
         ADIW      R26,0x02       ;Add immediate to word
         LD        R24,X+         ;Load indirect and postincrement
         LD        R25,X          ;Load indirect
         SBIW      R26,0x03       ;Subtract immediate from word
         MOVW      R20,R26        ;Copy register pair
         SBIW      R24,0x00       ;Subtract immediate from word
         BREQ      PC+0x03        ;Branch if equal
         MOVW      R26,R24        ;Copy register pair
         RJMP      PC-0x002C      ;Relative jump
         MOVW      R30,R20        ;Copy register pair
         STD       Z+3,R29        ;Store indirect with displacement
         STD       Z+2,R28        ;Store indirect with displacement
         LD        R18,Z+         ;Load indirect and postincrement
         LD        R19,Z+         ;Load indirect and postincrement
         ADD       R30,R18        ;Add without carry
         ADC       R31,R19        ;Add with carry
         CP        R28,R30        ;Compare
         CPC       R29,R31        ;Compare with carry
         BRNE      PC+0x0E        ;Branch if not equal
         LDD       R24,Y+0        ;Load indirect with displacement
         LDD       R25,Y+1        ;Load indirect with displacement
         ADD       R18,R24        ;Add without carry
         ADC       R19,R25        ;Add with carry
         SUBI      R18,0xFE       ;Subtract immediate
         SBCI      R19,0xFF       ;Subtract immediate with carry
         MOVW      R30,R20        ;Copy register pair
         STD       Z+1,R19        ;Store indirect with displacement
         STD       Z+0,R18        ;Store indirect with displacement
         LDD       R24,Y+2        ;Load indirect with displacement
         LDD       R25,Y+3        ;Load indirect with displacement
         STD       Z+3,R25        ;Store indirect with displacement
         STD       Z+2,R24        ;Store indirect with displacement
         POP       R29            ;Pop register from stack
         POP       R28            ;Pop register from stack
         RET                      ;Subroutine return

SubA0838:
         MOVW      R26,R24        ;Copy register pair
         RJMP      PC+0x0002      ;Relative jump
         ST        X+,R22         ;Store indirect and postincrement
         SUBI      R20,0x01       ;Subtract immediate
         SBCI      R21,0x00       ;Subtract immediate with carry
         BRCC      PC-0x03        ;Branch if carry cleared
         RET                      ;Subroutine return

SubA083F:
         CLR       R21            ;Clear Register
         CLR       R0             ;Clear Register
         SBRS      R24,0          ;Skip if bit in register set
         RJMP      PC+0x0003      ;Relative jump
         ADD       R0,R22         ;Add without carry
         ADC       R21,R23        ;Add with carry
         LSL       R22            ;Logical Shift Left
         ROL       R23            ;Rotate Left Through Carry
         CP        R22,R1         ;Compare
         CPC       R23,R1         ;Compare with carry
         BREQ      PC+0x05        ;Branch if equal
         LSR       R25            ;Logical shift right
         ROR       R24            ;Rotate right through carry
         SBIW      R24,0x00       ;Subtract immediate from word
         BRNE      PC-0x0C        ;Branch if not equal
         MOV       R25,R21        ;Copy register
         MOV       R24,R0         ;Copy register
         RET                      ;Subroutine return

Global_Interrupt_Disable:
         CLI                      ;Global Interrupt Disable
         RJMP      PC-0x0000      ;Relative jump

JoyStickTbl: 
;.DB "Select Pressed!",0x0D
;Select Pressed!
         .dw 0x6553 ; Se
         .dw 0x656C ; le
         .dw 0x7463 ; ct
         .dw 0x5020 ;  P
         .dw 0x6572 ; re
         .dw 0x7373 ; ss
         .dw 0x6465 ; ed
         .dw 0x2120 ; !
         .dw    0xD
;Right Pressed
;.DB "Right Pressed!",0x0D
         .dw 0x6952 ; Ri
         .dw 0x6867 ; gh
         .dw 0x2074 ; t
         .dw 0x7250 ; Pr
         .dw 0x7365 ; es
         .dw 0x6573 ; se
         .dw 0x2064 ; d
         .dw  0xD21 ;  !
;Left Pressed!
;.DB "Left Pressed!",0x0D
         .dw 0x4C00 ;  L
         .dw 0x6665 ; ef
         .dw 0x2074 ; t
         .dw 0x7250 ; Pr
         .dw 0x7365 ; es
         .dw 0x6573 ; se
         .dw 0x2064 ; d
         .dw  0xD21 ; !
;Down Pressed!
;.DB "Down Pressed!",0x0D
         .dw 0x4400 ;  D
         .dw 0x776F ; ow
         .dw 0x206E ; n
         .dw 0x7250 ; Pr
         .dw 0x7365 ; es
         .dw 0x6573 ; se
         .dw 0x2064 ; d
         .dw  0xD21 ; !
;Up Pressed!
;.DB "Up Pressed!",0x0D
         .dw 0x5500 ;  U
         .dw 0x2070 ; p
         .dw 0x7250 ; Pr
         .dw 0x7365 ; es
         .dw 0x6573 ; se
         .dw 0x2064 ; d
         .dw  0xD21 ; !
;Hellow from AT90USB162!
;.DB "Hellow from AT90USB162!",0x0D
         .dw 0x4800 ;  H
         .dw 0x6C65 ; el
         .dw 0x6F6C ; lo
         .dw 0x6620 ;  f
         .dw 0x6F72 ; ro
         .dw 0x206D ; m
         .dw 0x5441 ; AT
         .dw 0x3039 ; 90
         .dw 0x5355 ; US
         .dw 0x3142 ; B1
         .dw 0x3236 ; 62
         .dw 0x2120 ;  !
         .dw    0xD
         ;         
		 .dw   0x20
         .dw  0x194 ; "
         .dw	 0
         .dw  0xFF53; 
;A088B:   FF53        SBRS      R21,3          Skip if bit in register set

