Small Assembly example please
krazyideas
Posts: 119
I'm working on my first assembly program.
So I have figured out how to get waitcnt to work. By work I mean I carefuly went through the example in the prop manual and it makes sense to me. But I can't get waitpeq to work.
I think I get how to do the rest of what I want. Namely grabing the cnt value, subtracting values, and I think I can divide values (we will see on this one), then triggering a output pin
That brings up another question also. How does the dividing of numbers work in Binary? I have noticed that in spin that there are several different numbers that you can divide and still come up with the same answer. For example say 300/20 = 15 but 300/21 = 15 too. does the prop just round it or trunk it or what??
Anyway back to the orginal question
I don't understand how to identifi the Pin to watch or to I dentifi it's state.
I don't really understand the terms "state" or "Mask" in the prop manuel in regards to waitpeq or any other command for that matter.
What I am doing is
But no matter how I guess at it, it still don't work.
The goal is to put the waitpeq into the example in the book (I can't remember the page but it's in the introduction to assembly about 320 or something) so that it won't begin triggering pin 16 until a pin goes high.
I small example of how to use waitpeq would be awsome
Thanks
So I have figured out how to get waitcnt to work. By work I mean I carefuly went through the example in the prop manual and it makes sense to me. But I can't get waitpeq to work.
I think I get how to do the rest of what I want. Namely grabing the cnt value, subtracting values, and I think I can divide values (we will see on this one), then triggering a output pin
That brings up another question also. How does the dividing of numbers work in Binary? I have noticed that in spin that there are several different numbers that you can divide and still come up with the same answer. For example say 300/20 = 15 but 300/21 = 15 too. does the prop just round it or trunk it or what??
Anyway back to the orginal question
I don't understand how to identifi the Pin to watch or to I dentifi it's state.
I don't really understand the terms "state" or "Mask" in the prop manuel in regards to waitpeq or any other command for that matter.
What I am doing is
waitpeq pin, pin pin long |< 15
But no matter how I guess at it, it still don't work.
The goal is to put the waitpeq into the example in the book (I can't remember the page but it's in the introduction to assembly about 320 or something) so that it won't begin triggering pin 16 until a pin goes high.
I small example of how to use waitpeq would be awsome
Thanks
Comments
- grab ina
- and it with mask (extract pins/bits of interest)
- compare against state
- if equal continue with next insn otherwise go back to step 1
So for your example this would mean we deal with pin 15 (zero-based). The waitpeq extracts said pin and compares it against itself (state == mask). Which means that in order to become true pin 15 must become high: HTHMabe what I should ask is what does ANDed, ORed mean or do.
From what I understand (uber beginer) my little code should have worked.
The waitpeq grabed the ina register. Then it checked to see if the state and mask were equil to each other.
OK so that does not make sense to me. If the waitpeq grabs the ina register all at once why does it have to have a mask?? shouldn't it just wait for the ina reg to match the state?
I'm not understanding the steps you don't see in the command.
Is it that waitpeq grabs the ina register.
The state is the pin or pins to watch
and the mask is what you want those pin to == ?
Also do you think it would be easyer for a beginer such as my self to write out the entire registers, masks and states in Binary like in your example to help me see what I'm trying to do as I work with assembly to start with
Sorry and Thanks
eg: would wait for pins 3, 2, 1, and 0 to equal 0, 1, 0, and 1, respectively.
waitpeq checks the ina register but is only concerned with the bits set to 1 in the Mask, and waits for those pins set to 1 in the mask to match the state that is in the state part of the expression.
Mask sets the pins to watch
state is the states of those pins
Thanks
here is what I am doing.
'The waitpeq only works on pin 3 (%0000_0000_0000_0000_0000_0000_0000_1000)
'if I enter %0000_0000_0000_0000_0000_0000_0000_0001 in both the state and mask var's it wont work.
'It won't work on pins 1,2,4,5,6,7 either
'Why will it only work on pin 3
'I have nothing but a scope hooked up to pin 16 so I can see what it is doing.
'I am lost.
Note that due to the way this is all evaluated you may end up with cases where waitpxx never exits or never waits (independent of external signals), e.g.
Thanks a ton guys.
So next question. Dividing, and timesing. Not as easy as I thought.
I thought I could just use Mov like this
But no chance I guess.
I have heard of useing addtion to multiply some how but I do not recall how that works.
What I really want to do is divide.
Can someone point me down the right road.
Thanks again
Chip did the following in the Spin-Interpreter...KYE posted this not long ago and I kept it ...
Enjoy!
Mike
On to the next question.
I have a loop going on and in the middle of the loop I need to check to see if a Pin is high. If it is then I need to jump to another loop but if it is not then it needs to just pass by the jump and continue the first loop again and again till the Pin goes High.
So after studying I understand this.
-In order to use an IF statment you have to use the Z and C flags. They are what the condition must look at.
-Each command writes to the Z or C flag depending on the command and if you tell it to write to the flag or not.
I think I understand that part,(said that before and I was very wrong, but ya gotta start somewhere)
So the real question at present is how would I check a single bit in the ina register that coralates to the pin I want lets call it pin 20?????????
ina reads the whole register at once right? so how do I look at pin 20 alone.
I was thinking mabe useing the AND command somehow but it didn't work in my head.
All I'm pretty sure about is that I need to cmp a mask and Pin 20 which if equle will WZ then if z then jump to other loop
Am I barking up the right tree??
Thanks
mask is set to 20 via |< 20 which is the same thinga as %0000_0000_0001_0000_0000_0000_0000_0000 right.
Then the test command looks at ina but because of the mask is only looking at pin 20 Right?
So if Mask and ina == each other (both == 1) it writes the Z flag to be 1, otherwise the Z flag remains 0 and it continues on with the next command.
If so then why did you use if_nz (if not Z) then jmp. Or is it that I would have
if_nz jmp to one place and
if_z jmp to the other place ?
Thanks
Now, the wz effect for and/test is that it's set when the result is 0 and cleared when it is not (zero). Which means for a high pin 20 we get a non-zero result (!Z) and for a low pin a zero result (Z). This is not to be confused with the cmp behaviour where the zero flag is determined by the difference between both operands (A == B is Z, A != B is !Z), e.g.
So I need too pause the assembly program while I do a bunch of stuff in spin that is dependant on the information gained by the assembly code and then start the assembly code again.
The easyest way of doing that in Spin us just calling a method. So the question is can I call a spin method from a assembly program and have it do the same thing, just jump back to what called the method and continue from there? or do I need to write the assembly program so it skip the puse loop until a flag is set thenl run an endless loop until a hub var is == to a value then jump out of the pause loop.
Any thoughts on a simple way of doing this?
Thanks
I just wasn't sure if there was some super easy thing that I just didn't know about that would do what I wanted. It happens often with me so I thought I would ask this time.
Thanks a ton