Saturday, May 9, 2009

61.2) Simple Machine Language Programs

back to top back to best labs summary contents

preferably the same programming environment as the lego robots or maybe use something like the Tierra machine code!

Get a programming book again and pick a few simple ones; binary search, sorting, and of course we will program up the one dimensional cellular automata; rule 30!


10) write machine code? hmmm simplest. show 4 bit processor has few basic instructions, inc, dec, set=0, dec and loop, so they can make simple programs on a screen of some kind... but what's gonna happen here? it takes some period of learning of motivation to figure out how to make a program. what do you want them to be able to accomplish?

ultimately program legobots but i don't want it to be abstract, i want them to see that it's all based on these basic mechanical components. the legobot programing environment was a mystical make believe geometric representation on a computer screen. i don't want that! that's magic!

so can you make a simple legobot that's controlled by the code for that simple machine? 4 bit instruction code, 15 instructions with the 16th code signaling for an extended instruction set.

ok, make it 8bit 4 bit code 4 bit register code, 16 registers

inc reg
dec reg
set=0 reg
if not zero reg branch loc
brach loc
shift right reg
shift left reg
if flag branch loc

i suppose i should have stack implementation
subroutine call and return
load program counter etc..

extended instructions (2 4bit nibbles)
X fwd steps
Xrot (rotate clockwise 22.5deg) or from 0 to 360-22.5deg (16 options)
Xload imm reg
extended instruction:
(can add other sensors and actions later)

show the actual circuitry of the robot, the 4 bit processor

bar, you are dreaming. how will you test this all out to see how feasible it is? and again... how will kids write the programs?

so you see the blow up 4bit processor circuit on the wall.

then you have the legobot with hex display or something and button for load, read, reset etc.. like my 1802 board. and lights and things insiode the clear case to simulate these signals going to the 4bit processor. the clock rate is like a pulse every 2seconds so they can see all the steps... or again, you can turn a dial to slow down the pulse rate or speed it up... hmmm

hell you can make the bot big enough (good, robust) to have a keyboard with a button for each command, labeled, inc, dec, loop, back, rotate... and then a shift key to use those same keys for the hex numbers. of course you have on the wall the diagram for the circuit that polls the keyboard! well it's a simple circuit, keypress signals a register with input etc.. 16 line to 4 bit decoder...

then describe
CPU architecture: memory, registers, program counter, execution, transfers, how arithmetic operations work and effect flags, how branch instructions chagne program counter, describe hex notation, describe 0-1=255, etc..

so then what? so they start making programs:
move 5
move 5
move 5
move 5

that makes a square that's easy enough to suggest to a kid.

show some programs that the kid can watch and then he modifies them...

the concept of looping...

loop 2
loop 1
move 5
test for bump
until 1
until 2

bar that's a sophisticated concept! do you think you can really get kids at a science center to begin to play with this stuff? i don't think science museum is the right environment for sitting down and experimenting and thinking.

i don't know. what if you just show the programs and see how they loop, proceed while watching the bot, and then you can modify the programs?

then you can watch on the wall a diagram (watch the bouncing ball...) run through a complicated program while watching the bot go at it...

Further lessons:

give examples of use of each instruction.

describe register pointers

write simple turtle programs to make shapes

describe branches for if then

then introduce loops

adding list of numbers

searching list of numbers

then you can show langton ant

describe subroutines

should get my old forth book for outline of what to teach, do i got my 68000 book? i've got the 1802 manual and a programming lesson based on it!

We can program langton's ant:

' not sure how i'm implementing read and write to the floor!
' reg B=0
' reg C=1
load imm B, 0
load imm C, 1
read to A
if A zero branch [1] ' if land on a 1
write B 'write blank
rot 12 ' rot counter clockwise
fwd 1
branch [2]
[1] ' if land on a 0
write C ' write 1
rot 4 ' rot clockwise
fwd 1
brach [3]

No comments:

Post a Comment


About Me

almost native to new york state. teacher and storyteller. email: