Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

right shift issue #7

Open
tpircher-zz opened this issue Apr 8, 2017 · 1 comment
Open

right shift issue #7

tpircher-zz opened this issue Apr 8, 2017 · 1 comment

Comments

@tpircher-zz
Copy link

I think I'm running into a problem with the right-shift operation. It seems that the rrc operation in-fills zeros or ones, independently of the carry flag.

I'm trying to emulate the following C code:

#include <stdlib.h>
#include <stdint.h>

void xprintf(const char *fmt, unsigned int val)
{
    (void)fmt;
    volatile unsigned int xxx = val;
    (void)xxx;
}

int main(void)
{
    volatile uint16_t val1 = 0xf001;
    volatile uint16_t val2 = 0x4f85;
    xprintf("res: %#x\n", val1 ^ (val2>>4));

    return 0;
}

I think I run into a problem with the right-shift (val2>>4). This code is compiled as:

    c04a:       b4 40 85 4f     mov     #20357, -4(r4)  ;#0x4f85, 0xfffc(r4)
    c04e:       fc ff 
    c050:       1f 44 fc ff     mov     -4(r4), r15     ;0xfffc(r4)
    c054:       12 c3           clrc
    c056:       0f 10           rrc     r15
    c058:       12 c3           clrc
    c05a:       0f 10           rrc     r15
    c05c:       12 c3           clrc
    c05e:       0f 10           rrc     r15
    c060:       12 c3           clrc
    c062:       0f 10           rrc     r15

In the online emulator I get the sequence of values of:

0x4f85
0xa7c2
0xd4e1
0x69f0
0xb4f8

I.e. sometimes I get a zero infill, sometimes I get a 1 infill, even though the carry flag should be cleared by the clrc instruction.

I compile with msp430-gcc version 4.6.3:

msp430-gcc -mmcu=msp430g2553 -O0 -g -W -Wall -std=c99   -c -o main.o main.c
msp430-gcc -mmcu=msp430g2553 -O0 -g -o firmware.elf main.o
@RudolfGeosits
Copy link
Owner

tpircher,

Thank you for bringing this bug to my attention, I'll be taking a look at it this week!

  • Rudolf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants