Calculator Community > Casio Calculators

SH3 op of the day

(1/3) > >>

z80man:
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.








DJ Omnimaga:
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.

z80man:

--- Quote from: DJ_O 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.

--- End quote ---
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.

jnesselr:
This looks interesting.  But what if you wanted to load a word into memory?

JosJuice:

--- Quote from: graphmastur on March 10, 2011, 07:39:40 am ---This looks interesting.  But what if you wanted to load a word into memory?

--- End quote ---
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.

Navigation

[0] Message Index

[#] Next page

Go to full version