HP Forums

Full Version: (41) HP-16C+ - 16X=0? issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello
I am trying to port the IEEE conversion program from the HP-16C manual to the HP-16C emulator.
I discovered a problem with the X=0? test of the HP-16C emulator for the HP-41.
When I use the test program below, the test doesn't give the the results I would expect:

Code:
'1'
16INPT
XEQ 'TST'

displays 'X=0' whereas it should show 'X≠0'. Am I doing something wrong or is this a bug?

Code:
 01 LBL "TST"
 02 LBL 01
 03 16#       ( 16X=0?)
 04 6
 05 GTO 05
 06 GTO 06
 07 LBL 05
 08 "X=0"
 09 PROMPT
 10 RTN
 11 LBL 06
 12 "X≠0"
 13 PROMPT
 14 END
Thanks for the bug report, I've corrected the wrong jump-to address in that code - pls. see the updated MOD file attached.
Thanks for the update. That was fast!
I'll check it tomorrow.

(05-30-2023 06:28 AM)Ángel Martin Wrote: [ -> ]Thanks for the bug report, I've corrected the wrong jump-to address in that code - pls. see the updated MOD file attached.
Hello Angel,
I have written a small test program to check the comparisons. The test with 2CMP are all OK. There seems to be a small inconsistency when using 1CMP. The two representations of zero (0 and -0) are both evaluating to zero when using the comparisons X=0?, X#0?, etc. with my HP-16C, but not with the emulator.
I have written a program to check the test. Here is the output:
Code:
2CMP
X=0? YES: OK
X#0? YES: OK
X<0? YES: OK
X<=0?YES: OK
X>0? YES: OK
X>=0?YES: OK
X=Y? YES: OK
X#Y? YES: OK
X<Y? YES: OK
X<=Y?YES: OK
X>Y? YES: OK
X>=Y?YES: OK
X=0? NO: OK
X#0? NO: OK
X<0? NO: OK
X<=0?NO: OK
X>0? NO: OK
X>=0?NO: OK
X=Y? NO: OK
X#Y? NO: OK
X<Y? NO: OK
X<=Y?NO: OK
X>Y? NO: OK
X>=Y?NO: OK
1CMP
X=0? YES: ERR
X#0? NO: ERR
X<0? NO: ERR
X<=0?YES: OK
X>0? NO: OK
X>=0?YES: ERR

Here is the program with comments:
Code:
LBL "TST"
XROM 16,22    ; HEXM
2
XROM 16,02    ; 16#
22            ; LOW16^
XROM 16,09    ; 16WSZ
"2CMP"
AVIEW
FC? 21
PSE
XROM 16,11    ; 2CMP

SF 05          ; Expected "YES"
CF 07        ; Show args?

0
XROM 16,02    ; 16#
22            ; LOW16^
XEQ 02        ; X=0?

1
XROM 16,02    ; 16#
22            ; LOW16^
XROM 16,51    ; 16CHS
XEQ 03        ; X#0?

XEQ 04        ; X<0?

XEQ 05        ; X<=0?

XROM 16,51    ; 16CHS
XEQ 06        ; X>0?

XEQ 07        ; X>=0?

0
XROM 16,02    ; 16#
22            ; LOW16^
XROM 16,52    ; 16ENT^
XEQ 08        ; X=Y?

1
XROM 16,02    ; 16#
22            ; LOW16^
XROM 16,51    ; 16CHS
XEQ 09        ; X#Y?

XEQ 10        ; X<Y?

XEQ 11        ; X<=Y?

1
XROM 16,02    ; 16#
22            ; LOW16^
XEQ 12        ; X>Y?

XEQ 13        ; X>=Y?

CF 05          ; Expected "NO"

XEQ 02        ; X=0?

0
XROM 16,02    ; 16#
22            ; LOW16^
XEQ 03        ; X#0?

XEQ 04        ; X<0?

1
XROM 16,02    ; 16#
22            ; LOW16^
XEQ 05        ; X<=0?

XROM 16,52    ; 16ENT^
XROM 16,51    ; 16CHS
XEQ 06        ; X>0?

XEQ 07        ; X>=0?

0
XROM 16,02    ; 16#
22            ; LOW16^
XEQ 08        ; X=Y?

XROM 16,52    ; 16ENT^
XEQ 09        ; X#Y?

XEQ 10        ; X<Y?

1
XROM 16,02    ; 16#
22            ; LOW16^
XEQ 11        ; X<=Y?

0
XROM 16,02    ; 16#
22            ; LOW16^
XEQ 12        ; X>Y?

XEQ 13        ; X>=Y?

"1CMP"
AVIEW
FC? 21
PSE
XROM 16,10    ; 1CMP

3
XROM 16,02    ; 16#
22            ; LOW16^
SF 05          ; Expected "YES"
XEQ 02        ; X=0?

CF 05          ; Expected "NO"
XEQ 03        ; X#0?

XEQ 04        ; X<0?

SF 05          ; Expected "YES"
XEQ 05        ; X<=0?

CF 05          ; Expected "NO"
XEQ 06        ; X>0?

SF 05          ; Expected "YES"
XEQ 07        ; X>=0?

RTN

LBL 02
XEQ 97        ; Copy flag 05 -> flag 06
"X=0? "
XROM 16,02    ; 16#
6            ; 16X=0?
GTO 98        ; Invert flag and show result
GTO 99        ; Show result

LBL 03
XEQ 97        ; Copy flag 05 -> flag 06
"X#0? "
XROM 16,02    ; 16#
7            ; 16X#0?
GTO 98
GTO 99

LBL 04
XEQ 97        ; Copy flag 05 -> flag 06
"X<0? "
XROM 16,02    ; 16#
8            ; 16X<0?
GTO 98
GTO 99

LBL 05
XEQ 97        ; Copy flag 05 -> flag 06
"X<=0?"
XROM 16,02    ; 16#
9            ; 16X<=0?
GTO 98
GTO 99

LBL 06
XEQ 97        ; Copy flag 05 -> flag 06
"X>0? "
XROM 16,02    ; 16#
10            ; 16X>0?
GTO 98
GTO 99

LBL 07
XEQ 97        ; Copy flag 05 -> flag 06
"X>=0?"
XROM 16,02    ; 16#
11            ; 16X>=0?
GTO 98
GTO 99

LBL 08
XEQ 97        ; Copy flag 05 -> flag 06
"X=Y? "
XROM 16,02    ; 16#
12            ; 16X=Y?
GTO 98
GTO 99

LBL 09
XEQ 97        ; Copy flag 05 -> flag 06
"X#Y? "
XROM 16,02    ; 16#
13            ; 16X#Y?
GTO 98
GTO 99

LBL 10
XEQ 97        ; Copy flag 05 -> flag 06
"X<Y? "
XROM 16,02    ; 16#
14            ; 16X<Y?
GTO 98
GTO 99

LBL 11
XEQ 97        ; Copy flag 05 -> flag 06
"X<=Y?"
XROM 16,02    ; 16#
15            ; 16X<=Y?
GTO 98
GTO 99

LBL 12
XEQ 97        ; Copy flag 05 -> flag 06
"X>Y? "
XROM 16,02    ; 16#
16            ; 16X>Y?
GTO 98
GTO 99

LBL 13
XEQ 97        ; Copy flag 05 -> flag 06
"X>=Y?"
XROM 16,02    ; 16#
17            ; 16X>=Y?
GTO 98
GTO 99

LBL 97
FC? 05        ; Copy flag 05 -> flag 06
CF 06        ; ...
FS? 05        ; ...
SF 06        ; ...
RTN

LBL 99
FC?C 06        ; Invert Flag 06
SF 06        ; ...
LBL 98
FC? 07
GTO 00
VIEW Y
VIEW X
LBL 00
FS? 05
"|-YES: "
FC? 05
"|-NO: "
FS? 06
"|-OK"
FC? 06
"|-ERR"
AVIEW
FC? 21
PSE
END
[attachment=12228]
Lines 02 - 05 in the TST program set the word size to 2, why is that intended??

Testing manually X<0? and X<=0? on 1CMP with 16x = -0d returns the correct "YES" result, not sure why your program doesn't get the same outcome... will need to look at it with more time.

But X=0? returns "NO", which I believe it is correct because -0d is not the same as 0d

in binary, 1CMP representation with WS = 2 :
00 = 11 ?? Not quite, so I'll stick by the current "NO"

isn't that right?
Sorry, if I didn't explained it clearly.

Quote:Lines 02 - 05 in the TST program set the word size to 2, why is that intended??
I just choose the word size for simplicity, because there are only four numbers. In the one complement representation 00B and 11B are both zero, 01B is one and 10B is minus one. The outcome of the program itself is independent of word size if you set the starting value accordingly.

Quote:But X=0? returns "NO", which I believe it is correct because -0d is not the same as 0d
I just set the expected outcome (flag 05) to that of a physical HP-16C. Since 00B and 11B are both zero, on the HP-16C the "X=0?" test give true and the other "X...?" tests are consistent with that. Interestingly the "X=Y?" test with y: 11B and x: 00B on the stack results in "NO", which is correct also for the 16C-library.

Remark:
I don't use the one complement representation, myself. I was just curious how the HP-16C and the 16C-library behave for this special case.
Reference URL's