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

Add test bin for renesas rx #146

Merged
merged 1 commit into from
Feb 14, 2024
Merged

Add test bin for renesas rx #146

merged 1 commit into from
Feb 14, 2024

Conversation

Heersin
Copy link
Member

@Heersin Heersin commented Feb 14, 2024

compiled from

#include <stdio.h>
#include <string.h>

char *MORSE_CODE[] = {
    ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
    ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",
    "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."
};

void text_to_morse(char *text) {
    while(*text) {
        if(*text >= 'a' && *text <= 'z') {
            printf("%s ", MORSE_CODE[*text - 'a']);
        } else if(*text >= 'A' && *text <= 'Z') {
            printf("%s ", MORSE_CODE[*text - 'A']);
        } else {
            printf(" ");
        }
        text++;
    }
    printf("\n");
}

void morse_to_text(char *morse) {
    char *token = strtok(morse, " ");
    while(token) {
        for(int i = 0; i < 26; i++) {
            if(strcmp(token, MORSE_CODE[i]) == 0) {
                printf("%c", 'A' + i);
                break;
            }
        }
        token = strtok(NULL, " ");
    }
    printf("\n");
}

int main() {
    char text[] = "Hello World";
    text_to_morse(text);

    char morse[] = ".... . .-.. .-.. --- / .-- --- .-. .-.. -..";
    morse_to_text(morse);

    return 0;
}

command: ./rx-elf-gcc -mcpu=rx610 morse.c -o morse

@XVilka XVilka merged commit 0e73954 into rizinorg:master Feb 14, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants