passing pointers to strings

General discussion on mikroBasic PRO for 8051.
Post Reply
Author
Message
free_electron_2
Posts: 17
Joined: 20 Oct 2009 19:20

passing pointers to strings

#1 Post by free_electron_2 » 20 Oct 2009 20:13

Code: Select all

sub procedure my_lcd_print (dim byref x as word)
    dim p as ^word  ' create pointer
    p = @x              ' attach to x
    while p^ <>0
         P0 = p^
         p1.B4 = 1
         p1.B4 = 0
         inc(p)
    wend
end sub

 main:
 my_lcd_print ("hello world")
  while TRUE                        ' Endless loop
  wend
end.
when i look at the machine language the string 'hello world' gets moved and shuffled around. that is a pure waste of cpu cycles.
how can i pass a pointer to a string to a subroutine ?

I am trying to make optimised libraries. the standard libraries consume waay too much room and are too slow.

free_electron_2
Posts: 17
Joined: 20 Oct 2009 19:20

#2 Post by free_electron_2 » 20 Oct 2009 21:07

To clarify : this is the intended target code i want to create

Code: Select all


loop:
    MOV   DPH,STRP                 ; set DPTR to point to string
    MOV   DPL,STRP+0001H
    CLR   A                               ; clear accumulator
    MOVC  A,@A+DPTR             ; copy contents of dptr into accumulator
    JZ   done                             ; if zero : end of string jump to exit point
    SETB  P34                           ; set P34 (RS pin of LCD)
    MOV   P1,A                          ; throw accumulator onto P1 (data port of LCD)
    CLR   P30                            ; clear P30 ( EN pin of LCD )
    SETB  P30                           ; set P30 (EN pin of LCD)
    INCR DPTR
    SJMP  loop
done:
    RET

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#3 Post by anikolic » 26 Oct 2009 11:36

I am sorry, I have posted the answer to this on your other thread. Please refer to here http://www.mikroe.com/forum/viewtopic.p ... 571#111571

Sorry for the inconvenience.

Best regards,
Aleksandar
Web Department Manager

Post Reply

Return to “mikroBasic PRO for 8051 General”