: : Hi all,
: : i have a piece of program written in assembly. I have to rewrite it
: : to C, but i dont know how, can somebody help me with it ?
: :
: :
: : unsigned int iz32prvi( //read word from nonvolatile data buffer
: : TNVVar *nvv, // pointer to nonvolatile memory
: : UINT16 dat) // address of doulbe word in nonvolatile memory
: : {
: : UINT16 vh1 = dat;
: : unsigned int bla=0;
: : asm {
: : LDD 7,SP
: : ADDD 2,SP
: : TFR D,X
: : LDD 0,X
: : STD 0,SP
: : }
: :
: : return bla;
: : }
: : : :
: : Thx and best regards,
: : BoSCHoW.
: :
: Well, in the absence of context it is not easy to disassmeble this
: code, even assuming you know the processor. Who wrote the code as
: they should know what it is doing?
: If you don't know, then a literal disassembly by hand may well be
: wrong, but here goes (mind you my background is 6800/6802 not 6812):
: LDD 7,SP 'Load D (16-bit Accumulator) Indexed Indirect from the
: stack pointer (the 7 is probably an offset from the SP value).
: ADDD 2,SP 'Add D Indexed Indirect from the stack pointer (offset of
: 2)
: TFR D,X 'Transfer the result to the Index Register.
: LDD 0,X ' Load D with the value from the memory location in the
: Index Register, no offset
: STD 0,SP 'Store it in the location given by the stack pointer
:
: Mind you, as I said I am not familiar with anything near as new as
: this chip (but starting to update) after not doing 6800 assembly
: since 1985 or so. It seems highly odd to me that you would
: calculate an address from old stack values, grab that value then
: shove it on the stack; that is too dangerous for my style, but hey
: whatever thrills you.
P.S. I should have added that you need to get the right resources for the CPU chip. Download from freescale.com the CPU12RM and CPU12RG/D, they're PDF and free. That'll make you more independent as well.
It would also help in future if you provided more information. As I said, code without context is risky to work with. Almost all of the traffic on your question has been trying to identify the CPU and gain the required information to help you.