Sonic and Sega Retro Message Board: How to translate basic 68k assembly to c++ code - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Page 1 of 1
    Locked
    Locked Forum

How to translate basic 68k assembly to c++ code

#1 User is offline Chris Pancake 

  Posted 22 December 2017 - 07:31 PM

  • Posts: 7
  • Joined: 16-December 17
  • Gender:Not Telling
  • Project:Sonic Union
This is my first topic!
Unfortunately I was unable to find the c++ equivalent to the bset, bclr, bchg, bvc and bvs..
If you want to know how to do rol and ror, look there.

Local variables
Spoiler


Conditions
Spoiler


Addiction and subtraction
Spoiler


The clear, swap and exchange instruction
Spoiler


Bitwise operators
Spoiler


The neg, ext
Spoiler


Multiplication and division
Spoiler


Branch on sign
Spoiler

This post has been edited by Chris Pancake: 26 January 2018 - 12:27 PM

#2 User is offline MainMemory 

Posted 23 December 2017 - 01:55 AM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4051
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339
Your "Addition and Subtraction" section uses d1 as a pointer, which is not permitted on 68000. Aside from that, a lot of this is just common sense stuff that you'd figure out if you know C and 68000 ASM.
The equivalent to bset #X,d0 is d0 |= 1 << X;
The equivalent to bclr #X,d0 is d0 &= ~(1 << X);
The equivalent to bchg #X,d0 is d0 ^= 1 << X;

#3 User is offline Chris Pancake 

Posted 23 December 2017 - 08:32 AM

  • Posts: 7
  • Joined: 16-December 17
  • Gender:Not Telling
  • Project:Sonic Union

View PostMainMemory, on 23 December 2017 - 01:55 AM, said:

Your "Addition and Subtraction" section uses d1 as a pointer, which is not permitted on 68000. Aside from that, a lot of this is just common sense stuff that you'd figure out if you know C and 68000 ASM.
The equivalent to bset #X,d0 is d0 |= 1 << X;
The equivalent to bclr #X,d0 is d0 &= ~(1 << X);
The equivalent to bchg #X,d0 is d0 ^= 1 << X;

To be honest, I didn't have so much practice with the 68k, already fixed that.

#4 User is offline flamewing 

Posted 27 December 2017 - 06:51 AM

  • Emerald Hunter
  • Posts: 1118
  • Joined: 11-October 10
  • Gender:Male
  • Location:🇫🇷 France
  • Project:Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
  • Wiki edits:12

View PostChris Pancake, on 22 December 2017 - 07:31 PM, said:

register int d0 = hello;
register int d1 = world;



For what is worth, "register" keyword is mostly ignored by C and C++ compilers and, since C++11, it has the same semantics as whitespace in C++. C, even C11, still pretends it does something but, in practice, it does not.

#5 User is offline Chris Pancake 

Posted 03 January 2018 - 05:49 PM

  • Posts: 7
  • Joined: 16-December 17
  • Gender:Not Telling
  • Project:Sonic Union

View Postflamewing, on 27 December 2017 - 06:51 AM, said:

View PostChris Pancake, on 22 December 2017 - 07:31 PM, said:

register int d0 = hello;
register int d1 = world;



For what is worth, "register" keyword is mostly ignored by C and C++ compilers and, since C++11, it has the same semantics as whitespace in C++. C, even C11, still pretends it does something but, in practice, it does not.

With optimization on of course (MSVC /Ox and GCC -Ox for example), that's why I said:

Quote

This keyword is not needed when this is a release build though. (which normally has the O2 build option).
I also changed the name of this topic because this guide is really basic.

#6 User is offline lil-g-gamegenuis 

Posted 06 January 2018 - 07:19 PM

  • GO! GO! GO! GO! GO! GO!
  • Posts: 22
  • Joined: 03-April 12
  • Gender:Male
  • Location:olathe, ks
  • Project:Practicing to make better SMPS
Actually even when optimization is off, it's still ignored. Compilers nowadays only treat it as a keyword with no meaning. Its about as useful as the auto modifier (Note: Not the auto type)

#7 User is offline Revival 

Posted 17 January 2018 - 12:04 AM

  • The AppleTalk Network System
  • Posts: 200
  • Joined: 08-July 07
  • Gender:Male
  • Location:The British Republic (< 3)
  • Wiki edits:34
This certainly seems correct, but this is something that could be done by an automatic translator. Aside from folding some lines into one-another the result of that would almost exactly match the original assembly on a line-by-line basis. It would be far from idiomatic C++.

If a direct translation of a whole program from 68k ASM to C++ were intended, it would probably be better to make drastic changes - abandon manipulation of global variables representing the registers, for example, and instead make the subroutines pass data as actual arguments. The modern optimising C++ compiler could probably match the performance of the original assembly.

#8 User is offline flamewing 

Posted 17 January 2018 - 09:25 AM

  • Emerald Hunter
  • Posts: 1118
  • Joined: 11-October 10
  • Gender:Male
  • Location:🇫🇷 France
  • Project:Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
  • Wiki edits:12

View PostRevival, on 17 January 2018 - 12:04 AM, said:

The modern optimising C++ compiler could probably match the performance of the original assembly.

They cannot, unless you are talking about really bad assembly; mostly because the modern C++ compilers which support 68k family at all are more oriented towards later models of the 68k family (which have pipelines), as well as using an ABI which makes heavy use of the stack.

Page 1 of 1
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users