Giter Club home page Giter Club logo

Comments (3)

TomHarte avatar TomHarte commented on June 14, 2024

This definitely puzzled me, but I think I've figured it out: the stack is stomping upon the instruction mid-flight.

The cycle breakdown for JSR per 64doc is:

    1    PC     R  fetch opcode, increment PC
    2    PC     R  fetch low address byte, increment PC
    3  $0100,S  R  internal operation (predecrement S?)
    4  $0100,S  W  push PCH on stack, decrement S
    5  $0100,S  W  push PCL on stack, decrement S
    6    PC     R  copy low address byte to PCL, fetch high address
                   byte to PCH

So in this case:

PC is initially 0x17B; S is initially 0x7D so the stack pointer is currently at 0x17D.

  1. fetch opcode from 0x17b, which is 0x20;
  2. fetch low byte of target address from 0x17c, which is 0x55;
  3. read from the stack, by coincidence address 0x17d, doing absolutely nothing with the result;
  4. write the current high byte of the PC, which is value 1, to the stack at 0x17d;
  5. write the current low byte of the PC, which is 0x7d, to the stack at 0x17c;
  6. fetch high byte of target address from 0x17d, which is now 1, because it was written there back in cycle 4.

from processortests.

essial avatar essial commented on June 14, 2024

WAIT. Wow. This test is executing instructions INSIDE of the stack. I didn't even think about that!

This is both the best and worst test ever written.

You, my friend, have won the internet.

from processortests.

essial avatar essial commented on June 14, 2024

Just to follow up, I implemented that order of operation and that passed the test, thank you so much!

        var addressLow = readByte();
        pushWord(state.pc);
        var addressHigh = readByte();
        state.pc = (addressHigh << 8) | addressLow;

from processortests.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.