The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
HP-15C: Fixing the CHS and Stack Lift Bug
12-12-2015, 10:44 PM (This post was last modified: 05-15-2022 08:47 AM by Thomas Klemm.)
Post: #1
HP-15C: Fixing the CHS and Stack Lift Bug
For a description of the bug see: CHS and Stack Lift

TL;DR: CHS doesn't enable the stack lift when the X-register is 0.

The line 07117 is responsible for the CHS-bug. When the mantissa of the X-register is all 0 then the program jumps to line 00250.
But then the flag 9 which disables the stack-lift is not cleared in line 07127. Thus the stack-lift keeps disabled.

Code:
07116:        1372 ? c<>0  m
07117:        1241 ?nc goto 00250
07120:        0002
07121:        0611 ?nc call 05142
07122:        0050
07123:        1314 ? s=0 13
07124:        0321 ?c  goto 31064
07125:        0313
07126:        1276 c=-c-1  s
07127:        1104 s=0 9
07130:        0360 c<>n
07131:        1663 ?nc goto 07117

But line 07117 is also used with short branches, probably to save some precious bytes. Thus we have to adjust these as well.
And then there are two short branches to line 07127 which we have to consider.

This is the patch I came up with:

Code:
07116:        1372 ? c<>0  m
07117:        0103 ?nc goto 07127
07120:        0611 ?nc call 05142
07121:        0050
07122:        1314 ? s=0 13
07123:        0321 ?c  goto 31064
07124:        0313
07125:        1276 c=-c-1  s
07126:        0360 c<>n
07127:        1104 s=0 9
07130:        1241 ?nc goto 00250
07131:        0002

Thus the long jump to line 00250 was moved down.
The commands s=0 9 and c<>n got swapped so we can only enable the stack-lift.
Unfortunately the distance from line 07027 is now too long for a short branch.
Instead of using a long jump I decided to do it in two steps:

Code:
07026:        0414 ? s=0 8
07027:        0027 ?c  goto 07031
07030:        0510 s=1 6
07031:        0773 ?nc goto 07130

So far the fix works fine. I just hope that I haven't introduced other bugs.
Keep a copy of the original ROM!

Instructions to apply the patch:
  1. unzip the attached file hp-15c-chs-bug.zip:
    unzip hp-15c-chs-bug.zip
  2. apply the patch:
    patch 15c.obj hp-15c-chs-bug.patch


Kind regards
Thomas


Attached File(s)
.zip  hp-15c-chs-bug.zip (Size: 387 bytes / Downloads: 55)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP-15C: Fixing the CHS and Stack Lift Bug - Thomas Klemm - 12-12-2015 10:44 PM



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