PDA

View Full Version : MPASM Help



rwskinner
- 19th February 2008, 04:09
This is all greek to me. MPASM is saying I have a "Aurgument out of range - Using LSB". Line 206 of Mac File.

SUB?CBB macro Cin, Bin, Bout
MOVE?BA Bin
sublw Cin <------- Line 206
MOVE?AB Bout
endm

I have not a clue to what any of this is or what is causing the warning error.
18F4530 PBP 2.46 MPASM

Any hints or clues? Never used MPASM before and it's got me all bent out of shape.
Richard

skimask
- 19th February 2008, 04:20
This is all greek to me. MPASM is saying I have a "Aurgument out of range - Using LSB". Line 206 of Mac File.

SUB?CBB macro Cin, Bin, Bout
MOVE?BA Bin
sublw Cin <------- Line 206
MOVE?AB Bout
endm
I have not a clue to what any of this is or what is causing the warning error.
18F4530 PBP 2.46 MPASM
Any hints or clues? Never used MPASM before and it's got me all bent out of shape.
Richard

I'm fairly sure it means that you're using a word, and the function wants a byte, so it only uses the low byte.
Figure out which line 'calls' this line in the assembly file and you should have your answer.

rwskinner
- 19th February 2008, 04:46
Thanks, this helped a lot.

The offending code, which works fine is.....
LRC = 256 - LRC

LRC is defined as a byte, but I have to subtract LRC from $100
I guess I could say....
LRC = $FF - LRC
LRC = LRC -1

Would be the same thing..., unless there is a better way or I just need to ignore the error since we only need the 8 LSB anyway.

Richard

Charles Linquis
- 19th February 2008, 06:00
Are you doing SNMP by any chance?

rwskinner
- 19th February 2008, 12:06
No, Modbus ASCII LRC Calculation

Bruce
- 19th February 2008, 21:49
Assume LRC = 10.

LRC = 256 - LRC. Which works out to LRC = 246, but returns a warning message.

Now try this approach with LRC still = 10;

LRC = $FF - LRC ' LRC = 255 - 10. Now LRC = 245
LRC = LRC - 1. Now we have 245 - 1 which = 244. Oops! Not what we expected, although it
looked darn good at 1st glance.

Now try this, and see if you can figure out why it works & doesn't return the warning
message;

LRC = !256-LRC ' LRC = NOT 256 - LRC

Here's a short test to verify it;


LRC VAR BYTE
X VAR BYTE

Main:
FOR X = 0 TO 255
LRC = X ' We'll work with LRC = 0 to 255 to prove it works
HSEROUT ["256-",DEC X,"="]
LRC = !256-LRC
HSEROUT [DEC LRC,13,10]
NEXT X
Here:
GOTO Here ' done
END

Food for thought ehh....;o}

A more efficient approach would be to just promote LRC to a word variable,
and use the lower byte for your result, but this is pretty cool.

skimask
- 19th February 2008, 21:54
.....Now try this, and see if you can figure out why it works & doesn't return the warning message;

That's pretty slick...
I almost missed it and was about to reply back that you were wrong in this instance. :D Good thing I didn't. My foot goes in my mouth enough as it is...

Bruce
- 19th February 2008, 22:19
It certainly wouldn't be the 1st time I was wrong, but it does work..;o}