Porting C code to m68k Assembly

For discussion and distribution of custom code and hacks
Post Reply
User avatar
Gampy
Posts: 2333
Joined: Sat Dec 15, 2018 7:38 am

Porting C code to m68k Assembly

Post by Gampy »

Hi all,

Anyone know how to convert this C code into assembly ??
I have used intermediate files to see how it assembles ...

C Instruction to convert to assembly

Code: Select all

#define HARDWARE_IO     (*(unsigned short *)(0xFFFFE2FA))
HARDWARE_IO |= 0x0001;
Intermediate files show it done like,

Code: Select all

move.l #-7430,%d0
move.l #-7430,%d1
move.l %d1,%a0
move.w (%a0),%d1
or.w #1,%d1
move.l %d0,%a0
move.w %d1,(%a0)
And the oppasite

Code: Select all

#define HARDWARE_IO     (*(unsigned short *)(0xFFFFE2FA))
HARDWARE_IO &= 0xFFFE;
Intermediate files show it done like,

Code: Select all

move.l #-7430,%d0
move.l #-7430,%d1
move.l %d1,%a0
move.w (%a0),%d1
and.w #-2,%d1
move.l %d0,%a0
move.w %d1,(%a0)
Cannot figure out what,
-7430
equates too. Normally I can figure this out, for some reason I cannot with this one!

This is where http://www.godbolt.org would be extremely handy if it did m68k, unfortunately it takes Linux to do the testing, I don't run Linux or I would add it, it is supposed to be easy to add by using another GNU implementation as a template.
An awesome task for a Linux user looking to help the community ...

To read the Howto on installing a new compiler, Select menu Other, then Wiki, and on the right sidebar of the Wiki, Select How to install a compiler.
Want to do it and need help, ask, I'll do whatever I can to help!

-Enjoy
Intelligence is in the details!

It is easier not to learn bad habits, then it is to break them!

If I was here to win a popularity contest, their would be no point, so I wouldn't be here!
yoda69
Posts: 1215
Joined: Sun Mar 15, 2009 10:20 am
cars: 2004 VYII Acclaim Wagon V6 Auto LPG/Petrol
2004 VYII Berlina sedan V6 Auto
2005 VZ Monaro CV8 manual
Location: Geelong, VIC

Re: Porting C code to m68k Assembly

Post by yoda69 »

Not that I understand the coding thought I’d throw it into ChatGPT and ask to convert the first one from C to M68K and it spat out the following:

MOVE.W #0xFFFF, A0 ; Load the base address of HARDWARE_IO into A0
MOVE.W #0xE2FA, D0 ; Load the offset of HARDWARE_IO into D0
ADD.L A0, D0 ; Add the offset to the base address to get the full address of HARDWARE_IO
MOVE.W (D0), D1 ; Load the current value of HARDWARE_IO into D1
ORI.W #0x0001, D1 ; Set the least significant bit of D1 to 1
MOVE.W D1, (D0) ; Write the new value of HARDWARE_IO back to memory

Note that this assumes a 16-bit m68k architecture, where the ori instruction is used to set the least significant bit of HARDWARE_IO to 1. If the architecture is different, the instructions may need to be modified accordingly.


Doesn’t help with your 7430 problem and not even sure it’s correct but was interesting to see it spat out commented code.
kur4o
Posts: 950
Joined: Sun Apr 10, 2016 9:20 pm

Re: Porting C code to m68k Assembly

Post by kur4o »

Code: Select all

move.w  (word_FFFFE2FA).w,d3
bset    #0,d3
move.w  d3,(word_FFFFE2FA).w

Test in a timed loop when bit5 fa19=1, if loop expires without=1 exit with a error
btst    #5,(word_FFFFFA19).w

Code: Select all

move.w  (word_FFFFE2FA).w,d3
bclr    #0,d3
move.w  d3,(word_FFFFE2FA).w

test bit5 fa19=0
btst    #5,(word_FFFFFA19).w
I see what you want to do, enable vpp voltage with that register.

Code compiler don`t need that IO defined, as it use it as a define for the cpu, cpu don`t care about it.

Here is example what need to be done with that register, basically switching a bit on/off.

It may be optimized or switch to C code that will do something like that. Read register switch bit on/off write to a register

On some pcms enable vpp all the time bogs VPW bus and is used only for a write event and than switched off.
In-Tech
Posts: 788
Joined: Mon Mar 09, 2020 4:35 pm
Location: California

Re: Porting C code to m68k Assembly

Post by In-Tech »

Hiya,
Shoot, I wish I had a bit of time. I love assembly. Equates for your assembler engine is your friend :) I will dig into it soon so I can hopefully help with some stuff. I had 5 boats to do up in the Delta near Stockton, CA, then went to Reno to do a couple vehicles. Feast or famine :thumbup:
72_C10.jpg
72_C10_LS3.jpg
Big_Tire.jpg
DD_Dash.jpg
HotRod.jpg
I was a bit grouchy till this happened. I count cards digitally in assembly :punk:
Jackpot.jpg
Jackpot.jpg (138.77 KiB) Viewed 4127 times
ironduke
Posts: 583
Joined: Thu Feb 13, 2020 11:32 pm
cars: Mainly GM trucks, a Cruze and an Equinox for dailys..

Re: Porting C code to m68k Assembly

Post by ironduke »

Nice pics...
As far as Grampy's problem.. I have the answer, sorta.. I can explain the 7430 at least..
It's -7430 decimal.. that is also 0xffffe2fa which is in your first statement..

Or did I misunderstand the question?? Happens often, lol..
User avatar
Gampy
Posts: 2333
Joined: Sat Dec 15, 2018 7:38 am

Re: Porting C code to m68k Assembly

Post by Gampy »

kur4o,
Thank you sir! It worked ... :D :D :thumbup:
See more below ...

yoda69,
Thank you sir!
In-Tech wrote:Shoot, I wish I had a bit of time. I love assembly. Equates for your assembler engine is your friend :) I will dig into it soon so I can hopefully help with some stuff.
You're late to the party again ...

Thanks to kur4o for kicking my final hurdle down we now have Intel Flash Sector erase in Assembly!
AMD is already done, untested, still needs testing, I just haven't done that yet, I may rewrite it after learning some things doing Intel.
No P12 AMD Unlock/Lock yet, that has still to be worked out.

We are getting closer and closer to Assembly Kernel Writes ... A new era for PcmHammer!

Some damn nice rides ... Makes me jealous, I miss being out and about doing that shit!
ironduke wrote: As far as Grampy's problem.. I have the answer, sorta.. I can explain the 7430 at least..
It's -7430 decimal.. that is also 0xffffe2fa which is in your first statement..

Or did I misunderstand the question?? Happens often, lol..
Already figured it out, but you are 100% correct!
Don't know why I had so much problem, I must have been tired, because now my formula works ...

Thanks y'all!

-Enjoy
Intelligence is in the details!

It is easier not to learn bad habits, then it is to break them!

If I was here to win a popularity contest, their would be no point, so I wouldn't be here!
User avatar
antus
Site Admin
Posts: 8253
Joined: Sat Feb 28, 2009 8:34 pm
cars: TX Gemini 2L Twincam
TX Gemini SR20 18psi
Datsun 1200 Ute
Subaru Blitzen '06 EZ30 4th gen, 3.0R Spec B
Contact:

Re: Porting C code to m68k Assembly

Post by antus »

Good stuff! I just saw the thread, and picked the endianness and decimal hex, took a screen shot of the calculator and then saw the next 10 posts and all the answers. Good work! Good to hear the intel is working now. I have not been able to figure out why my implementation appears to be crashing the DLC when it doesn't use it but I'll stand by now, with your progress.
Have you read the FAQ? For lots of information and links to significant threads see here: http://pcmhacking.net/forums/viewtopic.php?f=7&t=1396
Post Reply