compile assemble to C- code ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BigT
    New Member
    • Apr 2008
    • 7

    compile assemble to C- code ?

    I'm new to the world of C and try to start walking. I have below code in assemble language and would like to compile it in C. Can someone let me know how to and/ or do it?

    Code:
    ; set processor option ..........................
    
    	Processor 16F84
    	
    ; Register Label Equates..........................
    PCL		EQU		02	; Program counter
    PORTA	EQU		05		; Port A 
    PORTB	EQU		06		; Port B 
    Count 	EQU		0C		; Counter (1-6)
    
    ; Register Bit Label Equates......................
    Roll 	EQU		4		; Push Button Input
    
    ; Start Program...................................
    
    ;Initialize (Default = Input)
    MOVLW	b'00000001'		; Define RB1-7 outputs
    TRIS	PORTB			; and set bit
    GOTO 	reload			; jump to main program
    
    ; Table subroutine................................
    table 	MOVF	Count,W	; Put count in W
    		ADDWF	PCL	; Add to Programm Counter 
    		NOP	
    		RETLW	00C		; Display 1
    		RETLW	0B6		; Display 2
    		RETLW	09E		; Display 3
    		RETLW	0CC		; Display 4
    		RETLW	0DA		; Display 5
    		RETLW	0FA		; Display 6
    
    ; Main Loop.......................................
    reload	MOVLW	06		; Reset counter 
    		MOVF	Count	; to 6
    		
    start	BTFSC	PORTA,Roll	;Test button
    		GOTO	nexnum		; Jump if not presseed 
    		CALL	table		; get display code 
    		MOVWF	PORTB		; Output isplay Code
    		GOTO	start		; start again
    		
    nexnum	DECFSZ	Count		; Dec & Tets Count = 0?
    		GOTO	start		; start again 
    		GOTO 	reload		; restart count if zero
    		
    		END
    Thanks for all your help in advance,
    T
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    There are various disassemblers around. Google is your best bet. Of course, you will lose all the comments and the variable names.

    If I knew what trhe assembly does, I would just learn enough C to write it myself and skip the disassembler.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Please use code tags it makes you code easier to read.

      So this is a PIC micro-processor right? It looks like PIC assembler and I believe 16F84 is a PIC part. It looks like Port A is being configured as an input and the comment indicates an attached button and port B as an output, from the ouput values I would guess port B is connected to a 7 segment LED (or LCD?) digit display.

      Everytime the button is pressed it displays the next digit in sequence 1, 2, 3, 4, 5, 6 on the display looping back from 6 to 1.

      I doubt you will be able to find a dis-assembler to convert back to C, this looks to me to be directly written in assembler and is pulling tricks (in the table sub-routine) that are unlikely to have a conversion to C, that is directly altering the program counter to cause the program to execute a different return instruction to return a different value from the function.

      However the function of the program is so simple that I would have thought re-writing it in C would be a fairly simple matter even for someone with limited C experience.

      Comment

      • BigT
        New Member
        • Apr 2008
        • 7

        #4
        Thanks for taking the time and sending me some answers. Yes it is for a PIC 16F84 processor. I'll google and see if i find something. I'm not concerned loosing the text or comments.
        The problem is i got pretty much no knowledge of C. I learned assemble language but that is processor specific. I'll hit the books hard and see if i can put something together since Banfa said its a pretty easy routine.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by BigT
          The problem is i got pretty much no knowledge of C.
          C is a replacement for assembly language. You can learn C over a weekend. There are only 43 operators.

          If you keep your code simple you will be amazed how much you can do in a very short time. It is truly faster to write C than to write assembly.

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Originally posted by weaknessforcats
            If you keep your code simple you will be amazed how much you can do in a very short time. It is truly faster to write C than to write assembly.
            Not to mention once you know it you will be able to program for any microprocessor with a C compiler which nowadays most of them do have (if not a C++ compiler).

            Comment

            • BigT
              New Member
              • Apr 2008
              • 7

              #7
              Thanks again. Please close this post and i'll check back if get lost writing C with some code questions.

              T

              Comment

              Working...