Cómo funciona el desbordamiento 6502

El 6502 era un microprocesador omnipresente en la década de 1980, que operaba dispositivos como Apple II y Nintendo Entertainment System. [Ken] Eché un vistazo profundo a una pequeña parte del procesador: el circuito redundante.

Para realizar cálculos con signo, la unidad lógica aritmética (ALU) de un microprocesador debe poder calcular cuándo se produce un desbordamiento. Esto sucede cuando se suman dos números que no caben en un byte. El resultado del cálculo será incorrecto, por lo que el procesador debe informar al programa que se ha producido un desbordamiento. Esto se hace estableciendo una bandera redundante.

[Ken] usa este ejemplo para explicar primero cómo funciona el circuito redundante en lógica. Luego mira las puertas y la implementación del transistor de la lógica. Finalmente, nos guía a través del circuito en el dado 6502 real, mostrando cómo el circuito está construido de silicio.

Este es un gran ejemplo para aprender un poco más sobre cómo funcionan las ALU y cómo se construyen los circuitos integrados.

  • Contar bits, recoger liendres dice:

    Esto me trae grandes recuerdos.

    Cuando era adolescente a principios de los 80, aprendí a programar en BASIC en ti99. Y luego lenguaje de máquina en APPLE][. And then assembly language on that Apple. Wow – Macros! Labels! Self-modifying code!

    And then I acquired a copy of the Aztec C compiler for the Apple ][. That was an awesome dev environment, complete with a shell that supported redirction much like the Bourne shell, and source for some of the standard UNIX utilities.

    (side note, all of that independent study hurt my grades, where it should have been some kind of AP credit)

    And then, in University, they wanted me to pay to learn Pascal. WTF?

    And now, Java garbage. It’s pretty much been going downhill since those Aztec C days 😉

    • joecomputer says:

      Just like the Simpsons meme with Grandpa walking into the brothel, hanging up his hat and then circling right out, I left my first computer science course in freshman year because the prof said, ok open your pascal books to….I also first cut my teeth on a TI99 4/a and then went to assembler, but on the 6809 chip. I have my masters and 17 years as an engineer now. I plan on teaching my son assembler using the 6502 though.

      • cantido says:

        > And now, Java garbage. It’s pretty much been going downhill
        > since those Aztec C days 😉

        *yawn* If you can’t adapt and use stuff that isn’t your prefered choice that’s your problem. Things have come a long way since these 8 bit micros were king.

        > I left my first computer science course in freshman year because the prof said, ok open your pascal books to…

        But the skills you could have learned via Pascal would have been applicable to most programming languages. If you know everything already why even turn up to the class?

        • Alex says:

          Come on man, you even quoted the wink part. It was tongue-in-cheek.

    • Mike van Lammeren says:

      OMG! For 25 years I thought I was the only one!

      I learned Basic on ZX-81 in 1982, when I was in grade 7, primarily from the manual that Sir Clive Sinclair wrote, help from my Dad, and source code from Compute magazine. Later, I learned Z-80 Assembly, then learned more languages on various Atari computers. Then, in 1989 I walked out of my first-year computer science course because it was taught using Pascal!

      Of course, I had made a huge mistake, and wound up doing a second degree, this time in Computer Science, and I have been a software developer since 2000. Walking out of that course because of Pascal cost me many years and $$.

  • Entropia says:

    ALU stands for Arithmetic Logic Unit, not Algorithmic.

    • Eric Evenchick says:

      Opps, corrected. Thanks!

  • Ryan7777 says:

    “This is a great example to learn a bit more about how ALUs work and how integrated circuits get built.”

    in 1975….

    Still relevent?

    The logic, sure. But thats about it!

    • SavannahLion says:

      I’m not sure where you’re coming from on this. Wasn’t there a post just recently that describes how big fabricators are using old techniques of yore for various reasons?

      Understanding some of the basics of how underlying foundations work does translate to writing better code in higher languages.

    • Don’t chu java me says:

      Yeah sure, sure. Just code it in java and the compiler will take care of the details. And if it doesn’t run fast, just throw your hands up and blame the jit compiler or the jvm.

      • cantido says:

        >blame the jit compiler or the jvm.

        Or don’t be a baby and learn to use the profiling tools that are available?
        You can write slow code in any language that’s why development environments have profilers etc.

  • FrankenPC says:

    Mother of gawd…the Xeon has 55,200 times as many transistors as the 6502.

  • Brendan Robert says:

    This is a great analysis! I’m glad he takes on the Overflow flag, as its behavior can be confusing sometimes — especially for emulator authors trying to get their 6502 cores to act correctly. 😉

  • Ren says:

    So, did [Ken] tiene una descripción y ubicación de las diversas puertas en el chip, o se dio cuenta de esto con solo mirar la obra de arte?

    • ken shirriff dice:

      Ren, gracias por tu pregunta. Tengo algunos esquemas de chips 6502 que estudié en detalle y descubrí el circuito redundante en el nivel de puerta de ellos. El proyecto visual6502 tiene todas las ubicaciones y etiquetas de transistores en bruto en muchos de los transistores, por lo que pude reducir rápidamente el lado derecho del chip. Encontrar la ubicación de cada transistor en cuestión y asignarlo a la puerta fue simple pero un poco tedioso. Originalmente planeé explicar toda la ALU, pero solo este circuito tomó mucho tiempo. Tal vez en un próximo artículo.

  • NES dice:

    En realidad, mi CPU no es la 6502, sino un microprocesador basado en 6502 llamado “RP2A03”.

Matías Jiménez
Matías Jiménez

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *