PDA

View Full Version : Questions - deSilva's machine code PDF



Zap-o
12-30-2009, 06:29 PM
I am starting to program the propeller in assembly. And while reading deSilva's fine PDF. I come to a misunderstanding. On page 3 he mentions:


deSilva said...

Let’s talk about processors – called “COGs” in Propeller lingo.
What do they do? There is an always correct answer: They execute
instructions! A standard processor gets these instructions from a
globally addressed memory (in a so called “von-Neumannarchitecture”)
or from a dedicated instruction memory (in a so
called “Harvard-architecture” – this is the way PICs and AVRs are
organized!). Having two memories allows to “tune” them according
to specific needs (e.g. non-volatile, read-only, fast access
time), and also to access them in parallel!
A Propeller processor gets its instructions from its internal COGmemory,
space limited to 496 instructions!



I am not so sure there are 496 instructions perhaps 30-40 but almost 500 that's insane. Now to me a instruction would be IF_A, AND, CNT, etc... I am sure I am interpreting this incorrectly. Some one shed some light on this please and be prepared for more questions...

http://forums.parallax.com/attachment.php?attachmentid=48819

kuroneko
12-30-2009, 06:38 PM
Zap-o said...
I am not so sure there are 496 instructions perhaps 30-40 but almost 500 that's insane.

It simply means there is space for 496 instructions (max PASM code size) which are selected from the ~76 available instructions.

heater
12-30-2009, 06:45 PM
You are reading "A Propeller processor gets its instructions from..." incorrectly. I forget how many unique instructions the Prop has, ADD, SUB, OR, AND etc etc but thats not what it's about here.

When a program executes it has to read instructions from some where, find out what the instruction is, ADD, SUB, etc, read the data required for that instruction from somewhere, perform the required operation and write the result somewhere. You will from time to time see mention of "fetch", "decode" "execute" and such phases of a CPU cycle.

What deSilva is talking about here is the first part, where to read the instructions from. Well they can only be in the COG memory and there is only 512 possible addresses in that space. 16 of those slots are used for special purpose registers, INA, OUTA, etc leaving 496.

So normally that is the maximum size of a PASM program for a COG. Unless you get into creating a PASM program that fetches instructions from HUB first and then executes them. So called Large Memory Model. Let's not get into that just now.

As for the ambiguity in "A Propeller processor gets its instructions from..." I like that, ultimately all Propellers got there instructions from Chip Gracey who designed them that way.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.

Zap-o
12-30-2009, 06:52 PM
Yea I understand now thanks for clearing that up fellas.

Dr_Acula
12-30-2009, 06:58 PM
Indeed, you do have that many instructions. Life is good :)

An 'instruction' consists of one 'word', or 4 bytes. Some of your code might be instructions, and some might be text, and you have 4x the number of bytes if you want to access stored data.

Or looking at it another way, if a byte stores an ascii character like "A" then an instruction can store "ABCD". Sometimes you can do cunning things like storing new data in old instruction space that isn't needed any more (eg startup code) or storing new code to instruction space. And you can get new data from Hub ram as you need it. Or even from external memory.

And you have 8 of these microprocessors all humming along together.

I like assembly. The hardest part is the building blocks you need to start, eg ORG 0 at the beginning, tables at the end of the code, using FIT to check it fits, and the way cogs are started and stopped. It helps to copy some existing code, eg from the keyboard or vga text driver objects. I found that once I had the template working, Assembly was actually easier than Spin.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller (http://www.smarthome.viviti.com/propeller)

Post Edited (Dr_Acula) : 12/30/2009 12:04:44 PM GMT

Zap-o
12-30-2009, 07:08 PM
So my next question is...
...can one write code in spin and in areas where speed is needed can machine code run. For example: say I am already running all cogs and in cog 0 I have the bulk of the code running spin - I also want to run machine code in that same cog.

Is this possiable?

Because in one of the examples it states this





cognew(@ex01A, 0)

heater
12-30-2009, 07:12 PM
Dr_A: "Assembly was actually easier than Spin"

Do you realize what an incredible statement that is? Perhaps for the first time in history of programming we have a device were programming in assembler is easier than the provided high level language. And Spin is quite a simple HLL as they go. That is one of the major attractions of the Prop for me.

As compared to this from a certain other processor I've been looking at:




.globl ssctrl_check
.globl ssctrl_check.nstackwords
.linkset ssctrl_check.nstackwords, 2
ssctrl_check:
entsp 2
stw r1, sp[ 1 ]
bl ssctrl_read
ldw r1, sp[ 1 ]
eq r11, r0, r1
ecallf r11
retsp 2


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.

StefanL38
12-30-2009, 07:44 PM
No it is NOT possible to mix SPIN and PASM in the same cog

If a cog executes SPIN, all 496longs are occupied by the SPIN interpreter. There is no space left for PASM.

Maybe there is a possability if you use the improved interpreter. But EVERY time you change the code you would have to fiddle around the adresses
where is SPIN and where is PASM.

@Bean Hitt: I know PropBasic can be mixed with pure PASM.
Is it possible to mix PropBasic with SPIN ? (as PropBasic is compiled to PASM and therefore pretty fast).

best regards

Stefan

Leon
12-30-2009, 08:08 PM
Heater,

Unlike the Propeller, the XMOS chip was designed for efficient execution of compiled languages - assembler isn't needed very often. The XMOS assembler also uses a linker, which complicates matters. Using a linker has the advantage that separately compiled modules (XC, C and assembler) can be used, and libraries can be created.

Leon

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM

Post Edited (Leon) : 12/30/2009 1:18:23 PM GMT

heater
12-30-2009, 08:24 PM
Oooo, Leon, you spoke the name. We will get flogged again:)

You are right though, it's a different world over there.

Thing is I like torturing my brain with assembler coding occasionally. Strangely enough I did have some fun programming Windows once. In assembler. Windows, dialog boxes etc. Seemed that the explanations in the book I had about how it all worked were clearer than those in the C++ equivalents.

Can't remember exactly now but it could have been from this book: www.amazon.com/Windows-Assembly-Language-Systems-Programming/dp/087930474X (http://www.amazon.com/Windows-Assembly-Language-Systems-Programming/dp/087930474X)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.

Leon
12-30-2009, 08:42 PM
I've always liked assembler, as well. My first computer was a Motorola 6800 D2 kit which I soldered together, it had a mere 128 bytes of user RAM. I wrote my programs in assembler and hand-assembled them. Things got easier when I wrote a little routine which calculated relative branches for me. Even when I graduated to a Z80 and 8086, I was still hand-assembling my code - I wrote a quite powerful monitor/debugger for the Z80 and 8086 using hand-assembly, about 10 pages of (handwritten) code. It's a good way to learn a new instruction set. It wasn't until I got a TRS-80 Model I that I was able to use a real assembler - Microsoft's Macro-80.

Leon

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM

Post Edited (Leon) : 12/30/2009 1:47:26 PM GMT

CannibalRobotics
12-30-2009, 09:34 PM
Leon,
can't disagree with you. I·started on the 6502 then migrated to the Intel 80xxxx series·but I've got to say, it took me a while to get my head out·wrapped around·working without a stack.
Jim-


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.

heater
12-30-2009, 09:40 PM
Why did you need a stack in PASM? I have yet to come to a situation were I need one.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.

CannibalRobotics
12-30-2009, 09:50 PM
Didn't 'need' one at all. It was a learning curve issue, the flowcharting lobe of my brain kept trying to apply that archetecture/model. Habit I guess, the stack had been pervasive in everything else I had done. My beloved HP calculator is the last remenant.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.

heater
12-30-2009, 10:02 PM
I know what you mean. The Prop has dispensed with a lot of things that people thought they needed for decades, stacks, interrupts and the like. Whilst also adding things people did not know they needed, deterministic timing, all pins the same etc etc.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.

potatohead
12-30-2009, 11:32 PM
That's the fun part right there!

I was writing some 6809 yesterday. God, I love that chip. It is the best of the 8 bitters, and has a multiply. Anyway, I'm wanting to do a little math to obtain a screen address...

WHERE DID ALL MY REGISTERS GO, and HOW COME I CAN'T JUST USE ALL OF THEM HOW I WANT TO?

LOL!!

That stack came in very handy, because the number of registers isn't high enough to operate without it!

Back on Prop, I find it so easy to just write assembler. Not that I can just knock it out or anything. It's all a struggle for me. But, the difference was in addition to just sorting out the problem, which is my main Propeller problem as I'm an amateur, I had to also sort out the registers and do that planning too!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
8x8 color 80 Column NTSC Text Object (http://obex.parallax.com/objects/550/)
Safety Tip: Life is as good as YOU think it is!

heater
12-30-2009, 11:42 PM
Ah great, another 6809 fan. You will be happy when I get the MoCog 6809 emulator for the Prop finished. Then you can program in both your favourite assemblers at the same time:)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.

potatohead
12-30-2009, 11:51 PM
Yeah I will.

Color Computer has always been one of my favorite computers. It's possible to really expand one and do some fairly serious computing on it, yet it can be broken down to just a computer, maybe a disk, and do simple, fun things too. The basic language interfaces to machine code nicely, and it's I/O and memory map overall are sane, and not a mess.

One nice thing about 6809 is external devices, like video, can operate on the last phase of it's clock, meaning no DMA is needed, allowing the chip to run deterministically, timing wise, and achieve full though put no matter what the video system is doing. Most other 8 bit computers, but for the Apple, are a mess of timing, cycles, interrupts and such.

Maybe OS/9 in multi-user mode will be possible someday on Propeller... Just a day ago, some guy put his on the net so others could telnet in. Was fun to browse around "dir -e" ftp a "thanks for letting me play" text file, and see what some of the other users were doing.

So, yeah. I was a fan straight away, having cut my assembly language teeth on the 6502. At the time 6809 seemed so much more powerful and elegant. It still is, if you look at 8 bit computing, and even some of the bastardized 16 bitters out there. 6809 punched well above it's weight. But... after doing prop, it seemed so constraining. Funny how perceptions change, isn't it?

Edit: And I bought a spare 6809, when I picked up 6502 stuff, just on the off chance I might end up hooking it to a Prop. Maybe after seeing success on my 6502 build, that chip can be done for testing illegals and such. What is hard to get is the Hitachi 6803...

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
8x8 color 80 Column NTSC Text Object (http://obex.parallax.com/objects/550/)
Safety Tip: Life is as good as YOU think it is!

Post Edited (potatohead) : 12/30/2009 5:04:20 PM GMT

Zap-o
12-31-2009, 12:34 AM
All this lingo makes me excited however I don't have enough time in a day to even come close to understanding it all. Is there a good place to learn machine code for the propeller. the PDF that deSilva wrote has me confused?

hover1
12-31-2009, 12:35 AM
Some boards are just not happy without assembly language. http://forums.parallax.com/images/smilies/tongue.gif
It's hard to know with one to play with, but I like my demo board the best!

Jim

Leon said...
I've always liked assembler, as well. My first computer was a Motorola 6800 D2 kit

Leon
12-31-2009, 01:00 AM
I've played with this 6809 FPGA emulation on a Xilinx Spartan 3 board:

members.optusnet.com.au/jekent/system09/index.html (http://members.optusnet.com.au/jekent/system09/index.html)

Leon

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM