macro

Status
Not open for further replies.

baftab

New Member
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:
PB,
How does that macro loop? Does it automatically produce the code for each character in the string?

Mike.
 
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

**broken link removed**

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:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…