tribby@hpindda.HP.COM (David Tribby) (07/26/88)
I spent a couple of hours yesterday evening tracking down a software bug, and figured others could learn from my mistake... I'm writing a fairly large application on my GS using TML Pascal and Assembler. An assembly language routine reports toolset errors in an alert window. One of the things it does is to copy a string passed from the caller into local memory via the MVN instruction. Everything was fine as long as the global block and code segment were in the same data bank. But last night my program must have grown over the boundary. When the MVN instruction executed, it set the Data Bank Register (B-reg) to the bank containing the subroutine. When the subroutine returned to Pascal, the B-reg pointed to the wrong area...and all sorts of strange things happened! I fixed the problem by saving the B-reg upon entering the subroutine and restoring it before returning. So 65816 hackers: what do you usually do with a MVN instruction? Surround it with PHB PLB? How do you handle moves to an address passed as a parameter (which may be in any data bank)? The only way I could figure to do it is to load the high-order byte of the address from the stack, then store it in the code byte containing the source bank number. (That trick wouldn't work too well in ROM!) --Dave Tribby - - - - - ARPA: tribby%hpda@hplabs.HP.COM UUCP: hplabs!hpda!tribby
jason@lakesys.UUCP (Jason) (07/28/88)
In article <6230014@hpindda.HP.COM>, tribby@hpindda.HP.COM (David Tribby) writes: > [...] via the MVN instruction. Everything was fine > as long as the global block and code segment were in the same data bank. > But last night my program must have grown over the boundary. When the > MVN instruction executed, it set the Data Bank Register (B-reg) to the > bank containing the subroutine. When the subroutine returned to Pascal, > the B-reg pointed to the wrong area...and all sorts of strange things > happened! I fixed the problem by saving the B-reg upon entering the > subroutine and restoring it before returning. > > --Dave Tribby Upon exit, the MVN or MVP instructions leave the DBR containing the bank specified as the target bank. I suppose it might be useful in some cases, but it sure seems like a pain to me - I use PHB & PLB as well (seems to be the only easy way... not like it takes up tons of code space). As far as doing "variable" moves, I think that the self-modifying code is the only possible trick... It seemed sort of annoying to me, but then I thought about how the parameters would be passed (Considering that the A,X, and Y regs are all used), and figured I'd just count my blessings... 7 cycles per byte ain't too bad! -- Jason - Not your average iconoclast | UUCP: uwvax!uwmcsd1!lakesys!jason