[PASM] Get the address
Good Day,
How I get the memory's address without calculate it by hand ?
The code print some string on Lcd and convert the number 389 in ascii
'Can I write #0 without var char ?
How I can return without jump to :done ?
How I get the memory's address without calculate it by hand ?
The code print some string on Lcd and convert the number 389 in ascii
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PUB Main cognew(@entry, @msg) repeat ' the spin stops here dat ' separate dat section to show msg is independent long msg byte "Hello ",0 'Test First message msg2 byte "World !",0,0 'Test second message buffer res 1 dat org 0 entry mov dira,port 'Config Port I/O 'INIT THE LCD mov _tmpDelay,#500 Call #Delayms 'Wait for powerUp lcd about 0.5s Call #lcd_init 'Init Lcd ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'READ STRING MSG AND MSG2(#7) FROM MEMORY AND PRINT IT mov _ndx,par 'read the address of msg to ndx Call #LcdChar mov _ndx,par 'read the address of msg to ndx add _ndx,#7 'I WOULD LIKE GET THE ADDRESS WITHOUT CALCULATE IT BY HAND ( @msg2 ? ) Call #LcdChar ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'CONVERT THE NUMBER #389 TO ASCII ( THREE DIGIT ) AND PRINT IT, 'WRITE IT TO MEMORY, READ IT FROM MEMORY AND PRINT IT AGAIN andn outa,rs 'Get ready for next string mov cmd,#$C0 'second line call #LcdDat 'Send command or outa,rs ' mov _ndx,par 'read the address add _ndx,#17 'My buffer start here ( 17th byte ) I WOULD LIKE GET THE ADDRESS WITHOUT CALCULATE IT BY HAND Call #decToAscii 'Convert #389 to ascii. This is a test ( there is no reverse string) mov _ndx,par 'read buffer add _ndx,#17 ' Call #LcdChar 'Print memory contents :done jmp #:done 'nothing left to do, just jmp #done forever ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' LcdChar or outa,RS :loop rdbyte cmd,_ndx 'read the character from ndx tjz cmd,#:done 'if the character is 0, exit the loop Call #LcdDat 'character is not 0, print it mov _tmpDelay,#511 Call #Delayms add _ndx, #1 'get the next character address jmp #:loop 'repeat the loop :done LcdChar_ret ret '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' decToAscii ' TEST mov number,#389 'this is what I want view on Lcd :loop Call #Modulus 'digit = number % 10 mov __x,number 'x = number mov __y,#10 'y = 10 Call #Divide 'number = number / 10 andn __x,clrW 'Clear remainder ( High word) mov number,__x 'copy to var number the new value ( number /=10) mov char,digit 'copy digit to char add char,#48 'Add '0' to char. The ascii-characters for numbers start at 48 (for 0) up to 57(for 9) mov cmd,char 'ready to send to Lcd Call #LcdDat 'Send char to Lcd wrbyte char,_ndx add _ndx,#1 tjnz number,#:loop 'if number = 0 Exit mov char,#0 wrbyte char,_ndx 'I WOULD LIKE WRITE AN IMMEDIATE VALUE ( ZERO ) decToAscii_ret ret '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Can I write #0 without var char ?
mov char,#0 wrbyte char,_ndx
How I can return without jump to :done ?
tjz cmd,#:done :done retThanks in advance
Comments
-Phil
-Phil
That way all you have to do is reference the message by number.
It works , Thanks
@Jazzed : yes it would be better, but I dont know what mailbox means, where I can read about it ?
is there an example ?sry I'm learning step by step
Thanks
Basically you can pass a PAR value to PASM like cognew(@pasm, @value).
The @value is the address of the variable value.
You can use value as an "anchor" for a set of variables - for example: That is a set of variables which can be used as a mailbox.
Now, consider this:
You can read the contents of value and friends in PASM almost the same way you read "msg" before. The problem is in getting the initial address of each message. Here's an example to study.
If you are - what looks like - concerned about speed/wasted cycles then you should use something like this: So in case the jump is taken you spend 4 cycles, in case it's not you only have to worry about a nop (rather than the full jump-not-taken penalty).
sry for later answer
@Jazzed : I am constrained to know the message 's address but it works thanks
@kuroneko: thanks for your tips
@ChrisGadd : because that @@ is part of Chap 2 Spin Section I haven't read it ( my error )
I will try it thanks
Edit :
It works thanks !