473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

compile assemble to C- code ?

7
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?

Expand|Select|Wrap|Line Numbers
  1. ; set processor option ..........................
  2.  
  3.     Processor 16F84
  4.  
  5. ; Register Label Equates..........................
  6. PCL        EQU        02    ; Program counter
  7. PORTA    EQU        05        ; Port A 
  8. PORTB    EQU        06        ; Port B 
  9. Count     EQU        0C        ; Counter (1-6)
  10.  
  11. ; Register Bit Label Equates......................
  12. Roll     EQU        4        ; Push Button Input
  13.  
  14. ; Start Program...................................
  15.  
  16. ;Initialize (Default = Input)
  17. MOVLW    b'00000001'        ; Define RB1-7 outputs
  18. TRIS    PORTB            ; and set bit
  19. GOTO     reload            ; jump to main program
  20.  
  21. ; Table subroutine................................
  22. table     MOVF    Count,W    ; Put count in W
  23.         ADDWF    PCL    ; Add to Programm Counter 
  24.         NOP    
  25.         RETLW    00C        ; Display 1
  26.         RETLW    0B6        ; Display 2
  27.         RETLW    09E        ; Display 3
  28.         RETLW    0CC        ; Display 4
  29.         RETLW    0DA        ; Display 5
  30.         RETLW    0FA        ; Display 6
  31.  
  32. ; Main Loop.......................................
  33. reload    MOVLW    06        ; Reset counter 
  34.         MOVF    Count    ; to 6
  35.  
  36. start    BTFSC    PORTA,Roll    ;Test button
  37.         GOTO    nexnum        ; Jump if not presseed 
  38.         CALL    table        ; get display code 
  39.         MOVWF    PORTB        ; Output isplay Code
  40.         GOTO    start        ; start again
  41.  
  42. nexnum    DECFSZ    Count        ; Dec & Tets Count = 0?
  43.         GOTO    start        ; start again 
  44.         GOTO     reload        ; restart count if zero
  45.  
  46.         END
  47.  
Thanks for all your help in advance,
T
Apr 20 '08 #1
6 2158
weaknessforcats
9,208 Expert Mod 8TB
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.
Apr 20 '08 #2
Banfa
9,065 Expert Mod 8TB
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.
Apr 21 '08 #3
BigT
7
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.
Apr 21 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
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.
Apr 21 '08 #5
Banfa
9,065 Expert Mod 8TB
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).
Apr 21 '08 #6
BigT
7
Thanks again. Please close this post and i'll check back if get lost writing C with some code questions.

T
Apr 22 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: alphatan['a:lfa:ta2n] | last post by:
ASSUME: 1.There's no symbol table of my program. 2.gdb, is my only choice. 3.disassembly code of my program(snatch): 0x08048340 <main+24>: push $0x804840d 0x08048345 <main+29>: call ...
7
by: lxrocks | last post by:
Hi, I am looking for some C routines that disassemble/assemble MSN Messenger packets and more if possible. Are there any open / shareware tools around ? tks
10
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data...
1
by: Mike Walters | last post by:
Reading the current Namespace.Class, Assemble at runtime I am trying to get the Assemble, Namespace and Class name of a form at runtime. I have several assembles and namespaces in my app, I...
0
by: Just Me | last post by:
When I try to add an AddressControl usercontrol to a form I get the message. An exception occurred while trying to create an instance of AddressControlNS.AddressControl... The exception was...
4
by: mike | last post by:
I need to do a minor update to a 8051 program written in assembler in 1994 and assembled on a machine/language that no longer exists. I wrote the program, so I have some idea how it works. The...
3
by: starffly | last post by:
I overloaded operator+ in a class, and I want to invoke this operator in inline assemble like this: _asm call operator+ but it cannot be complied OK. compiler says there are some illegalI...
3
by: =?Utf-8?B?QWxleGFuZGVyIFd5a2Vs?= | last post by:
My application is taking way too long to build. It use to never take so long. I change only line and I think it recompiles all the classes in the assembly because it hangs forever. Here is the...
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.