Continue to Site

# PIC assembly macro parameter transfer

#### Peet19

##### Member
Hello!
I want to pass the value of a register to a macro, but I don't know.
How can this be solved?
Code:
 MOVLW 100
MOVWF XY

LOOP
MOVLW 10
SUBWF XY
VAR1 SET XY
BEIR VAR1

GOTO LOOP

I decreased the value of the XY register by 10 in each cycle.
If I enter the name of the register as a parameter of the macro, it does not pass the value.
I already tried changing the value of XY to a variable and passing it when calling the macro, but that's no good either.
What could be the problem?

Here is the macro:
Mist:
BEIR MACRO A
MOVLW A
MOVWF ZZ
ENDM

But if I enter a number when calling the macro it works.
I don't understand the problem.
Thank you in advance for your help!

Last edited:
Solution
You might find this website useful:

Have a look at 5.3.3 where it passes a variable as par0 - notice it doesn't use MOVLW.

#### Peet19

##### Member
If someone could tell me how to load the value of a register into a variable, I would really appreciate it.

Eg: VAR1 SET XY

it only loads the address of the register into the variable, not its value.
I just need the value, it would solve my problem.
Thank you very much in advance.

#### Nigel Goodwin

##### Super Moderator
Most Helpful Member
If someone could tell me how to load the value of a register into a variable, I would really appreciate it.

Eg: VAR1 SET XY

it only loads the address of the register into the variable, not its value.
I just need the value, it would solve my problem.
Thank you very much in advance.

What about MOVF ?

There is no 'set' instruction in mid-range assembler, what device are you using?.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
Most Helpful Member
most register commands will use the W register..

equ VAR1 0x32 ; declare variable
movlw .14,w ; mov decimal 14 into W
movwf VAR1,f ; mov w into VAR1

Looking at your macro BEIR takes a value in W then moves it to ZZ ie it does what I did above

usage BEIR VAR1.. This will place whatever is in VAR1 into variable ZZ

Never seen SET so this must be a macro as well

loop:
movf XY,w ; move XY into W
BEIR XY ; store it in ZZ
Movf XY,w
sublw 10
movwf XY
goto loop

ZZ should be decreased every loop. !!UNTESTED!! as I use C most of the time.

Sorry Nigel.. I was typing SSLLOOWWLLYY

#### Peet19

##### Member
I use 18F24k22.
I load the value of register XY into W with MOVF. True?
How can I put it in the variable VAR1?

#### Peet19

##### Member
Thanks Ian, I'll test it.
Nigel: I'm using MPLAB 8.92.

#### Dan Soze

##### Member
You seem to be just starting to learn about assembly language coding.

You should start by describing a little about what you know about using the Microchip controllers and tools. Like the part number of the controller, the version of the Microchip IDE, and the type of operating system you run on your work station. The answer should be something like: PIC16F887, MPLABX version 5.35, Windows 10.

It seems that Ian got you an answer while I was typing this.

There is now the partial answer: PIC18F24K22, MPLAB version 8.92 and Windows (no version mentioned)

Since you seem new to assembly language should we presume that you are using the "Absolute" mode of the MPASM assembler?

Most of the example code I have is for the "Relocatable" mode.

The "Absolute" mode is easier to comprehend but has some "features" that can make using the debugger somewhat confusing.

Last edited:

#### Peet19

##### Member
PIC18F24K22, MPLAB version 8.92 and Linux.
Yes, I use it in absolute mode, because I can see my own registers in the Watch window.

#### Dan Soze

##### Member
I have only used MPLAB version 8.92 on Windows. I suspect that running it on Linux may require some kind of Windows OS emulation. I hear this can be tricky to get the Microchip debug tools working.

#### Peet19

##### Member
Fails.
I did a simple test, but it's still not good.
85 will be in VAR1 and 200 will not be included.
In other words, I give the macro 85, not 200.
I do not understand.
All I need to do is load the value of a register into a variable that I can pass to the macro when the macro is called.

VAR1 EQU 85

TESTM MACRO A
MOVLW A
ENDM

MAIN
MOVLW 200
MOVWF CNT1

CLRF WREG

MOVF CNT1, W
MOVWF VAR1

TESTM VAR1

GOTO MAIN

Last edited:

#### Peet19

##### Member
Dan:
Sorry, MPLAB is running on Windows 8 on a virtual machine.

#### Mike - K8LH

##### Well-Known Member
Code:
testm   macro   addr            ; param is a variable address
banksel addr            ;
movf    addr,W          ; W = value in 'addr'
endm

testv   macro   value           ; param is a literal value
movlw   value           ; W = value
endm

#### augustinetez

##### Active Member
There is no 'set' instruction in mid-range assembler, what device are you using?.
Really? From MPASM 8.92 help file.

#### augustinetez

##### Active Member
I load the value of register XY into W with MOVF. True?
How can I put it in the variable VAR1?
MOVF XY,W ; W = value that was in XY
MOVWF VAR1 ; VAR1 = value that was in XY

#### Nigel Goodwin

##### Super Moderator
Most Helpful Member
Really? From MPASM 8.92 help file.

Yes really - those aren't PIC instructions - check the list of instructions in the datasheets. It's an assembler directive, NOT an instruction. I suspect the OP is mostly getting confused by what are 'instructions' and what aren't.

#### Nigel Goodwin

##### Super Moderator
Most Helpful Member
Fails.
I did a simple test, but it's still not good.
85 will be in VAR1 and 200 will not be included.
In other words, I give the macro 85, not 200.
I do not understand.
All I need to do is load the value of a register into a variable that I can pass to the macro when the macro is called.

Code:
VAR1   EQU   85

TESTM   MACRO   A
MOVLW    A
ENDM

MAIN
MOVLW   200
MOVWF   CNT1

CLRF   WREG

MOVF   CNT1, W
MOVWF    VAR1

TESTM   VAR1

GOTO   MAIN

MOVLW means MOVe Literal to W - so will move the value 'A' (0x41) to W, and the variable A isn't used at all.

If you're posting code, put it in the 'code' quotes, as I've done above.

#### Peet19

##### Member
Yes, I did it as you write, but it's still not good.
Check out my code:
When the TESTM VAR1 macro is called, the value of VAR1 should be 200, but instead it is 85, i.e. the original value.

#### Peet19

##### Member
Something is very wrong.
Check out.
When I call the macro, the address of the parameter is passed, not the value of VAR1.
The rest works fine, but this one is not good.
I would like to be able to send the value of VAR1 to the macro.

If I understand correctly, it is not possible to pass a parameter to the macro that is variable?

Last edited:

#### Nigel Goodwin

##### Super Moderator
Most Helpful Member
Something is very wrong.
Check out.
When I call the macro, the address of the parameter is passed, not the value of VAR1.
The rest works fine, but this one is not good.
I would like to be able to send the value of VAR1 to the macro.

View attachment 140745

If I understand correctly, it is not possible to pass a parameter to the macro that is variable?
See post #17, you're still using MOVLW to pass a fixed value (0x41) in line 89 - look up MOVF

Replies
3
Views
7K
Replies
23
Views
849
Replies
10
Views
2K
Replies
44
Views
4K
Replies
4
Views
9K