Pyastra - Python code translator to assembler for PIC architecture

    Pyastra is a translator of Python code to assembler. It takes a source file written in Python and, if the code contains no errors, it generates an assembler file that you can compile into a HEX file using your favorite PIC assembler (gpasm, mpasm or others compatible with them).

    image

    image

    Supported microcontrollers and processors


    All microcontrollers of the PIC12, PIC14 and PIC16 family.

    Example


    Source code (Port A, pin 0 flashes endlessly):

    while(1):
        PORTA[0] = 1
        for i in xrange(0,255):
            pass
        PORTA[0] = 0
        for i in xrange(0,255):
            pass


    Assembly code output

    ;
    ; Generated by pyastra 0.0.1
    ; infile: led_blink.py
    ;
            processor       16c432
            #include        p16c432.inc
    _lshift_left    equ     0x20    ;bank 0
    _lshift_right   equ     0x21    ;bank 0
    _rshift_left    equ     0x22    ;bank 0
    _rshift_right   equ     0x23    ;bank 0
    _mul_left       equ     0x24    ;bank 0
    _mul_right      equ     0x25    ;bank 0
    mul_cntr        equ     0x26    ;bank 0
    mul_res equ     0x27    ;bank 0
    _div_left       equ     0x28    ;bank 0
    _div_right      equ     0x29    ;bank 0
    div_cntr        equ     0x2a    ;bank 0
    div_buf equ     0x2b    ;bank 0
    _mod_left       equ     0x2c    ;bank 0
    _mod_right      equ     0x2d    ;bank 0
    mod_cntr        equ     0x2e    ;bank 0
    mod_buf equ     0x2f    ;bank 0
    _pow_left       equ     0x30    ;bank 0
    _pow_right      equ     0x31    ;bank 0
    pow_res equ     0x32    ;bank 0
    pow_buf equ     0x33    ;bank 0
    pow_cntr        equ     0x34    ;bank 0
    stack0  equ     0x35    ;bank 0
    _i      equ     0x36    ;bank 0
    stack1  equ     0x37    ;bank 0
    stack2  equ     0x38    ;bank 0
    stack3  equ     0x39    ;bank 0
    stack4  equ     0x3a    ;bank 0
            org     0x0
            goto    main
            org     0x5
    main
    label0
            movlw   0x1
            bcf     STATUS, RP0
            movwf   stack0
            bcf     STATUS, RP0
            btfsc   STATUS, Z
            goto    label1
            bcf     STATUS, RP0
            bsf     PORTA,  0
            bcf     STATUS, RP0
            clrf    _i
            movlw   0xff
            bcf     STATUS, RP0
            movwf   stack2
            bcf     STATUS, RP0
            movwf   st
    label2
            bcf     STATUS, RP0
            movf    stack1, w
            bcf     STATUS, RP0
            subwf   _i,     w
            bcf     STATUS, RP0
            btfsc   STATUS, Z
            goto    label3
            bcf     STATUS, RP0
            btfsc   STATUS, C
            goto    label3
    label4
            bcf     STATUS, RP0
            incf    _i,     f
            goto    label2
    label3
            bcf     STATUS, RP0
            bcf     PORTA,  0
            bcf     STATUS, RP0
            clrf    _i
            movlw   0xff
            bcf     STATUS, RP0
            movwf   stack4
            bcf     STATUS, RP0
            movwf   stack3
    label5
            bcf     STATUS, RP0
            movf    stack3, w
            bcf     STATUS, RP0
            subwf   _i,     w
            bcf     STATUS, RP0
            btfsc   STATUS, Z
            goto    label6
            bcf     STATUS, RP0
            btfsc   STATUS, C
            goto    label6
    label7
            bcf     STATUS, RP0
            incf    _i,     f
            goto    label5
    label6
            goto    label0
    label1
            goto    $
            end


    Official site: pyastra.sourceforge.net
    You can download from here: sourceforge.net/projects/pyastra/files

    Also popular now: