Jump to content

Right Shifting, Redundant Code


Recommended Posts

Rignt shifting an unsigned long right 4 or more bits, except multiples of 8 :) , creates 12 redundant program words to the assembler code at beginning of the statement.

 

#include <system.h>

unsigned long	mylong;

void main(void) {

mylong = 0x12345678;
0003  3078	  MOVLW 0x78
0004  1283	  BCF STATUS, RP0
0005  1303	  BCF STATUS, RP1
0006  00A0	  MOVWF gbl_mylong
0007  3056	  MOVLW 0x56
0008  00A1	  MOVWF gbl_mylong+D'1'
0009  3034	  MOVLW 0x34
000A  00A2	  MOVWF gbl_mylong+D'2'
000B  3012	  MOVLW 0x12
000C  00A3	  MOVWF gbl_mylong+D'3'

mylong >>= 4;
000D  3000	  MOVLW 0x00
000E  3800	  IORLW 0x00
000F  3800	  IORLW 0x00
0010  39FF	  ANDLW 0xFF
0011  1903	  BTFSC STATUS,Z
0012  2819	  GOTO	label268438905
0013  0D23	  RLF gbl_mylong+D'3', W
0014  01A0	  CLRF gbl_mylong
0015  01A1	  CLRF gbl_mylong+D'1'
0016  01A2	  CLRF gbl_mylong+D'2'
0017  01A3	  CLRF gbl_mylong+D'3'
0018  281C	  GOTO	label268438907
0019		label268438905
0019  3004	  MOVLW 0x04
001A  00A4	  MOVWF CompTempVar495
001B  08A4	  MOVF CompTempVar495, F
001C		label268438907
001C  1903	  BTFSC STATUS,Z
001E  1003	  BCF STATUS,C
001F  0CA3	  RRF gbl_mylong+D'3', F
0020  0CA2	  RRF gbl_mylong+D'2', F
0021  0CA1	  RRF gbl_mylong+D'1', F
0022  0CA0	  RRF gbl_mylong, F
0023  03A4	  DECF CompTempVar495, F
0024  281C	  GOTO	label268438907

}

 

Using BoostC 6.81, WinXP Pro XP2.

 

Cheers

 

Reynard

Link to post
Share on other sites
  • 3 years later...

Hi Dave, Pavel,

 

Has there been any thought on this redundant code generation when using shifts on longs.

 

3 years down the line and it is still present in 7.04.

 

void main (void)
{
unsigned long id;
id = id << 8;
0008  6A05	   CLRF CompTempVar574
000A  5001	   MOVF main_1_id, W
000C  6E06	   MOVWF CompTempVar575
000E  5002	   MOVF main_1_id+D'1', W
0010  6E07	   MOVWF CompTempVar576
0012  5003	   MOVF main_1_id+D'2', W
0014  6E04	   MOVWF main_1_id+D'3'
0016  5005	   MOVF CompTempVar574, W
0018  6E01	   MOVWF main_1_id
001A  5006	   MOVF CompTempVar575, W
001C  6E02	   MOVWF main_1_id+D'1'
001E  5007	   MOVF CompTempVar576, W
0020  6E03	   MOVWF main_1_id+D'2'
id = id >> 8;
0022  5002	   MOVF main_1_id+D'1', W
0024  6E05	   MOVWF CompTempVar578
0026  5003	   MOVF main_1_id+D'2', W
0028  6E06	   MOVWF CompTempVar579
002A  5004	   MOVF main_1_id+D'3', W
002C  6E07	   MOVWF CompTempVar580
002E  6A08	   CLRF CompTempVar581
0030  5005	   MOVF CompTempVar578, W
0032  6E01	   MOVWF main_1_id
0034  5006	   MOVF CompTempVar579, W
0036  6E02	   MOVWF main_1_id+D'1'
0038  5007	   MOVF CompTempVar580, W
003A  6E03	   MOVWF main_1_id+D'2'
003C  5008	   MOVF CompTempVar581, W
003E  6E04	   MOVWF main_1_id+D'3'
id <<= 8;
0040  84D8	   BSF STATUS,Z
0042  E104	   BNZ label1
0044  84D8	   BSF STATUS,Z
0046  E102	   BNZ label1
0048  84D8	   BSF STATUS,Z
004A  E005	   BZ label2
004C		    label1
004C  6A01	   CLRF main_1_id
004E  6A02	   CLRF main_1_id+D'1'
0050  6A03	   CLRF main_1_id+D'2'
0052  6A04	   CLRF main_1_id+D'3'
0054  D00A	   BRA label4
0056		    label2
0056  0E08	   MOVLW 0x08
0058		    label3
0058  0BFF	   ANDLW 0xFF
005A  E007	   BZ label4
005C  90D8	   BCF STATUS,C
005E  3601	   RLCF main_1_id, F
0060  3602	   RLCF main_1_id+D'1', F
0062  3603	   RLCF main_1_id+D'2', F
0064  3604	   RLCF main_1_id+D'3', F
0066  0FFF	   ADDLW 0xFF
0068  D7F7	   BRA label3
006A		    label4
id >>= 13;
006A  0E00	   MOVLW 0x00
006C  0900	   IORLW 0x00
006E  0900	   IORLW 0x00
0070  0BFF	   ANDLW 0xFF
0072  E006	   BZ label5
0074  3404	   RLCF main_1_id+D'3', W
0076  6A01	   CLRF main_1_id
0078  6A02	   CLRF main_1_id+D'1'
007A  6A03	   CLRF main_1_id+D'2'
007C  6A04	   CLRF main_1_id+D'3'
007E  D003	   BRA label6
0080		    label5
0080  0E0D	   MOVLW 0x0D
0082  6E05	   MOVWF CompTempVar582
0084  5205	   MOVF CompTempVar582, F
0086		    label6
0086  B4D8	   BTFSC STATUS,Z
008A  90D8	   BCF STATUS,C
008C  3204	   RRCF main_1_id+D'3', F
008E  3203	   RRCF main_1_id+D'2', F
0090  3202	   RRCF main_1_id+D'1', F
0092  3201	   RRCF main_1_id, F
0094  0605	   DECF CompTempVar582, F
0096  D7F7	   BRA label6

}

 

Cheers

 

Reynard

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...