Jump to content

Boostc Generates Wrong Shift Instructions

Recommended Posts

Bug description:

generates wrong code for shift operations


Steps to reproduce:

compile following example with boostc


#include <system.h>

unsigned int  counter, result;

void main()
 counter = 2457;
 counter = counter >> 3;   // division by 8
 result = counter;
 counter = counter << 3;   // multiply by 8
 result = counter;


Expected behaviour:

Compiler should generate a shift operation and not a rotate operation. for every right shift cycle the carry flag should be cleared.


	ORG 0x00000000
0000   158A            BSF PCLATH,3
0001   160A            BSF PCLATH,4
0002   D42F            GOTO	_startup
ORG 0x00001FD4
1FD4           _startup
1FD4          ; {
1FD4          ; }
1FD4   D52F            GOTO	main
ORG 0x00001FD5
1FD5           main; function begin
1FD5          ; {
1FD5          ; {
1FD5   9930            MOVLW	0x99
1FD6   A000            MOVWF gbl_counter
1FD7   0930            MOVLW	0x09
1FD8   A100            MOVWF gbl_counter+D'1'
1FD9          ; }
1FD9          ; {
1FD9   2008            MOVF gbl_counter, W
1FDA   A400            MOVWF CompTempVar6
1FDB   2108            MOVF gbl_counter+D'1', W
1FDC   A500            MOVWF CompTempVar7
1FDD   0310            BCF STATUS,C
1FDE   A50C            RRF CompTempVar7
1FDF   A40C            RRF CompTempVar6
1FE0   A50C            RRF CompTempVar7
1FE1   A40C            RRF CompTempVar6
1FE2   A50C            RRF CompTempVar7
1FE3   240C            RRF CompTempVar6, W
Pseudo instruction:INSTR_RSHIFT_VAL_TO_W not available on target!
1FE4   A000            MOVWF gbl_counter
1FE5   2508            MOVF CompTempVar7, W
1FE6   A100            MOVWF gbl_counter+D'1'
1FE7          ; }
1FE7          ; {
1FE7   2008            MOVF gbl_counter, W
1FE8   A200            MOVWF gbl_result
1FE9   2108            MOVF gbl_counter+D'1', W
1FEA   A300            MOVWF gbl_result+D'1'
1FEB          ; }
1FEB          ; {
1FEB   2008            MOVF gbl_counter, W
1FEC   A400            MOVWF CompTempVar8
1FED   2108            MOVF gbl_counter+D'1', W
1FEE   A500            MOVWF CompTempVar9
1FEF   0310            BCF STATUS,C
1FF0   A40D            RLF CompTempVar8
1FF1   A50D            RLF CompTempVar9
1FF2   A40D            RLF CompTempVar8
1FF3   A50D            RLF CompTempVar9
1FF4   A40D            RLF CompTempVar8
1FF5   A50D            RLF CompTempVar9
1FF6   2408            MOVF CompTempVar8, W
1FF7   A000            MOVWF gbl_counter
1FF8   2508            MOVF CompTempVar9, W
1FF9   A100            MOVWF gbl_counter+D'1'
1FFA          ; }
1FFA          ; {
1FFA   2008            MOVF gbl_counter, W
1FFB   A200            MOVWF gbl_result
1FFC   2108            MOVF gbl_counter+D'1', W
1FFD   A300            MOVWF gbl_result+D'1'
1FFE          ; }
1FFE   0800            RETURN
1FFF          ; }
1FFF          ; main function end - Exit PCLATH/Uncertainty: 0x3:0x0





SourceBoost DE version: 5.6.1

Compiler: BoostC 1.1 Alpha


Remark: C2C generates correct code for this example

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.

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.

  • Create New...