Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!zaphod.mps.ohio-state.edu!ncar!ico!haddock!ima!esegue!compilers-sender From: ch@dce.ie (Charles Bryant) Newsgroups: comp.compilers Subject: Re: Help on disassembler/decompilers Keywords: disassemble, debug Message-ID: <1990Sep18.103653.24032@dce.ie> Date: 18 Sep 90 10:36:53 GMT References: <6839.26ea3b0e@vax1.tcd.ie> <3972@bingvaxu.cc.binghamton.edu> <1990Sep14.181616.26890@dce.ie> <4028@bingvaxu.cc.binghamton.edu> Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: ch@dce.ie (Charles Bryant) Organization: Datacode Communications Ltd, Dublin, Ireland Lines: 67 Approved: compilers@esegue.segue.boston.ma.us In article <4028@bingvaxu.cc.binghamton.edu> kym@bingvaxu.cc.binghamton.edu.cc.binghamton.edu (R. Kym Horsell) writes: >In article <1990Sep14.181616.26890@dce.ie> ch@dce.ie (Charles Bryant) writes: >>Well how would you translate this C function into Pascal. >>[simple linked list insertion] > >I'm not sure at what level to aim this so I'll play it straight. > >[pascal version using fixed size array] >It even duplicates the same bug as the original code! (:-) That's funny, I can't see any bug in the original. I can see a bug in the Pascal one though: when the list is empty new elements can't be inserted because 'head' is never changed. >Complaints about _efficiency_ can be countered by resorting to arguments re >code optimization ... Quite true. But one important property of the original is that it has no fixed limit. The Pascal version is limited by the space allocated in the array. If the array is big, space is wasted; and any fixed size may turn out to be too small. >[I suspect that the original author expected the Pascal version to use Pascal >pointers. My Pascal is rusty enough that I don't immediately see what the >problem is, other than perhaps the static list head. Any method can be used if the basic properties of the original code are preserved. One of these is that the list has no predetermined maximum size. As far as I can see this means pointers are necessary, but it is not possible to take the address of a variable in Pascal, so the case of an empty list must be treated specially, I'll use the array method here to make it easy to compare. begin if head=0 then begin head := newelem; mem[newelem].next := 0; end else begin p := head; break:= false; while (p<>0) and not break do if mem[p].item >= mem[newelem].item then break:=true; else p := mem[p].next; mem[newelem].next := mem[p].next; mem[p].next := newelem; end; end; >... This is a long way from decompiling assembler into >some language. -John] What I meant was that unless the decompiler produces code in the same language that the code was originally written in, it may have to produce things that bear no relation to the original code (nor the assembler). If the target language is less powerful that the original a decompilation may not be possible. (Well obviously you could write a program in the target language that emulated the machine that the assembly came from, but I wouldn't consider that to be decompilation). -- Charles Bryant (ch@dce.ie) -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.