News:

  • May 17, 2024, 03:29:27 AM

Login with username, password and session length

Author Topic: IB-521 example for mod results  (Read 3365 times)

8bits

  • Jr. Member
  • **
  • Posts: 19
IB-521 example for mod results
« on: October 17, 2008, 08:18:40 PM »
Hello, can any one give an example on getting the remainder from a IB-521 where it is just simple as:
(V2000/k600). Not sure how to specify to get the remainder and as there is only one destination for the results do I have to
do two separate math operations? :-\

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3561
  • Darth Ladder
Re: IB-521 example for mod results
« Reply #1 on: October 17, 2008, 09:57:59 PM »
The MOD operator is '%', so to get the remainder enter "V2000 % K600" in the expression box.  If you want both the integer quotient and the remainder, yes, you will have to do two operations.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3666
    • Host Engineering
Re: IB-521 example for mod results
« Reply #2 on: October 18, 2008, 11:26:04 AM »
If you need both, and you have both the numerator and denominator in a V memory register, it's best to do it "the old way" because the DIV PLC instruction does both at the same time.  The MATH IBoxes have to do funky math accumulator stack manipulation to work properly to do JUST a divide or JUST a mod.  You actually would end up doing TWO DIV instructions with the two expressions
MATH divresult "Numerator / Denominator"
MATH modresult "Numerator % Denominator "

You would be best off doing in the native math instructions (no IBox)
LD  Numerator
DIV Denominator
OUT divresult
POP
OUT modresult
« Last Edit: October 18, 2008, 11:27:47 AM by franji1 »

8bits

  • Jr. Member
  • **
  • Posts: 19
Re: IB-521 example for mod results
« Reply #3 on: October 18, 2008, 12:51:00 PM »
Thanks for the information, I will do it that way.
 :)