nanorg's

Ask questions about projects relating to: computer science or pure mathematics (such as probability, statistics, geometry, etc...).

Moderators: kgudger, bfinio, Moderators

Locked
devcon4
Posts: 1
Joined: Thu Jan 20, 2011 8:44 pm
Occupation: student: 9th grade
Project Question: computer science
Project Due Date: feb,3,2011
Project Status: I am conducting my experiment

nanorg's

Post by devcon4 »

I am doing the nanorg progect for this years science fair when i hit a problem. I wrote my own program with gide lines from the sample. No one i know can under stand what i wrote. I can't seem to understand what the cmp dose and what 0xFFFF dose. I would realy like to have some feed back and sugestions. I think it might be good for a 9th grader. please reply back. this is the program me and my partner have wrote.
info: slpnanorg, devyn tristan

main:
rand [dir], 1
rand [count], 1
add [count], 1

loop:
sense r2
jns nofood
eat

nofood:
energy r0
cmp r0, 2000
jl notenufenergy
sense r5
cmp r5, 0xFFFF
jne notenufenergy
release 100

notenufenergy:
cmp [count], 0
je poke
jns poke
sub [count], 1

poke:
mov r2, 15
poke 1, 1000
poke 2, 1000
poke 3, 1000
poke 0, 1000
jns charge
js charge
charge:
charge 0, 500
charge 1, 500
charge 2, 500
charge 3, 500
jmp loop

newdir:
rand [dir], 4
rand [count], 1
jmp loop


dir:
data { 0 }

count:
gbrebner
Former Expert
Posts: 9
Joined: Tue Sep 29, 2009 11:11 am
Occupation: Distinguished Engineer
Project Question: n/a
Project Due Date: n/a
Project Status: Not applicable

Re: nanorg's

Post by gbrebner »

Hi,
Sorry for the delay in anyone responding to you. I see how you have modified the sample program, though there are no longer any comments in your version to explain what you are trying to do!

To answer your immediate question, the CMP instruction will compare the value stored in a register to a constant value. Here it's comparing the contents of r5 with the constant value 0xFFFF - this is in hexadecimal (base 16) notation (the 0x prefix denotes this). It is equal to 65535 in decimal. Now, the instruction before this has done a SENSE into register r5. Quoting from the nanorg information:

"... the SENSE instruction to determine if your organism is standing on sludge or on top of a collection point (each type of sludge has a different ID number between 1 and 32, and collection points have an ID of 65535)"

So what your CMP instruction is doing is a check whether you are on top of a collection point. Your next instruction is a JNE, which means to jump if the previous comparison was not equal. So your program will jump if you were NOT on top of a collection point.

I'm sure this will make an interesting project for you. Assuming that you don't have previous experience with assembly language programming, I suggest you read up the supplied NANORG information carefully, then plan what you want to do and how to program it up.

Hope this helps,
Gordon.
Locked

Return to “Grades 9-12: Math and Computer Science”