Post Reply 
[16C] why are some commands entered before their arguments?
03-27-2019, 07:56 PM (This post was last modified: 03-28-2019 08:35 AM by wynen.)
Post: #10
RE: [16C] why are some commands entered before their arguments?
IMHO it was a good idea to make the WSIZE "programmable" (i.e. posfix). Here a sample program, which reverses the byte order for 16bit and 32 bit word size.

The progran first determines the actual word size by shifting a 1 by 16 bits to the left. A carry will indicate 16bit word size.

For 32 bit, the two 16 bit integers are swaped by rotating the 32bit word 16 times. Now the word size is changed to 16 bit and the two bytes are swaped by rotating the 16 bits 8 times. Finally the word size is changed back to 32 bits and the two 16 bit words are combined.

These are the features, which make the HP-16C unique.

Hartmut

Code:

43,22, A : ->LBL A     // start
       1 :   [1]       // determine word size (16Bit/32Bit)
      36 :   ENTER
       8 :   [8]
   42  A :   f SL      // 10hex = 16dec
   42  E :   f RLn     // shift 1 by 16 to left
      33 :   Rdown     // x = entered value
43, 6, 4 :   F? 4      // carry set (from shift operation)?
   22  2 :   GTO 2     // If carry set, it must be 16 bit word size
      36 :   ENTER     // otherwise continue assuming 32 bit word size
      36 :   ENTER
       8 :   [8]
   42  A :   SL        // 10hex = 16dec
   42  F :   RRn       // swap 16bit words
   43 36 :   LSTx      // 10hex = 16dec
   42 44 :   WSIZE     // 16 bit word size
   21  2 :   GSB 2     // swap bytes in 16 bit word
      34 :   x<->y     // the other part
   21  2 :   GSB 2     // swap bytes in 16 bit word
       8 :   [8]
   42  A :   SL        // 10hex = 16dec
   42  A :   SL        // 20hex = 32dec
   42 44 :   WSIZE     // 32 bit word size
       8 :   [8]
   42  A :   SL        // 10hex = 16dec
   42  E :   RLn       // shift low word to high word
   42 40 :   OR        // add both parts
   43 21 :   RTN       // and return
43,22, 2 : ->LBL 2     // swap bytes of a word
       8 :   [8]
   42  F :   RRn
   43 21 :   RTN
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [16C] why are some commands entered before their arguments? - wynen - 03-27-2019 07:56 PM



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