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? -
; 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
6 2158
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.
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.
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.
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.
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).
Thanks again. Please close this post and i'll check back if get lost writing C with some code questions.
T
Sign in to post your reply or Sign up for a free account.
Similar topics
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 ...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 :
$...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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...
| |