EmbeddedRelated.com
Forums

ASM to C code conversion...Help

Started by "GHORPADE, VIJAYA" April 15, 2010
Hi all..

I am new to MSP430. I am working on project which is completely written in Assembly language and I want to convert the same into C.

May I know how do I start for it, I already made flowcharts of the ASM code.

Another doubt is, if I wrote C code in IAR Kickstart, Is there any tool available for simulation of my code.

For example if my code is about to ON/OFF The led after 500ms then how do I check for delay time and port output toggling?
Please suggest guide or books for Embedded C.

Waiting for valuab;e replies..

Vijaya

________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.


Beginning Microcontrollers with the MSP430

Of course I don't know the details of your project, but I would question the efficiency and quality of a conversion from ASM to C. It's riddled with logistical problems.

I presume that you would like to translate and then make changes (otherwise, why would you translate). If you already know how it's supposed to work, why not just write it from scratch? You will probably end up with a much higher quality end-product rather than converting and "hacking" the code.

Translating from ASM to C is not really the same as translating English to Hindi, which is a "conceptual" interpretation. It's not even like translating binary to ASCII, which is a methodical 1-to-1 translation that can go in either direction. What you are actually doing is changing from one "methodology" to another, which will require a great deal of skill and many hours (days, weeks, years...) of debugging.

There may be some middle ground. If there are some critical sections written in assembly that you want to preserve, maybe you can write most of your code in C and embed these sections in assembly.

Now, if the ASM code was actually written originally in C, but you only have a compiled (into assembler) version (i.e. no source code), then the translation may be worth while. You're really just reverse engineering to reconstruct the C-code.

On top of this, as you are asking for Embedded C books, this project may be a real challenge, but I wish you the best of luck.

Summary: code it from scratch in C!

Stuart

--- In m..., "GHORPADE, VIJAYA" wrote:
>
> Hi all..
>
> I am new to MSP430. I am working on project which is completely written in Assembly language and I want to convert the same into C.
>
> May I know how do I start for it, I already made flowcharts of the ASM code.
>
> Another doubt is, if I wrote C code in IAR Kickstart, Is there any tool available for simulation of my code.
>
> For example if my code is about to ON/OFF The led after 500ms then how do I check for delay time and port output toggling?
> Please suggest guide or books for Embedded C.
>
> Waiting for valuab;e replies..
>
> Vijaya
>
> ________________________________
> The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
>
>

Or update it in asm

Al

Stuart_Rubin wrote:
> Of course I don't know the details of your project, but I would question the efficiency and quality of a conversion from ASM to C. It's riddled with logistical problems.
>
> I presume that you would like to translate and then make changes (otherwise, why would you translate). If you already know how it's supposed to work, why not just write it from scratch? You will probably end up with a much higher quality end-product rather than converting and "hacking" the code.
>
> Translating from ASM to C is not really the same as translating English to Hindi, which is a "conceptual" interpretation. It's not even like translating binary to ASCII, which is a methodical 1-to-1 translation that can go in either direction. What you are actually doing is changing from one "methodology" to another, which will require a great deal of skill and many hours (days, weeks, years...) of debugging.
>
> There may be some middle ground. If there are some critical sections written in assembly that you want to preserve, maybe you can write most of your code in C and embed these sections in assembly.
>
> Now, if the ASM code was actually written originally in C, but you only have a compiled (into assembler) version (i.e. no source code), then the translation may be worth while. You're really just reverse engineering to reconstruct the C-code.
>
> On top of this, as you are asking for Embedded C books, this project may be a real challenge, but I wish you the best of luck.
>
> Summary: code it from scratch in C!
>
> Stuart
>
> --- In m..., "GHORPADE, VIJAYA" wrote:
>> Hi all..
>>
>> I am new to MSP430. I am working on project which is completely written in Assembly language and I want to convert the same into C.
>>
>> May I know how do I start for it, I already made flowcharts of the ASM code.
>>
>> Another doubt is, if I wrote C code in IAR Kickstart, Is there any tool available for simulation of my code.
>>
>> For example if my code is about to ON/OFF The led after 500ms then how do I check for delay time and port output toggling?
>> Please suggest guide or books for Embedded C.
>>
>> Waiting for valuab;e replies..
>>
>> Vijaya
>>
>> ________________________________
>> The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
>>
>>
>
Thanks Stuart,

