Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8048 code translation

Status
Not open for further replies.

DrWhoF

Advanced Member level 1
Joined
May 6, 2005
Messages
402
Helped
24
Reputation
48
Reaction score
11
Trophy points
1,298
Activity points
4,388
How difficult is to translate code (2kB) from 8048 to 8051?
Are there any tools available for this operation?
Thanks
DrWho
 

It depends on the code itself... Not necessarily straighforward.

The 2kB is size of the source or binary?

wek

[EDIT] oh yes, and also depends on the surrounding circuitry, for example if it uses the expander or not...[/EDIT]
 

I don't think there is a tool that can directly translate from 8048 to 8051 ..
This excercise may not be that difficult as both micros "share" a lot of common features ..
Firstly, use a 8048 disassembler ( if you don't have one here is a link: **broken link removed** ).
Starting from this stage you will have to do the analysis of the code line-by-line by yourself and name addresses one-by-one by yourself so later you will use them in the re-writting this code in 8051 format ..
Also handy will be printed out sets of codes for both MCUs ..
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
The code is 2kB binary.
I used disassembler but it is not easy job to make sense from this file.
Will someone be able to give me a hand with this translation?
I can ZIP this file and post it here or e-mail it.
Thanks.
DrWho
 

Well, the code itself without the knowledge of connected peripherals is of little use and can be hardly deciphered it's purpose... So I can help you, but you need to provide also schematics and description of function...

wek
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Please post the original BIN file as ZIP and describe what is/was connected to microcontroller pins ..
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Attached is ZIP with the code.
Here are the hardware connections:

AD0-AD7 - RTC6818, ALE, RD,WR

Port1 (P1.0-P1.6) - 8-button keypad

P2.7 - uPD6145 CS
P2.6 - uPD6145 STB
P2.5 - uPD6145 CLK
P2.4 - uPD6145 DATA

Thanks.
DrWho
 

You seem to be lucky here. No interrupts, no expander.
I just run through the disassembled code and I have seen nothing special in it, it should translate straighforwardly. Kick out the orgs, replace movp3 by movc a,@a+dptr (dptr set to the table beginning, originally at 300h), replace jbN by jb acc.N (N=0..7), replace the sel rbN by setting the appropriate bit for register banks in PSW, replace outl/in Pn by mov into/from appropriate port SFR, and you are roughly done - I don't think it should take more than a couple of hours.

Possible caveats:
- pinout difference between '51 and '48 (you are certainly aware of it)
- timing of the connected peripherals (check out the datasheets)
- timing in the program - there are some parts with nops in it, obviously for timing purposes
- purpose of the table - I did not attempt to understand it, but it seems that the table extends up to 033d (although the end of it can be interpreted also as code, but there are no references to that code).

Good luck!

wek
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
I would replace XOR+JZ, XOR+JNZ by CJNE (not essential) ..
The tables look like Months (30, 31 for normal months, or 28, 29 for February) and Leap Years (0, 4, 8 ..), so you can declare them as DBs anywhere you like, not necessarily at that page 3 address ..
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
IanP said:
I would replace XOR+JZ, XOR+JNZ by CJNE (not essential) ..
Well, generally, I would NOT do that... Although here this does not seem to be the issue, XOR does not modify the carry flag while CJNE does... Also, the software might make use of the implicit zero accumulator later on... And the few bytes' spare in program memory does not justify it...
IanP said:
The tables look like Months ... and Leap Years
Wow, a lot of experience you have IanP, don't you... Now I understand, thanks... Of course it does not need to be at 0300h (it would be a pain to keep it there), just the real address of it should be loaded to dptr prior using movc for table lookup.

wek
 

Will you be able to help me with this?
Can you post some lines of original and converted codes?
Thanks.
DrWho
 

Well, if you are not able to figure it out yourself (and it is really easy), I doubt you will be able to cope with the caveats I was talking about...

In the attached zipfile you will find the raw disassembled file and the "translated" one. As you can see, it took some 13 minutes... (writing this might take more...) Of course, it's upon you to make it working, no guarantee given :)

wek
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Thanks to WEK the 8051 code looks fine ..
Just one small thing:
In 8051 after reset SP=07h and all RAM cells are cleared ..
As in the end of the code you switch from one register bank to another instead of clearing RAM (address X0007) load SP with something like 40h .. 50h ..
This will ensure that you will always come back from CALL in CALL in CALL and PUSH PUSH PUSH .. situation ..
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
IanP said:
In 8051 after reset [...] all RAM cells are cleared ..
It is a common misconception that the 8051 zeroes RAM at reset. Please read the '51 "bibles" and datasheets - it does NOT clear or set anything except specified SFR locations. This misconception comes from a common practice of C-compilers which by default do clear the whole RAM as a first thing afer reset.

IanP said:
As in the end of the code you switch from one register bank to another instead of clearing RAM (address X0007) load SP with something like 40h .. 50h ..
Absolutely no need to do this. The '48 stack is exactly 16 bytes deep and range from RAM locations 08 to 23. This is the same as in the '51, by default the SP is 7 but it increments prior save so the stack grows from 08 up (they indeed considered '48 to '51 migration issues at Intel, no wonder...). The caveat would be that at overflow in '48 the stack wraps around while at '51 grows above 24, which is the register bank where I switch (as in '48 the second bank is exactly at 24) ... But that would be a perverse (ab)use of stack, wouldn't it? I don't expect it will happen here.

Just a note, there is no PUSH/POP on '48 so definitively no problem with that.

wek
 

It looks like most of crutial information on the system parameters is hold in the 6818 RAM (0Eh, 0Fh, ..)
In the case of this program there are limited number of cells used as flags/data bytes, so in my oppinion there is no need of clearing the whole memory area ..

As far as the SP is concerned, unless someone knows the code all the way through, I would advice to shift the SP to an unused region and have this issue solved for ever ..

Regard,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
IanP said:
In the case of this program there are limited number of cells used as flags/data bytes, so in my oppinion there is no need of clearing the whole memory area ..
No need to clear anything implicitly, nevertheless the program clears it anyway... the following is the original startup code:
Code:
reset:	mov	a,#0ffh
	outl	p1,a
	clr	c
	mov	r0,#7fh
	clr	a
X0007:	mov	@r0,a
	djnz	r0,X0007

IanP said:
As far as the SP is concerned, unless someone knows the code all the way through, I would advice to shift the SP to an unused region and have this issue solved for ever ..
As I mentioned, the 08-23 area IS safe as it is the original position of the stack in '48.
There are numerous indirect operations into the IRAM in the program, so unless it is thoroughly deciphered I would NOT move the stack elsewhere... except if it would be ported to a '52, then the stack could be absolutely safely moved to the area above 7Fh.

wek
 

You probably take all of this stuff to personal ..
If you think you are right ---> so be it ..
Regards,
IanP
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top