Porting guide - Assembler to C

  • Follow


Hi everyone,

My current job is porting assembler sources to C.
So currently I spend a lot of time for fighting with assembler...

Is there any document, book or something about porting guide ?
Or there is good book about low level C programming
to interoperate with assembler ?

Thank you for your reading and help.
Have a nice day. bye.


0
Reply Park 4/26/2005 5:31:30 PM

> Is there any document, book or something about porting guide ?
> Or there is good book about low level C programming
> to interoperate with assembler ?

My book discusses assembly language in a way that is heavily influenced 
by C (calling convention, linking, etc.).  In addition, it has an 
appendix containing C<->Assembly language idioms.

http://www.cafeshops.com/bartlettpublish.8640017

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017

0
Reply Jonathan 4/26/2005 8:10:26 PM


Park, Taehoon wrote:

> My current job is porting assembler sources to C.
> So currently I spend a lot of time for fighting with assembler...
> 
> Is there any document, book or something about porting guide ?
> Or there is good book about low level C programming
> to interoperate with assembler ?

When you say "assembler sources" do you mean 1. assembly code
written by a human being or 2. assembly code produced by an
optimizing compiler?

Because translating optimized assembly code *back* to C code
is like trying to turn hamburger into a cow.

:-�

0
Reply Grumble 4/26/2005 9:05:25 PM

Park, Taehoon wrote:
> Hi everyone,
>
> My current job is porting assembler sources to C.
> So currently I spend a lot of time for fighting with assembler...
>
> Is there any document, book or something about porting guide ?
> Or there is good book about low level C programming
> to interoperate with assembler ?
>
> Thank you for your reading and help.
> Have a nice day. bye.


Here is some stuff you might be interested in. It's largely for the
other direction (C->assembly), but it should give you some ideas.
http://webster.cs.ucr.edu/Page_win32/WindowsAsmPgm/html/Ch03.html

Kris Kaspersky's "Hacker Disassembling Uncovered" also covers this
subject from the c->assembly perspective (though it's more geared
towards reverse engineering code).

Cheers,
Randy Hyde

0
Reply randyhyde 4/26/2005 11:32:03 PM

"Grumble" <devnull@kma.eu.org> wrote in message
news:426eabb0$0$26251$636a15ce@news.free.fr...
> Park, Taehoon wrote:
>
> > My current job is porting assembler sources to C.
> > So currently I spend a lot of time for fighting with assembler...
> >
> > Is there any document, book or something about porting guide ?
> > Or there is good book about low level C programming
> > to interoperate with assembler ?
>
> When you say "assembler sources" do you mean 1. assembly code
> written by a human being or 2. assembly code produced by an
> optimizing compiler?
>
> Because translating optimized assembly code *back* to C code
> is like trying to turn hamburger into a cow.
>
> :-�
>

Hi. It is written by human being.
I want to know tips and guide for porting.
Please look below codes. How can I porting these to C?

DATALIST    DW SIZE_DATA
  DW 0
  DW 1
  DW 2
  DW 3
  DW 0FFFFH   ;TERMINATOR

SIZE_DATA EQU $-(DATALIST+2)

This is a WORD array definition. It use Label technique.
Do you have any idea? Thank you for your reading.


0
Reply Park 4/27/2005 2:11:07 AM

Park, Taehoon wrote:

> Hi. It is written by human being.
> I want to know tips and guide for porting.
> Please look below codes. How can I porting these to C?
> 
> DATALIST    DW SIZE_DATA
>   DW 0
>   DW 1
>   DW 2
>   DW 3
>   DW 0FFFFH   ;TERMINATOR
> 
> SIZE_DATA EQU $-(DATALIST+2)
> 
> This is a WORD array definition. It use Label technique.
> Do you have any idea? Thank you for your reading.

(I am no expert.) I'd write something like

#include <stdint.h>

int16_t datalist[] = { 0, 1, 2, 3, -1 };
int16_t size_data = (sizeof datalist / sizeof *datalist) - 1;

-- 
Regards, Grumble

0
Reply Grumble 4/27/2005 9:42:03 AM

Grumble wrote:

> Park, Taehoon wrote:
> 
>> Hi. It is written by human being.
>> I want to know tips and guide for porting.
>> Please look below codes. How can I porting these to C?
>>
>> DATALIST    DW SIZE_DATA
>>   DW 0
>>   DW 1
>>   DW 2
>>   DW 3
>>   DW 0FFFFH   ;TERMINATOR
>>
>> SIZE_DATA EQU $-(DATALIST+2)
>>
>> This is a WORD array definition. It use Label technique.
>> Do you have any idea? Thank you for your reading.
> 
> (I am no expert.) I'd write something like
> 
> #include <stdint.h>
> 
> int16_t datalist[] = { 0, 1, 2, 3, -1 };
> int16_t size_data = (sizeof datalist / sizeof *datalist) - 1;

Errr. (sizeof datalist / sizeof *datalist) is the number of elements
in the array. That number minus 1 ignores the terminator.

I think you want sizeof datalist - sizeof *datalist.

(I'm not sure why you'd want to ignore the size of the terminator.)

0
Reply Grumble 4/27/2005 10:00:25 AM

Grumble wrote:
> 
> Grumble wrote:
> 
> > Park, Taehoon wrote:
> >
> >> Hi. It is written by human being.
> >> I want to know tips and guide for porting.
> >> Please look below codes. How can I porting these to C?
> >>
> >> DATALIST    DW SIZE_DATA
> >>   DW 0
> >>   DW 1
> >>   DW 2
> >>   DW 3
> >>   DW 0FFFFH   ;TERMINATOR
> >>
> >> SIZE_DATA EQU $-(DATALIST+2)
> >>
> >> This is a WORD array definition. It use Label technique.
> >> Do you have any idea? Thank you for your reading.
> >
> > (I am no expert.) I'd write something like
> >
> > #include <stdint.h>
> >
> > int16_t datalist[] = { 0, 1, 2, 3, -1 };
> > int16_t size_data = (sizeof datalist / sizeof *datalist) - 1;
> 
> Errr. (sizeof datalist / sizeof *datalist) is the number of elements
> in the array. That number minus 1 ignores the terminator.
> 
> I think you want sizeof datalist - sizeof *datalist.
> 
> (I'm not sure why you'd want to ignore the size of the terminator.)

Hmmm, I'd interpret it as "size of size" that's being
ignored, rather than the terminator. Amounts to the same
thing, in this case, I guess. As I understand the original
code, "size_data" should be the first element of the array.
I'm not sure why we need both size and a terminator, but...

As I see it, the asm code shown doesn't give us any
information about whether this is signed or unsigned 16-bit
data. The fact that the terminator is expressed as 0FFFFh,
rather than -1, almost suggests unsigned. I think the only
way we can find out is to search through the code and see
how it's used. Is a "cmp" followed by "ja" or "jg"?... or
other clues. If we can't find any instances where the code
"cares" whether it's signed or unsigned, I guess it doesn't
matter. If values between 8000h and the (reserved)
terminator are to be treated as greater than zero, we don't
want to tell the compiler "signed", I don't think.

This may be a tougher question than it looks!

Best,
Frank

0
Reply Frank 4/27/2005 10:55:11 AM

Park, Taehoon wrote:
> "Grumble" <devnull@kma.eu.org> wrote in message
> news:426eabb0$0$26251$636a15ce@news.free.fr...
> > Park, Taehoon wrote:
> >
> > > My current job is porting assembler sources to C.
> > > So currently I spend a lot of time for fighting with assembler...
> > >
> > > Is there any document, book or something about porting guide ?
> > > Or there is good book about low level C programming
> > > to interoperate with assembler ?
> >
> > When you say "assembler sources" do you mean 1. assembly code
> > written by a human being or 2. assembly code produced by an
> > optimizing compiler?
> >
> > Because translating optimized assembly code *back* to C code
> > is like trying to turn hamburger into a cow.
> >
> > :-�
> >
>
> Hi. It is written by human being.
> I want to know tips and guide for porting.
> Please look below codes. How can I porting these to C?
>
> DATALIST    DW SIZE_DATA
>   DW 0
>   DW 1
>   DW 2
>   DW 3
>   DW 0FFFFH   ;TERMINATOR
>
> SIZE_DATA EQU $-(DATALIST+2)
>
> This is a WORD array definition. It use Label technique.
> Do you have any idea? Thank you for your reading.

SIZE_DATA EQU $-(DATALIST+2) resolves to 10d bytes by the assembler.

The structure likely needs to be static. [declared assembly data is
static, usually to the DSegment, although it could be in the code
segment as assembly can be free form.  This structure is a fixed array
of words.

static UWORD DataList[]={10,0,1,2,3,0xffff} /* my guess*/

You need to be careful about this data being always in scope of the
coverted C functions which access it.  Most likely those C functions
will need to access DataList by reference.

Since the first element of the array is the length of the useful data
[in bytes however], the array is more like a standard pascal array.
You need to watch carefully your pointer useage as the first element of
the array is 10, instead of the useful data 0.

FWIW.

0
Reply spamtrap 4/28/2005 1:54:16 AM

8 Replies
236 Views

(page loaded in 3.266 seconds)

Similiar Articles:













7/30/2012 9:26:17 AM


Reply: