Author Topic: SH3 op of the day  (Read 14200 times)

0 Members and 1 Guest are viewing this topic.

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
SH3 op of the day
« on: March 10, 2011, 12:51:35 am »
You have probably now seen the new Casio Prizm calc. You might also happen to know that it is powered by a SuperH 3 processor. If so, you might want to start coding for it. The purpose of this lengthy tutorial will be to teach you how to write SH3 asm code day by day. I will not be teaching how to do Prizm specific coding, just SH3 coding. I have also designed these tutorials to show parallel between the SH3 and the z80. It is highly recommended that you previously know a machine compiled language such as z80, arm, C, C++, x86, or axe. Other languages such as Java, python, and BASIC can also be used as prior experience, but you may find coding in SH3 more difficult. I also reccomend to everyone, if you have not done already, is to read Qwerty's previous tutorial on SH3 asm here http://ourl.ca/8986. Once I finish this tutorial I will place all of the lessons into a pdf file. I will here document every single instruction on the SH3 and there will be a lesson every day. I may skip a day or week at a time, but I will make up for the days I missed.
__Day One__
__MOV #imm,Rn  0xEnii__
1 cycle, no privilege required, T bit unchanged


I'm going to start this tutorial off with what one of the simplest instructions available. For a z80 coder, it is the equivalent of the ld a,$xx. Because the SH3 is a RISC processor, it only supports 16 bit fixed-length instructions. Therefore only byte values can be stored as immediate data. The hex for this instruction is 0xEnii. Where n is the register (0-15) and ii is a byte of immediate data to be stored in register n. An important note with this instruction is that a sign extension is preformed on the entire 32 bit register even though the data is only a byte. Basically a sign extension is formating the register that way the register is read the same when it is referred to as a long word. The easiest example are positive numbers. Say you want to load $04 into R15. Because $04 is a positive number, 0's will be placed in front of it in the register to reflect this as $00000004. So if you read R15 as a long word later you will see the value of $4 in there. Negative operations are really just the opposite. Say you now want to load $FE aka -2 into R15. Because $FE is a negative value the register is reflected as such. The result would be $FFFFFFFE in R15. Now if you read R15 as a long word you will get the value of -2. Now lets say the cpu did not do a sign extension for the last instruction. Then R15 would read $000000FE. Now if you try to read this, you will get a value of 254 not -2 which you wanted. That now completes lesson one. I hope you are now onto your way into learning SH3 asm. Tomorrow's lesson will teach you how to load data from memory using a displacement value.








« Last Edit: March 11, 2011, 01:57:14 am by z80man »

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: SH3 op of the day
« Reply #1 on: March 10, 2011, 01:34:22 am »
Sounds promising. A tutorial for SH3 ASM like ASM in 28 days or Hot Dog's tutorials (the later is more suitable for a greater range of people) would be more than welcome to increase Prizm programming popularity.

Personally I think it should be made suitable for visual people as much as possible, otherwise you're gonna single out a large group of people (like ASM in 28 days did). Calc screenshots of what each relevant example program does (even if camera captures) are more than welcome.

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: SH3 op of the day
« Reply #2 on: March 10, 2011, 01:40:22 am »
Sounds promising. A tutorial for SH3 ASM like ASM in 28 days or Hot Dog's tutorials (the later is more suitable for a greater range of people) would be more than welcome to increase Prizm programming popularity.

Personally I think it should be made suitable for visual people as much as possible, otherwise you're gonna single out a large group of people (like ASM in 28 days did). Calc screenshots of what each relevant example program does (even if camera captures) are more than welcome.
I'm going to edit each of the lessons later to include more details including pictures, charts, and screenshots. I am thinking that this might take a bit more than 28 days. I could divide this tutorial in sections with the first one being shorter and for beginners while an advanced one will teach the rest of the instruction in a much longer time period as I want to eventually teach every single instruction available. Even if most coders will never use half of them.
« Last Edit: March 10, 2011, 01:40:51 am by z80man »

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: SH3 op of the day
« Reply #3 on: March 10, 2011, 07:39:40 am »
This looks interesting.  But what if you wanted to load a word into memory?

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: SH3 op of the day
« Reply #4 on: March 10, 2011, 10:21:12 am »
This looks interesting.  But what if you wanted to load a word into memory?
Then you have to use MOV.W. It doesn't have any immediate data - a relative address is stored in the instruction, and the value at that address is read as a word. I'm sure z80man is going to include it soon.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: SH3 op of the day
« Reply #5 on: March 11, 2011, 12:46:36 am »
Sounds promising. A tutorial for SH3 ASM like ASM in 28 days or Hot Dog's tutorials (the later is more suitable for a greater range of people) would be more than welcome to increase Prizm programming popularity.

Personally I think it should be made suitable for visual people as much as possible, otherwise you're gonna single out a large group of people (like ASM in 28 days did). Calc screenshots of what each relevant example program does (even if camera captures) are more than welcome.
I'm going to edit each of the lessons later to include more details including pictures, charts, and screenshots. I am thinking that this might take a bit more than 28 days. I could divide this tutorial in sections with the first one being shorter and for beginners while an advanced one will teach the rest of the instruction in a much longer time period as I want to eventually teach every single instruction available. Even if most coders will never use half of them.
Cool to hear. :)

Also for now I'll create a link to this topic in the Casio Prizm section since some Casio Prizm hackers might find this useful.

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: SH3 op of the day
« Reply #6 on: March 21, 2011, 01:14:36 pm »
So, is this dead, or do you just have to make up 12 days?

Offline Rokem

  • LV0 Newcomer (Next: 5)
  • Posts: 4
  • Rating: +0/-0
    • View Profile
Re: SH3 op of the day
« Reply #7 on: July 08, 2011, 04:35:38 am »
So, is this dead, or do you just have to make up 12 days?
4 months now :P

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: SH3 op of the day
« Reply #8 on: July 08, 2011, 05:23:23 am »
So, is this dead, or do you just have to make up 12 days?
4 months now :P
Hmm, I wonder if there are that many instructions...

Offline seana11

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 15
  • Rating: +4/-0
    • View Profile
Re: SH3 op of the day
« Reply #9 on: July 17, 2012, 04:13:10 pm »
Can I crosspost some of this to UCF?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: SH3 op of the day
« Reply #10 on: July 18, 2012, 01:26:46 am »
I guess there would be no problem since the author has left over 6 months ago. It wouldn't hurt to make sure it's present in WikiPrizm (and the older PrizmWiki if it's still maintained) too, so all the info is at one place.
« Last Edit: July 18, 2012, 01:27:04 am by DJ_O »

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: SH3 op of the day
« Reply #11 on: October 21, 2012, 05:44:49 am »
Again a bit of a bump, but (in the picture) how do you get 126 from (sign-extended) $FE? I believe it should be 254 (like mentioned in the post body).

And i'd be interested in discussing SH3 assembly with anyone else interested ;)