I am doing conversion from ASM to C is for code up-gradation purpose. The project assigned to me has around 14000lines written in assembly, though I m familiar with C converting it into C is bit complex. I am confused how to start with it as I m novice to Embedded C.

Initially I went through the system functioning as per the ASM code. Now I prepared flowchart of ASM code which is much clumsy. So, next step tp do is convert the same into C functionality wise.

Even if I divides the code functionality wise and start from scratch, then there will be again question of replication of ASM.

Vijaya
From: m... [mailto:m...] On Behalf Of OneStone
Sent: Friday, April 16, 2010 10:04 PM
To: m...
Subject: Re: [msp430] Re: ASM to C code conversion...Help

Or update it in asm

Al

Stuart_Rubin wrote:
> Of course I don't know the details of your project, but I would question the efficiency and quality of a conversion from ASM to C. It's riddled with logistical problems.
>
> I presume that you would like to translate and then make changes (otherwise, why would you translate). If you already know how it's supposed to work, why not just write it from scratch? You will probably end up with a much higher quality end-product rather than converting and "hacking" the code.
>
> Translating from ASM to C is not really the same as translating English to Hindi, which is a "conceptual" interpretation. It's not even like translating binary to ASCII, which is a methodical 1-to-1 translation that can go in either direction. What you are actually doing is changing from one "methodology" to another, which will require a great deal of skill and many hours (days, weeks, years...) of debugging.
>
> There may be some middle ground. If there are some critical sections written in assembly that you want to preserve, maybe you can write most of your code in C and embed these sections in assembly.
>
> Now, if the ASM code was actually written originally in C, but you only have a compiled (into assembler) version (i.e. no source code), then the translation may be worth while. You're really just reverse engineering to reconstruct the C-code.
>
> On top of this, as you are asking for Embedded C books, this project may be a real challenge, but I wish you the best of luck.
>
> Summary: code it from scratch in C!
>
> Stuart
>
> --- In m..., "GHORPADE, VIJAYA" wrote:
>> Hi all..
>>
>> I am new to MSP430. I am working on project which is completely written in Assembly language and I want to convert the same into C.
>>
>> May I know how do I start for it, I already made flowcharts of the ASM code.
>>
>> Another doubt is, if I wrote C code in IAR Kickstart, Is there any tool available for simulation of my code.
>>
>> For example if my code is about to ON/OFF The led after 500ms then how do I check for delay time and port output toggling?
>> Please suggest guide or books for Embedded C.
>>
>> Waiting for valuab;e replies..
>>
>> Vijaya
>>
>> ________________________________
>> The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
>>
>>
>
>
>
The Assembly code given to me..I went through it and divided same to functionality wise..Some functions are yet to get clear but got sufficient Idea to start with. The code involves subroutines such as Delay, Bcd2hex conversion, Hex to ASCII conv.etc. I have started with it. It als has Interfaces such as keypad 4X4matrix, LCD and switches.

As far as C is concern I am familiar with C but not that much expert in Embedded C. Reading '16bit microcontroller programming using C' by Jasio trying to get into depth.

From: m... [mailto:m...] On Behalf Of Dan Bloomquist
Sent: Monday, April 19, 2010 11:30 AM
To: m...
Subject: Re: [msp430] Re: ASM to C code conversion...Help

GHORPADE, VIJAYA wrote:
> Thanks Stuart,
>
> I am doing conversion from ASM to C is for code up-gradation purpose. The project assigned to me has around 14000lines written in assembly, though I m familiar with C converting it into C is bit complex. I am confused how to start with it as I m novice to Embedded C.
>
> Initially I went through the system functioning as per the ASM code. Now I prepared flowchart of ASM code which is much clumsy. So, next step tp do is convert the same into C functionality wise.
>
> Even if I divides the code functionality wise and start from scratch, then there will be again question of replication of ASM.
>

You know, it depends how the original code was written. You can write
really well done OO in asm, or the other extreme, put it in a pot and
stir it.

If you can get a handle on the outer structure of the code, that is the
place to start. I'll guess 14000 lines of asm is about some 5000 lines
of C, maybe more, maybe less. That is really not that much code. And it
may be that the asm code is so ill structured that trying to replicate
it is not even worth the effort.

Without knowing what you are starting with it would be very hard for an
outsider to help you with this conversion. Personally, if I did not have
a well documented implantation in front of me, I would just write what
ever you are doing mostly from scratch and most likely have it done in
less time than trying to 'save it'. But this also depends on the level
of C programing confidence you have on staff.

Best, Dan.
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.