Host Engineering Forum
General Category => DirectSOFT => Topic started by: keith 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
-
Can you note the CPU and instructions you used to come to this conclusion?
-
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.
-
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
-
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?!?
-
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.
-
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.
-
Oh, and per my forum signature, I guess I don't know Hex or Octal, but I do know Binary! ;D
-
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
-
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"
-
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.
-
No, I was saying that I do like it in binary. I was saying it would be boring in hex or octal.
-
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.