Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

size of arguments in macro

Status
Not open for further replies.

subot.robot

New Member
What is the maximum size of the arguments that are passed to macros?If it is greater than 1 byte how can we store it in different registers or memory location? I want to pass an argument which can have maximum value of 1000 to a macro. The macro has to store the lower byte in TMR3l and higher byte in TMR3H. How can I do this?

Thanks
 
You did not say which processor/assembler combination you are using. TMR3 sounds lik the name of a timer in one of the PIC variants.

To answer the question you break it up into its component parts. The low order eight bits are extracted with an expression like
Code:
  movlw  timeValue & 0xFF

The high order eight bits can be obtained with
Code:
  movlw  timeValue >> 8
The double angle bracket operator means that timeValue should be shifted to the right. The literal '8' says how many places to shift right. In most cases this will be an arithmetic shift rather than a logical shift. Experimentation is in order if the documentation is unclear, ambiguous, or does not address the issue.

Since the assembler's expression arithmetic is done with 32 bit unsigned numbers you can extract additional bytes wirh
Code:
  movlw  timeValue >> 16
  movlw  timeValue >> 24
 
Several ways to do it... Here are a couple to supplement Papa Bravo's examples...

Best wishes... Regards, Mike

Code:
;
;
Read_Target_ID

        SETADR	h'3FFFFE'	;set TARGx vars to h'3FFFFE'

[...]

SETADR	macro   address
        movlw	UPPER(address)
        movwf	TARGU
        movlw	HIGH(address)
        movwf	TARGH
        movlw	LOW(address)
        movwf	TARGL
        endm

Code:
;
;
        movlw   address/.256
        movwf   TARGH
        movlw   address%.256
        movwf   TARGL
;
 
Last edited:
Thanks for the reply Papabravo and Mike.
I am using PIC18F452 microcontrollerand mpasm assembler.

Regards
Subot.robot
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top