ZPU Emulator needs help with mul, div, and mod.
heater
Posts: 3,370
I know this has been asked before, and by me, but could someone point me to some nice small arithmetic routines in PASM
for use in the ZPU emulator?
ZPU requires:
Multiplication of two 32 bit twos complement integers with a 32 bit result.
Multiplication of two 16 bit unsigned numbers with a 32 bit result.
Division of a 32 bit twos complement integer by another with a 32 bit result.
Modulus, as above.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
for use in the ZPU emulator?
ZPU requires:
Multiplication of two 32 bit twos complement integers with a 32 bit result.
Multiplication of two 16 bit unsigned numbers with a 32 bit result.
Division of a 32 bit twos complement integer by another with a 32 bit result.
Modulus, as above.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Comments
http://forums.parallax.com/showthread.php?p=731577
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
"a" holds the opcode (lower 5 bits as shown in the first block of code...·e.g. MPY=$F4=%10100)
"x" and "y" are the two numbers to be multiplied (or divided) x * y or x / y, result is in "x" (pushed).
So, if you use this routine with a set to...
·a = $F4 (multiply, return lower 32 bits),·= $F5 (multiply, return upper 32 bits), = $F6 (divide, return quotient 32 bits), = $F7 (divide, return remainder 32 bits)
But, only set the lower 5 bits meaning $F4 --> $14, etc to save the first and a/#%11111 instruction.
Hope this makes sense now
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
With those in place the ZPU is eating 321 LONG in COG. Only three little ops to do and the main fetch execute loop.
Looks like it will all fit in just fine.
At the moment the dispatch table is 256 bytes in HUB. I can use byte entries in the table as all the opcode handler routines can fit in the first half of the COG nicely.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
All the ZPU memory accesses have been localized to a few functions so moving to external RAM should be painless.
Has anyone ever heard of an "Arithmetic Shift Left" ?
The ZPU docs have defined one and it exists in their Java simulator. In fact they document this with the Java code:
What's the idea here ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Maybe they've done/named it to remain consistent with an ASR?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Life may be "too short", but it's the longest thing we ever do.
It's an awfully long winded way of specifying it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Tony
http://zuzebox.wordpress.com/
So to my simple mind and zero understanding of any funky Java operator quirks this maps to PASM shifts as follows:
LSHIFTRIGHT => SHR
ASHIFTLEFT => SHL
ASHIFTRIGHT => SAR
ZyLin's naming of the SHL seems a little weird to me.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
Here they are talking about a "...signed left shift operator..." which basically does not make any sense to me as there is only one type of left shift and it does not care about the sign. Unless of course unless Java sign extends a signed 16 bit short when shifting it left and assigning to a 32 bit int. Hence "arithmetic shift left".
I learned something new today. C is not guaranteed to use an arithmetic shift right for integers !
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.