Printing strings using getbyte
proppy
Posts: 7
Hi,
I have been slowly learning and inching my way through the propeller p2asm manual. I tried to print a string but noticed that if i use getbyte i can only get the first four characters. I'm not sure if getbyte is what I should use or if I need to use another instruction to advance the string past the first four characters. My example code is below:
con
dat
org
' Set the clock mode asmclk ' configure rx smart pin fltl #63 wrpin #P_ASYNC_RX, #63 wxpin ##655367, #62 drvl #63 ' configure tx smart pin fltl #62 wrpin ##(P_ASYNC_TX | P_OE), #62 wxpin ##655367, #62 drvl #62 getbyte tempbyte, msg, #0 wypin tempbyte, #62 'flush the tx pin nop .waittx testp #62 wc if_nc jmp #.waittx akpin #62 msg byte "Hello,world!", 10 tempbyte res 1
I am able to print H, e, l or l using #0 thru #3 but can't seem to figure out how to print the rest. I want to eventually put the whole thing in a loop, which i understand a little more now.
Comments
Where is this?
This is a small section from an S.BUS receiver program I wrote a while ago. What I have that you're missing is a loop, and an adjustment to the offset into the array (in your case, the message).
I just noticed that you have a 62 where you want 63 in your setup of the RX pin. This is why "magic numbers" are considered less than optimal (use named constants).
You need to use the alternative version of getbyte that is prefaced with altgb -- this allows a variable index.
I did a version using inline PASM. Maybe this will be helpful.
That said, PASM is not my strength; I resort to it when I need it.
Hi JonnyMac,
Thank you for the response. I will look it over. So far I think i understand. It didn't occur to me that i needed to set the index at the start. I had read in the manual how altgb works but didn't realize i needed to move the index at the start. Thanks so much for this, gonna pick away at it and see what i come away with.
I also corrected the misspelling of propeller as well.
I must say, that this is one of the riddles of P2 and it's documentation. Why not just:
....
mov pr0,#msg
.print rdbyte pr1,pr0
....
You would not want a string constant in precious cog ram registers, I think?
Christof
The OP is just learning PASM2, and I was following his structure. In an application I would pass a pointer to the start of a string that is stored in the hub.
Yes, that is correct. I am currently just going through the manual and learning what the instructions and registers do. Some concepts are pretty easy to understand such a looping and add/sub/mul. Others have a little more fine print to them, like getbyte. It did not click with me that i could do getbyte with one dest but altgb has a different dest. Also, learning how to push an address pointer forward was a key point because the manual does not clearly mention how to perform this.
Here is what I ended up:
con
dat
org
This works perfectly as far as I can tell. I have a ton of C/spin examples to convert to pasm2 which will help me learn more. I will also get rid of the magic numbers. Thank you all and I will try the mov pr0,#msg and .print rdbyte pr1,pr0. As stated before something like that is definitely not in the manual, but learning what the instructions do comes first for now.
Good. Especially in code that you share publicly. For example
I know this sets pin 62 to be a TX UART, but I have no idea what baud to set into my terminal so that I can see the output.
"Quick and dirty" is only ever dirty -- and easy way to create confusion, bugs, and burdensome editing.
If anything, calculating the "magic number" separately and then pasting it into the code is more work than just writing the calculation into the code.
Agreed. I did this in my example: