Stories
Slash Boxes
Comments

SoylentNews is people

posted by janrinok on Saturday March 23, @07:58AM   Printer-friendly

https://nanochess.org/emulator.html

After winning the IOCCC for the first time, I had the idea of writing an emulator of the 8080 processor in 2000 characters of C, after patterning experimentally the more than 200 instructions and doing measures of byte count, I realized that it was possible and I made it. Then I added CP/M support as a extra feature. I was completely astonished when I won Best of Show of 19th IOCCC :).

[...] This emulator was developed eighteen years ago when the computers had 32-bit processors and it used a hole in the C language syntax where you could pass a pointer on an integer. In fact, this is the IOCCC objective: make C compilers to do things these shouldn't be supposed to do.

However, the C compilers for 64-bit processors don't allow it any more as pointers are 64-bit and the int types are 32-bit, so compilers stop with an error (especially in macOS because clang).


Original Submission

This discussion was created by janrinok (52) for logged-in users only, but now has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
(1)
  • (Score: 5, Interesting) by Rosco P. Coltrane on Saturday March 23, @11:04AM (6 children)

    by Rosco P. Coltrane (4757) on Saturday March 23, @11:04AM (#1349955)

    That 2K program took me MONTHS and incredible amounts of work to shave one byte here, one byte there, abuse the C compiler while still passing lint... I was really proud when I finally saw my name on ioccc.org.

    And you may think it's pointless - well, maybe it is nowadays - but it's in my resume, and that's all the street creds I ever needed to convince propective employers that I'm a C specialist. Even better: if the interviewer knew what the IOCCC was, it was a very good indication that this was an employer worth working for.

    • (Score: 2) by SomeGuy on Saturday March 23, @11:52AM (2 children)

      by SomeGuy (5632) on Saturday March 23, @11:52AM (#1349957)

      It's great you can actually put something like that on your resume. A number of years back I tried to do some projects on my own, hoping to get something out of it I could put on my resume. But it all failed miserably. Employers around here only want someone who can kiss ass and suck dick. Anything technical just makes their eyes glaze over.

      I hate this planet.

    • (Score: 2) by Snotnose on Saturday March 23, @01:10PM (1 child)

      by Snotnose (1623) on Saturday March 23, @01:10PM (#1349965)

      That 2K program took me MONTHS and incredible amounts of work to shave one byte here, one byte there,

      Back in the day I tried to disassemble the ROM in my TRS-80. The Z80 in the TRS-80 had multibyte jump statements. The BASIC interpreter would jump to the middle of one of those multibyte instructions and interpret the "address" as, say, ADD A, B.

      Once I saw that more than once and realized it wasn't just a fluke I gained a lot of respect for the programming abilities of Mr Gates and Mr Allen.

      --
      "Now let me get this straight. The arabs get the oil, and we have to cut the ends of our what off?" ----- Moses
      • (Score: 3, Informative) by owl on Saturday March 23, @06:11PM

        by owl (15206) on Saturday March 23, @06:11PM (#1349994)

        The BASIC interpreter would jump to the middle of one of those multibyte instructions and interpret the "address" as, say, ADD A, B.

        This was not a Bill G or Paul A innovation. This was standard practice back in the days of writing things like interpreters in assembly while also meeting strict space limits (you had 4k of ROM and not a byte more).

        Any assembly programmer who did assembly for a living from the same time frame should have been more than capable of creating these sorts of tricks.

    • (Score: 2) by Tork on Saturday March 23, @04:13PM

      by Tork (3914) Subscriber Badge on Saturday March 23, @04:13PM (#1349985)
      I just wanted to let you know that I have, at best, a lay-person understanding of what you've accomplished. I'm not sure I fully understand the ramifications of your work, but I do think it's cool and wanted to say congratulations! I definitely understand putting that on your resume. Maybe submit this to the green site? (never thought I'd say that... 🤮
      --
      🏳️‍🌈 Proud Ally 🏳️‍🌈
  • (Score: 2) by hendrikboom on Saturday March 23, @01:53PM (1 child)

    by hendrikboom (1125) Subscriber Badge on Saturday March 23, @01:53PM (#1349967) Homepage Journal

    hole in the C language syntax where you could pass a pointer on an integer.

    You mean something like &4 ?

    • (Score: 3, Informative) by tekk on Saturday March 23, @03:19PM

      by tekk (5704) Subscriber Badge on Saturday March 23, @03:19PM (#1349975)

      No, you can still do that.
      It used to be that on 32 bit x86 (usually) the size of a pointer was the same as the size of an int. What this meant was that you could put a pointer into a slot of type int, be it a parameter or a structure member, a variable, etc. I wanna say that this trick was used sometimes for things like tagged pointers (imagine you have a pointer but you also have a garbage collector. You just declare that the top bit of your pointer is always 0 and mask it off while using it. Now when your garbage collector is running, you can use the top bit to mark that the pointer is in use and still valid without "wasting" any memory.)

(1)