Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 4th October 2006, 01:12 PM   (permalink)
Default macro

hold macro ;delay macro for I2C
nop
nop
nop
endm

disp_str macro string ;Macro for sending string to LCD
irpc char, <string>
if nul 'char'
exitm
endif
mov a,#'char'
lcall data_in
endm
endm

interfacing ds1307 with 8051 cant understand this macro i got from net...can anyone help??
baftab is offline  
Reply With Quote
Old 22nd June 2007, 06:13 PM   (permalink)
Default

what is your compiler?
chevali is offline  
Reply With Quote
Old 23rd June 2007, 02:56 AM   (permalink)
Default

Quote:
Originally Posted by baftab
hold macro ;delay macro for I2C
nop
nop
nop
endm

disp_str macro string ;Macro for sending string to LCD
irpc char, <string>
if nul 'char'
exitm
endif
mov a,#'char'
lcall data_in
endm
endm

interfacing ds1307 with 8051 cant understand this macro i got from net...can anyone help??
I'm guessing this is an 8051 assembler from the presence of the lcall instruction. For each character in the string an instruction sequence is generated which moves the character into the accumulator and then calls the data_in subroutine.

IMHO this is a really silly and stupid way to do things for strings which are longer than 3 or 4 characters.

Example:
disp_string "Hello World"

would expand as:
Code:
        mov  a,#'H'
        lcall  disp_in
        mov  a,#'e'
        lcall  disp_in
        mov  a,#'l'
        lcall  disp_in
        mov  a,#'l'
        lcall  disp_in
        mov  a,#'o'
        lcall  disp_in
        mov  a,#' '
        lcall  disp_in
        mov  a,#'W'
        lcall  disp_in
        mov  a,#'o'
        lcall  disp_in
        mov  a,#'r'
        lcall  disp_in
        mov  a,#'l'
        lcall  disp_in
        mov  a,#'d'
        lcall  disp_in

Last edited by Papabravo; 23rd June 2007 at 03:01 AM.
Papabravo is offline  
Reply With Quote
Old 23rd June 2007, 04:33 AM   (permalink)
Default

PB,
How does that macro loop? Does it automatically produce the code for each character in the string?

Mike.
Pommie is offline  
Reply With Quote
Old 23rd June 2007, 07:07 PM   (permalink)
Default

The irpc is a macro within a macro. It stands for "indefinite repeat character". It is common to many assemblers going back to at least the 1960's. Here is a snippet from the top google hit

http://www.physic.ut.ee/rprojekt/PicBasic/PM.TXT

5.2. IRPC

IRPC Param , String
Body
ENDM

The body of the macro is repeated once for each character in the specified
string. The specified parameter is substituted on each expansion with the
scanned character. The IRPC macro is executed immediately.


That is also why there are two "endm" statements. The inner one is for the irpc and the outer one is for the disp_str macro

Last edited by Papabravo; 23rd June 2007 at 07:09 PM.
Papabravo is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Timer0 Prescale lord loh. Micro Controllers 10 8th October 2008 05:13 PM
Macro in MPLAB_IDE KANADE D.G. Micro Controllers 2 6th September 2006 04:01 AM
size of arguments in macro subot.robot Micro Controllers 3 11th May 2006 06:01 AM
Difference between Macro and Subroutine? NewGeek Micro Controllers 4 31st August 2004 07:13 PM
pic assembly - macro or subroutine??? spyghost Micro Controllers 3 18th May 2004 04:28 AM



All times are GMT. The time now is 06:55 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.