Post Reply 
NOP on HP-41C
11-21-2020, 09:58 PM
Post: #1
NOP on HP-41C
Likely a question that came up decades ago... what is the fastest way to implement NOP on a 41C without disturbing the stack? I have been using FIX 5 - is there a better way?

Related to this, is it faster to use:
ISG 00
FIX 5 (NOP)

or:
1
STO+00
Find all posts by this user
Quote this message in a reply
11-21-2020, 10:36 PM (This post was last modified: 11-21-2020 10:37 PM by Thomas Okken.)
Post: #2
RE: NOP on HP-41C
You can find out which is faster by simply trying it. Try both options, have them run for a few seconds, and see how far they count when running the same amount of time.

If the instruction following the ISG is guaranteed to always be skipped, it doesn't matter what you put there or what side effects it has. You could use, say, DEG, because it takes only 1 byte. Or, my personal preference, use something that has no side effects at all, to make it clear what is intended; efficiency isn't the only concern when programming, making it easy to read and understand is also a good idea. A nice straightforward NOP for the 41C is STO X.
Visit this user's website Find all posts by this user
Quote this message in a reply
11-21-2020, 10:58 PM
Post: #3
RE: NOP on HP-41C
(11-21-2020 09:58 PM)Benoit Maag Wrote:  Likely a question that came up decades ago... what is the fastest way to implement NOP on a 41C without disturbing the stack? I have been using FIX 5 - is there a better way?

Related to this, is it faster to use:
ISG 00
FIX 5 (NOP)

or:
1
STO+00

Something like LBL 00 is best both as a NOP and after that ISG: it only takes 1 byte, has no side effects and executes fastest.

Also, the ISG is faster than the 1, STO+ and doesn't affect the stack so it doesn't lose T.

V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
11-22-2020, 12:00 AM
Post: #4
RE: NOP on HP-41C
X <> X

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
11-22-2020, 12:35 AM
Post: #5
RE: NOP on HP-41C
(11-22-2020 12:00 AM)Massimo Gnerucci Wrote:  X <> X

STO X is 2.75 ms faster
which of course only matters if it is ever actually executed
and probably not even then Big Grin
Visit this user's website Find all posts by this user
Quote this message in a reply
11-22-2020, 12:39 AM
Post: #6
RE: NOP on HP-41C
Synthetic programming came up with TEXT 0 as the apparently preferred NOP to use. Does not affect the stack or ALPHA and is faster (?) than the other options ?

Of course, requires synthetic programming, but I'm never without Angel's masterpiece roms so no problem.
Find all posts by this user
Quote this message in a reply
11-22-2020, 12:43 AM (This post was last modified: 11-22-2020 12:43 AM by Sylvain Cote.)
Post: #7
RE: NOP on HP-41C
The ultimate NOP is the synthetic TEXT 0 (0xF0).
With the ZenROM, in program mode, you XEQ "NOP" and it will enter the 0xF0 code in your program, otherwise you can always use the byte loader program.

Edit: Gene was faster than me. Wink
Find all posts by this user
Quote this message in a reply
11-22-2020, 12:50 AM
Post: #8
RE: NOP on HP-41C
(11-22-2020 12:43 AM)Sylvain Cote Wrote:  The ultimate NOP is the synthetic TEXT 0 (0xF0).

Hmm. I have been thinking about how to add a NOP instruction to Free42 in a backward-compatible manner, and I had completely forgotten about TEXT 0. It fits the bill perfectly! Nice, I'll go ahead and use that, then. Smile
Visit this user's website Find all posts by this user
Quote this message in a reply
11-22-2020, 01:34 AM
Post: #9
RE: NOP on HP-41C
Great Thomas!
Find all posts by this user
Quote this message in a reply
11-22-2020, 02:01 AM
Post: #10
RE: NOP on HP-41C
Thank you all for all the options!
Find all posts by this user
Quote this message in a reply
11-22-2020, 02:48 AM
Post: #11
RE: NOP on HP-41C
I use:

STO X

Namir
Find all posts by this user
Quote this message in a reply
11-22-2020, 03:38 PM
Post: #12
RE: NOP on HP-41C
Thank you all for all the options!
Find all posts by this user
Quote this message in a reply
12-28-2020, 12:25 PM
Post: #13
RE: NOP on HP-41C
(11-22-2020 12:50 AM)Thomas Okken Wrote:  Hmm. I have been thinking about how to add a NOP instruction to Free42 in a backward-compatible manner, and I had completely forgotten about TEXT 0. It fits the bill perfectly! Nice, I'll go ahead and use that, then. Smile

a SKIP instruction would also be nice, but there is no 1-byte equivalent that will always work ;-)

You might wonder where a SKIP instruction would be useful. If you have two tests, A (eg. X=Y?) and B (eg FS? 25), how would you implement:

1. if A or B then x; y; end :

01 ^A
02 B
03 SKIP
04 GTO 00
05 x
06 y
07 LBL 00

2. if A and B then x; end

01 A
02 ^B
03 SKIP
04 x

I've always managed to find 1-byte always-false-fillers to use as skip, though ;-)
Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
12-28-2020, 01:56 PM
Post: #14
RE: NOP on HP-41C
A general emulation for NOP for all calculators that support subroutines is a call to an empty subroutine. This is a solution for the desperate! :-)

Namir
Find all posts by this user
Quote this message in a reply
12-28-2020, 02:17 PM
Post: #15
RE: NOP on HP-41C
(11-21-2020 10:58 PM)Valentin Albillo Wrote:  Something like LBL 00 is best both as a NOP and after that ISG: it only takes 1 byte, has no side effects and executes fastest.

Also, the ISG is faster than the 1, STO+ and doesn't affect the stack so it doesn't lose T.

V.

It has one small side effect: it will potentially move the goose if the LBL is "executed". Wink

But I think most people can live with that - I typically use LBL 00 myself.
Visit this user's website Find all posts by this user
Quote this message in a reply
12-28-2020, 03:37 PM (This post was last modified: 12-28-2020 05:26 PM by Valentin Albillo.)
Post: #16
RE: NOP on HP-41C
(12-28-2020 02:17 PM)Dave Britten Wrote:  
(11-21-2020 10:58 PM)Valentin Albillo Wrote:  Something like LBL 00 is best both as a NOP and after that ISG: it only takes 1 byte, has no side effects and executes fastest.

Also, the ISG is faster than the 1, STO+ and doesn't affect the stack so it doesn't lose T.

V.

It has one small side effect: it will potentially move the goose if the LBL is "executed". Wink

But I think most people can live with that - I typically use LBL 00 myself.


If speed is wanted, as in this Fastest NOP case, leaving the goose merrily fly is a bad idea as it usually entails many display refreshes which somewhat slow down program execution (most noticeable in some emulators). I always have my programs execute "WAIT...", AVIEW at the very beginning to get rid of the goose for good. Looks more "pro" too.

P.S.: It seems DM42 creators also noticed this because in DM42 you can clear a specific bit in variable RefLCD to disable the goose flight and so avoid the slowdown altogether.

Regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
12-28-2020, 05:57 PM
Post: #17
RE: NOP on HP-41C
(12-28-2020 03:37 PM)Valentin Albillo Wrote:  If speed is wanted, as in this Fastest NOP case, leaving the goose merrily fly is a bad idea as it usually entails many display refreshes which somewhat slow down program execution (most noticeable in some emulators). I always have my programs execute "WAIT...", AVIEW at the very beginning to get rid of the goose for good. Looks more "pro" too.

P.S.: It seems DM42 creators also noticed this because in DM42 you can clear a specific bit in variable RefLCD to disable the goose flight and so avoid the slowdown altogether.

Regards.
V.

Very true. I'm guessing many large application programs end up VIEWing something, thus hiding the goose. Has anybody benchmarked the effect of having the goose visible vs. having VIEW/AVIEW visible when passing a label? I could whip up a little program on my 41CX that times execution for, say, 1000 loop iterations, and run it both with and without an initial AVIEW.
Visit this user's website Find all posts by this user
Quote this message in a reply
12-28-2020, 06:51 PM
Post: #18
RE: NOP on HP-41C
(12-28-2020 05:57 PM)Dave Britten Wrote:  Very true. I'm guessing many large application programs end up VIEWing something, thus hiding the goose. Has anybody benchmarked the effect of having the goose visible vs. having VIEW/AVIEW visible when passing a label? I could whip up a little program on my 41CX that times execution for, say, 1000 loop iterations, and run it both with and without an initial AVIEW.

Each move of the goose costs 15 cycles extra compared to if a message is shown. The code is:

Code:

SLBL:         ?s5=1                 ; display got something?
                                    ; (MSGFLG?)
              rtn c                 ; yes
              gosub   ENLCD
              rabcr                 ; rotate goose
              golong  ENCP00
Find all posts by this user
Quote this message in a reply
12-28-2020, 08:15 PM
Post: #19
RE: NOP on HP-41C
(12-28-2020 06:51 PM)hth Wrote:  
(12-28-2020 05:57 PM)Dave Britten Wrote:  Very true. I'm guessing many large application programs end up VIEWing something, thus hiding the goose. Has anybody benchmarked the effect of having the goose visible vs. having VIEW/AVIEW visible when passing a label? I could whip up a little program on my 41CX that times execution for, say, 1000 loop iterations, and run it both with and without an initial AVIEW.

Each move of the goose costs 15 cycles extra compared to if a message is shown. The code is:

Code:

SLBL:         ?s5=1                 ; display got something?
                                    ; (MSGFLG?)
              rtn c                 ; yes
              gosub   ENLCD
              rabcr                 ; rotate goose
              golong  ENCP00

Interesting, what does that translate to in microseconds? (Assuming a perfectly calibrated CPU clock, of course.)
Visit this user's website Find all posts by this user
Quote this message in a reply
12-28-2020, 08:37 PM (This post was last modified: 12-28-2020 08:41 PM by Sylvain Cote.)
Post: #20
RE: NOP on HP-41C
(12-28-2020 06:51 PM)hth Wrote:  Each move of the goose costs 15 cycles extra compared to if a message is shown.

(12-28-2020 08:15 PM)Dave Britten Wrote:  Interesting, what does that translate to in microseconds? (Assuming a perfectly calibrated CPU clock, of course.)

In the old HP 41 CPU speed thread John Ioannidis says the HP-41 process 6300 machine instructions per second or 1 instruction per 158.730 microseconds.
So assuming that this is a good estimation and that all instructions take the same amount of time to execute, which I doubt, the goose move subroutine (15 cycles) would takes 2.381 milliseconds to execute.
Find all posts by this user
Quote this message in a reply
Post Reply 




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