Post Reply 
(28S) Binary Arithmetic routines
08-23-2023, 08:40 PM
Post: #1
(28S) Binary Arithmetic routines
An excerpt from E D N magazine (international edition), Calculator performs 2's-complement math, 1990/10/11, page 221, Peter Kielbasiewicz.

"The calculator programs in Listing 1―HP-28 binary-arithmetic routines make up for the Hewlett-Packard HP-28 calculator's lack of 2's-complement binary-conversion routines."

"The first program negates a number in 2's-complement form."
Code:

BNEG                                       ;negate a number with 
                                           ;respect to 2's complement
<< -> a                                    ;store entered number into local variable
 << IF ->STR NUM 35 SAME                   ;if number begins with '#'
    THEN a NOT 1 +                         ;then make 2's complement
    ELSE a NEG                             ;else simply negate
    END
 >>
>>

"The second program converts numbers from real to binary and binary to real."
Code:

BCONV                                      ;convert from real to binary with 
                                           ;respect to 2's complement
<< -> a                                    ;store entered number into local variable
 << 2 RCWS 1 - ^ -> b                      ;b = max pos number for act wordsize
  << IF a  ->STR NUM 35 SAME               ;if number begins with '#'
     THEN a B->R                           ;then convert it to real
          IF DUP b >=                      ;     if a >= b
          THEN b 2 * -                     ;     then make negative result 
          END                              ;     endif
     ELSE IF a 0 >=                        ;else if a >= 0
          THEN IF a b >=                   ;     then if a >= b
               THEN "Size Err"             ;          then ERROR (a > max)
               ELSE "a NEG R->B            ;          else make positive binary
               END                         ;          endif
          ELSE IF a b NEG <                ;     else if a < -b
               THEN "Size Err"             ;          then ERROR (a < min)
               ELSE "a NEG R->B NOT 1 +    ;          else make negative binary
               END                         ;          endif
          END                              ;     endif
     END                                   ;endif
  >>
 >>
>>

BEST!
SlideRule
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)