# Omnimaga

## Calculator Community => Casio Calculators => Other Casio Calculators => Topic started by: z80man on March 10, 2011, 12:51:35 am

Title: SH3 op of the day
Post by: z80man 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.

(http://img.removedfromgame.com/imgs/image004.jpg)
(http://img.removedfromgame.com/imgs/image006.jpg)
(http://img.removedfromgame.com/imgs/image002.jpg)

Title: Re: SH3 op of the day
Post by: DJ Omnimaga 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.
Title: Re: SH3 op of the day
Post by: z80man 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.
Title: Re: SH3 op of the day
Post by: jnesselr on March 10, 2011, 07:39:40 am
This looks interesting.  But what if you wanted to load a word into memory?
Title: Re: SH3 op of the day
Post by: JosJuice 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.
Title: Re: SH3 op of the day
Post by: DJ Omnimaga 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.
Title: Re: SH3 op of the day
Post by: jnesselr on March 21, 2011, 01:14:36 pm
So, is this dead, or do you just have to make up 12 days?
Title: Re: SH3 op of the day
Post by: Rokem 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
Title: Re: SH3 op of the day
Post by: JosJuice 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...
Title: Re: SH3 op of the day
Post by: seana11 on July 17, 2012, 04:13:10 pm
Can I crosspost some of this to UCF?
Title: Re: SH3 op of the day
Post by: DJ Omnimaga 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.
Title: Re: SH3 op of the day
Post by: chickendude 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 ;)