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.

PIC assembly macro parameter transfer

Status
Not open for further replies.

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:
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.
 
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?.
 
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
 
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:
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.
 
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:
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
 
There is no 'set' instruction in mid-range assembler, what device are you using?.
Really? From MPASM 8.92 help file.

ASM_SET.jpg
 
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.
 
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.

FR.png



If I understand correctly, it is not possible to pass a parameter to the macro that is variable?
 
Last edited:
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
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top