News:

  • June 09, 2026, 01:48:34 PM

Login with username, password and session length

Author Topic: error in instruction documentation  (Read 22466 times)

keith

  • Full Member
  • ***
  • Posts: 21
error in instruction documentation
« on: May 19, 2010, 02:49:03 PM »
FROM A TECHNICAL POINT OF VIEW, THE DOCUMENTATION FOR THIS INSTRUCTION IS WRONG.

[ documentation ]
Add Binary (ADDB)
Add Binary is a 16 bit instruction that adds the
unsigned 2’s complement binary value in the
lower 16 bits of the accumulator with an unsigned
2’s complement binary value (Aaaa), which is
either a V memory location or a 16-bit constant.
The result can be up to 32 bits (unsigned 2’s
complement) and resides in the accumulator.

[ Why I say it is wrong ]
If the accumulator contains 0037FFFF and I add 1 to it, as the documentation is written, I should get 10000 because it adds the lower 16 bits of the accumulator FFFF with 1 and  gives the 32 bit result 10000.

However, the instruction actually adds the 32 bit value in the accumulator with the 16 bit argument, and gives a 32 bit result.   So 0037FFFF + 0001 = 00380000

Not sure if this comment belongs in this forum, but since the wrong documentation also comes with the online help, I figured it was ok to place my comment here.

Keith
« Last Edit: May 19, 2010, 03:55:50 PM by keith »

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: error in instruction documentation
« Reply #1 on: May 19, 2010, 03:04:18 PM »
Can you note the CPU and instructions you used to come to this conclusion?
« Last Edit: May 19, 2010, 03:10:07 PM by b_carlton »
An output is a PLC's way of getting its inputs to change.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: error in instruction documentation
« Reply #2 on: May 19, 2010, 03:23:32 PM »
He's definitly right.  "16 bit" instructions only means that the PARAMETER is 16 bit.  The instruction ALWAYS applies itself to the 32 bit accumulator.  Likewise, "32 bit" instructions means that the instruction's parameter is 32 bit, and like 16 bit instructions, is applied to the whole 32 bit accumulator.

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: error in instruction documentation
« Reply #3 on: May 19, 2010, 03:36:38 PM »
Quote
So 0037FFFF + 0001 = 00400000

I was actually questioning this.

On a DL06 With:
LDD K37ffff
ADDB K1
OUTD V1770

V1770/1 contained 380000, not 400000
An output is a PLC's way of getting its inputs to change.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: error in instruction documentation
« Reply #4 on: May 19, 2010, 03:50:05 PM »
Quote
So 0037FFFF + 0001 = 00400000

I was actually questioning this.

On a DL06 With:
LDD K37ffff
ADDB K1
OUTD V1770

V1770/1 contained 380000, not 400000
Oops!  You're right.  Ain't working with octal/hex fun?!?

keith

  • Full Member
  • ***
  • Posts: 21
Re: error in instruction documentation
« Reply #5 on: May 19, 2010, 03:54:08 PM »
I had an error in the example in my original post [isn't it good I am not responsible for creating the documentation].  I corrected the post with a proper example.  The error in the documentation still exists.

LDD V1400
ADDB V1402
OUTD V1404

with a data view DWORD HEX/BCD
37FFFF -> V1400
000001 -> V1402
V1404 will contain 380000

If executed PER the docs, FFFF+0001=10000

Sorry about the example in my original post.
 
As far as I can tell, the add/subtract instructions always use 32 bit calculations.  The instruction width is just the width of the argument, not the acc.

It should be noted that the 16 bit number is not signed extended to do a proper 32 bit + 16 bit signed addition.  I think the documentation already reflects this fact by saying "unsigned".  However, I don't see how unsigned and 2's complement belong in the same sentence.  If it is unsigned, it is not 2's complement.  2's complement is a way to represent signed numbers.
« Last Edit: May 19, 2010, 04:13:50 PM by keith »

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: error in instruction documentation
« Reply #6 on: May 19, 2010, 04:10:53 PM »
The error in the documentation still exists.
...
The instruction width is just the width of the argument, not the acc.
Yup.  We wrote up a case in our database for this (to update Help and Instruction Browser), and we will check on the user manual and let ADC know about that.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: error in instruction documentation
« Reply #7 on: May 19, 2010, 04:12:15 PM »
Oh, and per my forum signature, I guess I don't know Hex or Octal, but I do know Binary!  ;D

keith

  • Full Member
  • ***
  • Posts: 21
Re: error in instruction documentation
« Reply #8 on: May 19, 2010, 05:17:58 PM »
I also question the correctness of the "unsigned 2's complement" part.  Either a binary number is "unsigned" or "signed 2's complement".  "Unsigned 2's complement" makes no sense.  The 2's complement part specifys how the signed number is stored. (as opposed to 1's complement).

Strictly speaking, the instruction can do 2 different things:

1) add the usnigned 32 bit binary number in the acc with the unsigned 16 bit binary arg, giving a 32 bit unsigned binary result.

2) add the signed 2's complement 32 bit binary numnber with an unsigned 16 bit binary number giving a signed 2's complement binary result.

which of the 2 cases it does is determined by how you use the results and status flags.

The whole idea of using 2's complement binary and unsigned binary is that for like word sizes, the same add/subtract instructions can do either. However, in this case the word sizes of the 2 arguments are different.  Since the instruction does not sign extend the 16 bit number to 32 bits, it would be incorrect to say that the 16 bit number is signed (it is always interpreted as unsigned)  However, the 32 bit number could be either signed 2's complement binary or unsigned binary.

if I were writting the documentation, I would say that it adds the 32 bit binary (unsigned or signed 2's complement) number with the 16 bit binary unsigned number, leaving a 32 bit binary (unsigned or signed 2's complement) number in the acc.
   
Keith

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: error in instruction documentation
« Reply #9 on: May 19, 2010, 08:53:20 PM »
Oh, and per my forum signature, I guess I don't know Hex or Octal, but I do know Binary!  ;D

Yeah, but that joke's boring in hex or octal.  Base 1 (hashmark) might be entertaining.

"There are only || kinds of people in this world: those who know Base |, and those who don't"
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: error in instruction documentation
« Reply #10 on: May 19, 2010, 09:15:31 PM »
Come on - the "There are only 10 ..." joke's almost as old as "Who's On First ?" and I still laugh at that. But only if the original is played. I'm guessing  Hollerith or Jaquard first used it.
An output is a PLC's way of getting its inputs to change.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: error in instruction documentation
« Reply #11 on: May 19, 2010, 11:10:45 PM »
No, I was saying that I do like it in binary.  I was saying it would be boring in hex or octal.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 702
  • Hmmm...
    • Host Engineering, Inc.
Re: error in instruction documentation
« Reply #12 on: May 20, 2010, 02:27:31 PM »
The error in the documentation still exists.
...
The instruction width is just the width of the argument, not the acc.
Yup.  We wrote up a case in our database for this (to update Help and Instruction Browser), and we will check on the user manual and let ADC know about that.
I had AutomationDirect enter this manual change in their manual-change database, so it will be in the next release of the manual, I'm sure.
There are two types of people in the world; those that can extrapolate from incomplete data sets.