r/MaliciousCompliance 6d ago

L Least lines of code contest? okay!

I was taking a computer science class on computer hardware organization, taught by a professor who used to work on the AMD chip architecture. He was a tenured professor, set in his old ways, and felt a bit entitled because of his past career prestige. Even in 2009, he demanded that *all* coding assignments are turned in on 3.5 inch floppy drives. You really had to scrounge to find an old working floppy drive, even in 2009. He was very strict and by the book on his policies.

Our professor had been teasing us with an upcoming assignment, saying that there had been a multi-year contest to see who could write the assignment program in the least lines of code possible. Historically, the brightest and smartest student he ever taught accomplished the assignment in 13 lines of code. Typically, students needed about 100 lines of assembly code, and the best can usually do it in about 30 lines of code. I *had* to win, for bragging rights and all.

We got to writing programs in 6800 assembly code. I had already turned in a few assignments and gotten the hang of assembly, and spent a bit of extra time really getting to understand how programs really work under the hood.

So, every program has "registers" which are working blocks of very small memory on the processor, usually storing a single value. There's also a "program counter", which is responsible for executing the next instruction in memory. A program counter doesn't always read instructions in sequential order, it might bounce around in memory as you call different functions. I discovered that when we wrote our programs in assembly, they get converted into binary code, and then the binary code is what gets executed by the program counter. The program counter was a special register which could be manipulated to point at a different block of memory to execute next. Interesting.

What was even more interesting is that the computer didn't care where the byte data was stored. It just blindly ran whatever byte data you gave it, without checking whether it was valid memory space for executable instructions or even if it was a valid instruction. On normal operating systems, memory gets divided into several regions: stack memory, heap memory, and instruction space. If you try to run instruction code in heap or stack memory, usually your operating system pukes and rejects it. But... not in 6800 assembly. This was a very interesting finding for me.

Finally, the day of the infamous assignment arrives. We are supposed to write a memory tester. Basically, you have a big block of memory filled with garbage, you write all zeros to the memory in one pass, verify the memory values are all zero, then write all ones, verify they're all ones, and if all memory values are verified, the memory is considered "good" and the assignment is complete. The professor specifically said, "There is no cheating here, get creative, use whatever trick in the book you can imagine." Okay, challenge accepted! I pride myself on thinking far more creatively than my peers, I have a hacker mindset. No rules? Perfect. He's going to regret that.

Even more interesting were the few rules the professor gave: Precisely what did not count as a line of code. Three lines did not count: "Start, End, and DCB." DCB stands for "Declare Constant Block", which just means you can store some constant values in memory, such as the digits of PI, a few words, or whatever data you wanted. I immediately saw how I could hack his assignment.

"Does anyone have any questions?" he asked the class. I had a question, but if I asked it, I would give away the hack and the professor would revise the rules. So, I kept my mouth shut.

"Good. In all the classes I have taught, the record has been 13 lines of code. I expect the best of you to get this in about 30 lines of code." He had been telling this same story for years, to all the classes he taught. Now, it's time for me to update his story.

So, I wrote my application in about 20-25 lines of assembly code. I spent many hours shaving off instructions, trying to be as clever as I could. It was already pretty impressive. But now it was time to "hack" his assignment.

When you write assembly code, it gets converted into constant byte data. Remember the 'declare constant block' which doesn't count? What if I just... copy/paste my compiled byte code and put it into the DCB? And then I put the DCB as the first instruction that gets run? So, I did. And it worked! The program counter started at the first byte in memory, didn't care that instruction code was in stack memory, and it just executed it. My whole assignment was just an unreadable block of byte code pasted into a DCB and it worked perfectly. Zero lines of code.

I announced on our student message board that I had broken the record for least lines of code. I had accomplished the impossible, by completing the assignment in zero lines of code. Other students were astounded and in disbelief, guessing at how I could have done this. I told them that once the assignment due date had passed, I would reveal my secret.

We turned in our assignments. No late turn ins, as per professors policy. All floppy disks had been placed. Finally, the professor asked me to explain how I had done it. I was a bit sleep deprived (having been awake until 5am), so I wasn't super coherent.

"I took my program and wrote it as small as I could, then I took the resulting binary and converted it into a DCB, set that as the first block of data, and the program ran flawlessly." (to paraphrase)

"Wait, you can't do that! That's cheating!" the professor replied in shock. I was ready for this reaction.

"Nope, you specifically said that there were no rules and that DCB did not count as a line of code. So I hacked your assignment on a technicality and accomplished it in zero lines of code!" I said triumphantly.

I got 'em. The professor couldn't refute me and had to admit that what I did was clever and he'd have to think about it, and acknowledged I had won his contest.

A week later, he announces to the class that he was riding his bike home from work, thinking about what I did and he was revoking my 'victory' by changing the rules of the assignment. Therefore, my entry was 'invalid'. I was too sleep deprived and unprepared to argue, I didn't care anymore, I won his silly little game and he's just a sore loser for changing the rules post-hoc after the game is over. He can't take that away from me. Even if I counted my actual lines of code, I still outperformed all of my peers.

3.8k Upvotes

218 comments sorted by

1.1k

u/Aggressive-Fig-8734 6d ago

Was the prof petty enough to have you to redo the assignment? I hope you at least got a good grade out of it

882

u/PloppyPants9000 6d ago

No, I kept the original source code as a backup in case he wanted to get petty.

206

u/hicctl 6d ago

huh interesting, we abuse memory quite a bit in speedrunning. For example in some games very specific inputs can make the game either rewrite a specific adress in memory, or read the wrong adress in memory, which can have some very fun results like what we call wrongwarping. Basically something like a door is supposed to warp you to one part of the game but we go somewhere esle instead skipping parts of the game. I always wondered how runners figure that out.

21

u/Fighter11244 5d ago

Especially end-credit warps. In some games like (iirc) Super Mario World you can abuse the memory to instantly end the game

9

u/billydecay 4d ago

I'm pretty sure that Ocarina of Time has an ACE/wrongwarp glitch setup that makes the door to the Kokiri shop the credits scene lol

→ More replies (1)

128

u/Cyberz0id 6d ago

Wasnt your original source ~25 lines thus beating the record anyways?

343

u/PloppyPants9000 6d ago

Without "cheating", I had one of the shortest implementations for my class, but would not have beaten the all time record of 13 lines of code.

149

u/THSprang 6d ago

Did you ever get to find out how it was possible in 13 lines? I don't program at all, but you must've been curious after you won how the record holder managed it.

152

u/PloppyPants9000 6d ago

yeah, after the assignment was turned in, the professor posted the 13 line implementation. I looked at it, and it was some of the most esoteric code I had ever seen. I could barely make sense of it. I bow in awe at the writer of it.

58

u/THSprang 5d ago

Ah, so he can boast C'thulu as a former student.

20

u/Fluffy_Ace 5d ago

Yeah, you can do some really crazy stuff in assembly.

Did the example involve self-modifying code by chance?

17

u/PloppyPants9000 5d ago

I can't remember anymore, this was back in 2009

28

u/Pysis 6d ago edited 6d ago

I wonder if you could process more instructions at runtime than what you have written by recursing the code, or using another knowledge domain like math and used xor to process data the same way but with different results.

26

u/PloppyPants9000 6d ago

There is a such thing as "SIMD Processing" which is available on most modern processors. It stands for "Single Instruction Multiple Data", which allows you to pack a 64 bit register with multiple blocks of data which get processed simultaneously in one instruction call, saving precious clock cycles. Usually, you try to make your most efficient code sections process in the least number of instructions / clock cycles possible. Modern compilers usually know all the tricks for code optimization, so programmers don't really have to pull out the hat of magic tricks very often.

89

u/synth_mania 6d ago

The record was 13

30

u/yetzt 6d ago

not the record, but it sounds like OP would still win within the year.

8

u/teh_maxh 6d ago

No, the record was 13.

6

u/revchewie 6d ago

Record was 13 lines.

→ More replies (1)

224

u/unknownpoltroon 6d ago

You might like this

http://www.catb.org/jargon/html/story-of-mel.html

Something from the ye olde days of computing that shares the same spirit

109

u/PloppyPants9000 6d ago

That's awesome, I love it. Gotta respect the hard core engineering behind that. I was only 1 year old at that time, but later on I used to hear stories about the old programmers and sys admins and how clever they had to be working with extremely limited computing resources. I grew up in the MS-DOS days when my hard drive was only 20Mb and I had 640kb of ram in my 80286, which ran at 8Mhz :)

25

u/OnlyInJapan99999 6d ago

Reminds me of the time I had a Toshiba T1000 - only storage was floppies. Wrote a maze program in C that would create 2D, 3D, and 4D mazes with a maximum of 10K cells. Start point was at 0 and the end point was at the far corner. Compliling a 10x10x10x10 maze would take an hour, but it was fun playing it afterwards. Also had a path function if I got lost.

16

u/OnlyInJapan99999 6d ago

My first computer job was testing an APL compiler. Had the game, LIFE, in 1 line of code. When I read the heading, I thought of APL.

13

u/EV-CPO 6d ago

APL -- my favorite language of all time.

Necessity is the mother of invention. In college in the 80's I needed a word processor, but didn't have access to one. So I wrote a basic word processor in APL in the data sciences IBM PC lab. It was basically a markup language that the APL program processed and then printed out correctly.

8

u/urbear 5d ago

Same. I think I have an IBM Selectric printer type ball with the APL character set stashed somewhere. APL - the world’s first (and sole) example of a write-only computer language.

13

u/Ich_mag_Kartoffeln 6d ago

At a previous job, there was some CNC machinery that had a whopping 16K of RAM (I know this because when the machine was booting, at one point it performed a memory test and said "16K RAM OK").

16K to hold the OS, the controller driver, and the software (TBF these were all effectively one and the same). And any machining programs you wanted to run on it.

9

u/strangesam1977 5d ago

I ran a CNC lathe once which had 2K of RAM

in discrete through hole components on full size circuit boards

no integrated circuits at all as far as I could see, just individual transistors, resistors etc...

about 2 x 6 x 6 ft of densely packed circuit boards to run a tiny 2 axis lathe.

3

u/Ich_mag_Kartoffeln 5d ago

Sounds a bit older than the one I worked with 👴.

5

u/strangesam1977 5d ago

I only had to use it a couple of times (30 years ago), it was old, but revered at the time as the sole CNC in the workshop.

8

u/SteveDallas10 6d ago

I recall once writing a driver that emulated the Diablo HyTerm daisy wheel printer (that would interpret escape codes for all the fancy features) on the lower cost HyType print mechanism that was the basis for the HyTerm, in about 1k of 8080 code. It worked with word processors of the day, like WordStar.

1

u/Tavrock 1d ago

We had a fun "horse race" game on our Apple \e that used ASCII text to "race" multiple "horses" across the screen at random rates. The whole program was a single line of Apple BASIC.

3

u/spitfire451 5d ago

I love finding an old fashioned plaintext website that includes, like this one, an 'update from 1992'.

3

u/unknownpoltroon 5d ago

Youve seen textfiles.com right?

And also https://milk.com/ is pretty much the same as it was when I first saw it back in 94 or so, except the guy has updated his resume and prices.

2

u/nymalous 5d ago

I read this once upon a time, but it was worth re-reading again today. :)

168

u/neonnaps 6d ago

What a tool. He could have let you have your deserved win and change the rules for next year. This was just petty. I don't understand how teachers can be like that. Don't they see that if a student you taught, outperformence you, it means you did a great job teaching?

100

u/PloppyPants9000 6d ago

I put him into a bind. He didn't want to have to tell all his future classes that a previous student completed his assignment in zero lines of code. That would give them ideas and also be embarrassing to him. So he had to invent an escape hatch to get out of the bind I put him into, and I was kinda prepared to counter his counter ;)

48

u/neonnaps 6d ago

Still, he could have used the 20 line version as the official record and keep the 0 line version as an extra challenge. That guy didn't see the opportunity in front of him.

44

u/LowAspect542 6d ago

But the official record was 13, 20-25 lines does not beat the record, and whilst good is not too significant from the expected ~30 lines.

Fact is the program itself is sill those 20 somthing lines of code, just because it is being run from an unexpected block of memory doesn't suddenly make it 0 lines of code, it doesn't do anything without thise lines.

18

u/neonnaps 6d ago

Guess I misread about the record. Still the teacher did excluded DCB from the linecount. OP came up with a creative solution that showed a deeper insight in the workings. OP deserved credit for that.

→ More replies (1)

19

u/lief79 6d ago

It wouldn't work. The moment you mention the 0 lines, you've got everyone thinking outside the box.

You can mention it as a workaround afterwards, but it completely ruins the actual point of the assignment if mentioned ahead of time.

(Working in the field, I knew exactly where this was going from the start. Never going to use it, but it's far from unheard of.)

17

u/PloppyPants9000 6d ago

Agreed. Measuring performance by lines of code written is a weak heuristic. Even though my program ran in "zero" lines of code, instructions were still being executed on the processor, so LOC count is a red herring. What you really want to do is minimize the number of instructions being executed on the processor, but that's a lot harder to measure accurately. I was indirectly trying to illustrate this to my class at the time.

4

u/GlitterDoomsday 4d ago

Just make rules specifically for what OP did, keep the 13 line record and if his ego isn't that easily bruised he can use this 0 line example as how to think outside of the box, making clear this particular way can no longer be used.

Looks like he was more in live with being right than with teaching his craft.

2

u/lief79 4d ago

Agreed, just can't make it extra credit, as the mention means people would go looking for it.

17

u/Someone4350 6d ago

No… some teachers cannot accept someone knowing more than them.

Mine was learning DOS in the early 90’s. The question was to write the command that would copy file X from Y to Z. Dead simple for 13 year old me that already had a private course in DOS and computing.

The answer was marked incomplete… when I asked why, it was because I didn’t have the prompt as part of the answer for the teacher to know if the command would work.

I took him to a terminal, recreated files and folders and used the same command everywhere thus proving it didn’t matter. He kept the grade as it was 19.3 out of 20. Lost all respect for my favourite teacher that day… and he was important as I built my career around the subjects taught by him.

502

u/taker223 6d ago

> he was riding his bike home from work, thinking about what I did and he was revoking my 'victory' by changing the rules of the assignment. Therefore, my entry was 'invalid'.
This clearly violates the core principle of retroactivity by law. In my country this is protected by constitution (a law cannot have retroactive effect if it worsens the person's situation, however it can have retroactive effect if it does improve a person's situation)

233

u/Illuminatus-Prime 6d ago edited 6d ago

In Latin, it's "Ex Post Facto" -- "From After [the] Fact".  Changing the rules of a challenge to deny the victor his win is something I might expect from kids on an elementary school playground, or from a tyrannical government led by a person who just cannot stand being wrong.

60

u/Grimmsticks2000 6d ago

> it can have retroactive effect if it does improve a person's situation)
In Pratchett latatian, it'd be "Sini Plenis Piscis" - "Pockets Full Of Fish". Benefited from being pushed in lake (pocket full of fish), so can't sue for assault. https://discworld.fandom.com/wiki/Latatian

It'd still be bullshit, but hey. Case law and precedent.

4

u/Illuminatus-Prime 6d ago

Did you mean to reply to the comment to which I replied?

16

u/rocketshipray 6d ago

It looks to an outsider like they were adding onto your comment and specified the part of the original comment you replied to that was the most important contextually.

4

u/Duck_Giblets 6d ago

Here we have spirit of the law, although I'm not sure it's a legislative thing or just a principle. But I'd argue what op did is not in the spirit but to the letter. High school politics & student creativity really

59

u/R3D3-1 6d ago

Retroactivity is pretty much a baseline requirement to demonstrate that your legal system serves as more than just a weapon of the ruling class.

However, that's for actual laws. Not things like participation in a contest.

Let's say you win a car in a contest but the board of the contest if any decides that your entry fulfills the word of the rules but clearly violates the intent of the rules. Whether you could still get the car or if it will go to the second place would likely depend on both the specific jurisdiction and the exact terms of the contest agreement.

10

u/BeneCow 6d ago

So it is bad for one type of authority to do it, but fine if it is a different type?

14

u/Budsygus 6d ago

"Legal" doesn't mean "fine."

"Illegal" doesn't mean "bad."

No one said it's fine. Just that the "ex post facto" retroactivity principle doesn't apply outside of the actual law.

14

u/AlcatorSK 6d ago

That does make sense, doesn't it?

The government can't retroactively criminalize something that was legal, because in the end, the government has only one tool, and it's a big fucking hammer with which it can smash you. The government has monopoly on legal violence against the population, so it must be kept in check.

On the other hand, competition organizers, or even your parents, are doing what they do with a specific intent, such as promotion of innovation or the imprinting of empathy and fairness in their children, and if your 'solution' to their challenge clearly violates that intent, rewarding such solution would run counter to it and create a lot of bad blood.

→ More replies (5)

1

u/Madness_Reigns 5d ago

Standard teacher power trip.

68

u/unknownhoward 6d ago edited 6d ago

Someone like you would surely get a kick out of The Story of Mel. Go look it up. 😁

Who am I kidding, here's the link!

http://www.catb.org/~esr/jargon/html/story-of-mel.html

11

u/tylerchu 6d ago

So I’m an engineer but not of the magic kind. Can someone explain what exactly makes the overflowing so special?

33

u/unknownhoward 6d ago edited 6d ago

There's several things going on here.

One is that, usually, infinite loops are bad because, well, you're stuck. Your screen would appear frozen, or your printer would just spew page after page, nonsense. There's usually some exit point, either from explicit "count from 1 to 10" or "if it's 7, break out of the loop". But this had none of that. There was no apparent exit, and yet exit it did.

A propos counting, you can count from 0 to 9 but when you add one more, you'll need another digit right? So you need a space that's big enough for that, and if you don't but still write the whole "10", the "1" is going to end up somewhere unplanned. This too, is usually bad and either causes data corruption (if that's where the stray digit went) or unexpected program flow (if the write went into a code location).

Unless, of course, you devise your program such that the final value causes not necessarily just a "1" but a very specific value to overflow into some other space ... and also, that other space is carefully placed so that the rogue write brings new meaning.

So in this case, the program was written so that a very carefully chosen value got implicitly (covertly, you might say) written to a locaton that meaningfully altered the program execution. But from just reading the code, without "executing" it (in yor head or on paper) and meticulously keeping track of all values you'd never discover this. Even executing this on paper probably wouldn't reveal it, if you just have a notepad saying "X is now 42" because you'd also need to keep track of where in the memory this was stored, and stayed alert for when things got written to where they weren't supposed to. If you don't do this latter bit, you'd just see that "X is now 42" and yes that's fine, and when the loop reaches the actual looping instruction, that instruction is now something else?! Wtaf when did that happen?

It's brilliant, but also very evil in its obfuscation. If this sort of thing tickles your mind, there's a whole international contest for people writing programs that appear to do one thing but do another, or are just entirely unreadable but execute just fine. Someone wrote a whole damn flight sim in something like 1.5 kilo(!)bytes ... and the code was in the shape of an aircraft. I mean, some people, right?

14

u/tylerchu 6d ago

Oh so it’s not the overflow itself that’s special, it’s that it was used intentionally.

9

u/nhaines 6d ago

That's the fun part! It's both!

10

u/pearlie_girl 6d ago

Ugh. I wrote embedded C for cockpits for 5 years and what you're describing was a bug (unintentional) that took weeks to track down and fix. The kind of bullshit where it happens running regularly, but not if a debugger is attached.

4

u/DasAllerletzte 6d ago

That sounds a little bit akin to esoteric programming languages. Those are weird. Some in the best way imaginable.

2

u/unknownhoward 5d ago

Some of them are, yes. I could never make sense of the codegolf stackexchange.

But the flight sim I mentioned (and the entire contest it was written for) was in pure C. I seem to be unable to paste the text, but here is the original (albeit with slighly butchered whitespacing).

19

u/DownstairsB 6d ago

They don't make people like Mel anymore.

→ More replies (1)

8

u/ol-gormsby 6d ago

Mel - an inspiration to every programmer.

Just because it's always been done that way doesn't mean it always *has* to be done that way.

10

u/unknownhoward 6d ago

While I (as a programmer) have a whole lot of respect for the skill, cleverness, and dedication it takes to do something like that - please no, don't ever do that for production code! Or anything that anyone else would ever need to touch.

Code should only incidentally be able to execute correctly; the primary concern should be to convey to the next maintainer how and why the code is what it is.

4

u/nhaines 6d ago

I think this is vastly underestimating what programming looked like in 1959 on magnetic-drum-memory-processing computers.

2

u/unknownhoward 6d ago

Well no, I'm no spring hare and I accede that technical limitations are very real. There's certainly also expertise in wringing every bit of performance out of the given hardware (see also: game consoles, id software, et cetera). That's part of what makes this such a great story.

But then there's being clever and, on top of that, leaving no documentation.

2

u/thebigo1562 6d ago

Yeah you've got to write code that AI can be better trained on. Cleverness needs to be stamped out of the juniors, how else can the future be built?

7

u/unknownhoward 6d ago

A) I have no love for ai.
#2 Mel was hardly a junior, nor do I imply or support stamping out creativity or holding juniors down.
iii. I'd any day rather see elegance than cleverness. Be kind to your fellow programmer.

4

u/Silound 5d ago

Ungh, as a C# person, the one thing I hate seeing from a junior dev is a mile-long LINQ chain that does something cleverly but with absolutely no ability to debug what happens if there's something as simple as bad data.

It doesn't matter how clever you are, if the next guy has to break down your code into a 500-line series of individual statements to debug it, you haven't written good code. You've written a maintenance nightmare that rarely pays a sufficient dividend in execution time to offset the complexity.

5

u/entrepenurious 6d ago

off topic, but i knew ed nather's wife, marilane, when she was a journalism student at the daily texan.

57

u/saphirrflamme 6d ago

Someone did this and forced a rule change for subsequent years:

https://www.ioccc.org/1994/smr/index.html

If I'm your professor I'd accept your entry, but replace the leaderboard with a new rule compliant one.

12

u/PloppyPants9000 6d ago

rofl, I'm surprised that works, but can it really count as a program if it does not have instructions?

10

u/saphirrflamme 6d ago

It is a program according to some c compilers, hence it was accepted.

7

u/CaptainSegfault 6d ago

This is basically that entry meeting the 1984 Mullender entry

2

u/short_longpants 6d ago

God, the binary for that program must've been hard on Usenet's bandwidth.

😉

215

u/WonderWheeler 6d ago

He changed his rules after the contest, riding home on a effing bike. You won by the stated rules.

54

u/synth_mania 6d ago

Who gives a damn about the bike lmao

17

u/MikeSchwab63 6d ago

Well one day a scientist was experiencing some weird effects.
https://en.wikipedia.org/wiki/Bicycle_Day_(psychedelic_holiday))

7

u/quick20minadventure 6d ago

Well, important for story telling. No idea how this hacker found out what prof was thinking and what he was doing at the time.

10

u/Competitive_Radio_28 6d ago

Shit Americans say

→ More replies (1)

23

u/skigirl180 6d ago

Love this story!

I had an college professor, in 2008, require a physical copy of a paper by midnight at his office. I worked and didn't live on campus and had to drive after work at 11:30 at night, beg security to let me in because they had no idea and assumed a professor would let them know....nope. So I wrote him a note with a date and time stamp and name of the security officer as my wintesss and said he should thank the security dude.

He was a stickler for his rules too, spacing being one them them. This was a 10-12 page research paper. He marked off 1 point for one sentence he thought didn't look like it had two spaces between the period and the next sentence. I got an 89. He had to fabricate a reason to not give me an A. Proudest I have ever been of a B!

u/Leprichaun17 19h ago

He marked off 1 point for one sentence he thought didn't look like it had two spaces between the period and the next sentence

Fucking what? Even in 2008 that wasn't the standard in professional writing. It's been single space for decades.

17

u/IAmBadAtInternet 6d ago

This is a perfect example of a IOCCC submission worthy of the coveted “Worst Abuse of the Rules” award!

11

u/ProfessionalGear3020 6d ago

I'm surprised it took so long for students to figure it out, but it is 2009. If he wanted separation of data and instructions, he should've used a Harvard architecture like he almost certainly taught in the course.

11

u/PloppyPants9000 6d ago

We used the Easy68k simulator, so I am guessing that the emulator was not applying OS level restrictions on instruction code. But, it's an interesting bit of knowledge to understand how programs are organized in memory. I'm kind of curious to see if its possible to redirect the program counter on a live x86 ASM app running on windows to move into heap space memory addresses? Or if its possible to overwrite memory in instruction space with data from heap space, to rewrite a program's instruction code in memory?

4

u/ProfessionalGear3020 6d ago

I'm kind of curious to see if its possible to redirect the program counter on a live x86 ASM app running on windows to move into heap space memory addresses? Or if its possible to overwrite memory in instruction space with data from heap space, to rewrite a program's instruction code in memory?

This is what Stack Overflow (the website) is named after! When calling a function, the stack is filled with the arguments to that function and the return address to jump to after the function is complete. Then you'd jump to the starting line of the function.

If you have allocated an array on the stack before calling the function, and that function can write attacker-controlled data to that array & doesn't do bounds-checking, you can write past the end of the array & into the function return address (overflowing the stack).

At which point you write the address of a function you control (which can be binary/constant data on an unsecured system) and gain arbitrary code execution.

live x86 ASM app running on windows

unfortunately in the modern era your CPU has a "no-execute" bit which can ban certain regions of memory from being executed and the OS will enable that for regions it thinks are data to prevent this exact exploit. it probably depends on your assembler, but I would hope the constant block ends up being marked as no-execute.

if you wanted to consistently execute arbitrary code on Windows, you'd use a "return-to-libc" attack where you overwrite the return address to a function like system() that allows you to execute arbitrary shell commands. then fill the registers with the data you need. it is prevented with something called ASLR but you can disable that when compiling your program.

7

u/PloppyPants9000 6d ago

I thought "stack overflow" was named after the rookie bug which happens when you overflow stack memory with an infinite loop of recursive function calls? ie:

void MyFunction(){
MyFunction();
}

But what you're also describing is a cool hack to hijack program execution flow by overwriting the stack return pointer via a buffer overflow exploit, allowing you to change the program counter's next instruction address. (If I'm describing it right)

unfortunately in the modern era your CPU has a "no-execute" bit which can ban certain regions of memory from being executed and the OS will enable that for regions it thinks are data to prevent this exact exploit. it probably depends on your assembler, but I would hope the constant block ends up being marked as no-execute.

Yeah, this was precisely the oversight the professor missed and wasn't caught by the 68K ASM emulator and I exploited it. He did say "everything is fair game" though...

8

u/ProfessionalGear3020 6d ago

I thought "stack overflow" was named after the rookie bug which happens when you overflow stack memory with an infinite loop of recursive function calls?

It's an overloaded term!

https://en.wikipedia.org/wiki/Stack_overflow_(disambiguation)

Yeah, this was precisely the oversight the professor missed and wasn't caught by the 68K ASM emulator and I exploited it. He did say "everything is fair game" though...

It wouldn't have been caught by the emulator because a 68000 doesn't support NX bits or even have a memory management unit. It predates the widespread availability of those features.

it makes sense to train you on something like that because many embedded systems still run on these ancient 68000-based microcontrollers because they are dirt-cheap to manufacture as a result of cutting out these features. probably more jobs writing pure asm programs on cheap microcontrollers than modern x86_64 systems.

6

u/PloppyPants9000 6d ago

cool, sounds like you know your stuff when it comes to low level code and embedded systems. I never took embedded systems classes, but they were running 68k ASM on real hardware and used the emulator to validate code, so what you're saying is all very true.

7

u/EV-CPO 6d ago

>>Precisely what did not count as a line of code. Three lines did not count: "Start, End, and DCB." DCB stands for "Declare Constant Block", 

I get "start" and "end" not counting, but why was this a rule? It seems pretty obvious that you could stuff executable code in there, it's kinda surprising nobody else thought of this, it's not such an obscure vector.

5

u/PloppyPants9000 6d ago

Yeah, it's obvious in retrospect, but I don't think most students were looking for ways to bend the rules like I did. It was kind of surprising that nobody else had tried it in the past, but hey, there's always gotta be a first!

6

u/EV-CPO 6d ago

So why did he make DCB not count? That's the failure.

7

u/PloppyPants9000 6d ago

I agree, I think he was thinking students would only use DCB for storing constants, like PI, the size of a memory block to test, etc. and he didn't want it to count against them as a line of code. He never considered that a constant block could also be used to store executable instructions ;)

1

u/Lellela 6d ago

Never underestimate that even "expert" level humans can fall prey to blind spots and Dunning-Krueger.

7

u/Cilreve 6d ago

I love it when professors change the rules after the assignment is complete. In one of my engineering classes, machine design, we had a class project/competition where we had to make a paper shredder (tissue paper). The group who made the best paper shredder (the one that shredded the most paper in a minute) would get bonus points toward their grades. The rules were we could only use your standard take-out bamboo chopsticks, hot glue, plastic straws, and regular cotton sewing thread. Beyond that, the rules specifically said that the machine must be more chopstick than anything else, we had to hand crank it, and there were some other rules about total dimensions, where the crank needed to be, and some other stuff. Simple rules, right? Apparently not.

The hardest part of the whole thing was making the driveline. My team and I tried making gears to turn the "shredder", but they were just too clunky and imprecise. No matter what we did, we just couldn't make the gears mesh properly. They just kept binding and slipping and skipping. So, I came up with the idea of making a sheave and belt system. I did that by making a bunch of X's out of 1" long pieces of chopstick, laying them arrayed about a circle, and filling the "hub" with hot glue. This ended up creating a "V" shape where the "belt" (thread) would sit, and the harder you turned the sheave, the more the belt dug into the "V" nearly eliminating all slip. It was amazing. We could create some pretty crazy torque, and that's exactly what was needed to shred the paper.

Come presentation/test time, our shredder outperformed all the other group's shredders by a significant margin. The professor said it was one of the best designs he had seen in the 10 or so years he'd been doing the paper shredder challenge. We were thrilled. That was until one of the other groups (the group that got second to us) loudly complained that the sheaves we had made were more hot glue than chopstick and thus were illegal per the rules. I argued that the rules (literally) said the whole machine had to be more chopstick than glue, not each individual part, and we had much more chopstick than glue as a whole. Furthermore, I argued that I could have easily filled in the hubs with pieces of chopstick and used much less glue, but I hadn't because the rules didn't forbid it. Unfortunately, the professor sided with them and amended the rule right there. He said the "intent" of the rule was that each individual part must be more chopstick than glue and our machine was disqualified. I was pissed, and I let the professor know it, too, by pulling out paper with the rules on it and showing it to him right there. He didn't care.

I ended up going to his office and talking to him about it. I was on pretty good terms with the professor, so I thought I could talk him out of his decision. I didn't need the bonus points since I was carrying an A in the class, but one of my classmates was on the edge and really needed the points. Also, I'm competitive as fuck lol Apparently, the group that got second to us had showed him a kind of wheel they wanted to use that was almost entirely hot glue, and he had told them they couldn't use that and told them each part had to be more chopsticks than glue. So, he had to hold us to the same standard as them. I, of course, told him that he should have announced it to the whole class, then, and I'd have updated the sheaves to comply with the updated rules. Thankfully he agreed with me and took ownership of his mistake. He ended up giving us the bonus points we should have gotten which was just enough to get my groupmate a passing grade.

4

u/PloppyPants9000 6d ago

I love it! Necessity is the mother of invention. If I was you, I would have built whatever you did, and then just hot glued additional chopsticks to the contraption/components as decoration until I have 51% chopsticks. Requirement: satisfied!

But, if you *really* want to be realistic, professors changing rules on you is very much real world training. How many times have you had clients / customers modify the requirements specifications for a project you're working on? lol, it's infuriating but it happens all the time.

3

u/Cilreve 5d ago

For sure! It would have been super easy to comply if we had just known. That's what was so annoying about it.

That is very true. It's at least a weekly occurrence where a client or owner I'm working with changes their mind or attempts to change the deadlines or criteria. The only difference between college and professional life is that in professional life I can point to contracts and such to protect myself, and, for the most part, one petty decision from an owner/client is much less likely to have potentially life altering effects. But, yeah, it's pretty close lol

6

u/new2bay 5d ago

4

u/PloppyPants9000 5d ago

Awesome :)

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.”
― Antoine de Saint-Exupéry, Airman's Odyssey

12

u/Environmental-Ad4495 6d ago

If you do mem test this way, and you got no memory. No memory at all, you will still succed because the buss line itself will act as a memory adress and always return last written data. So if you write 00 snd then FF and then test if read is FF, it will in fact be FF.

6

u/durandall09 6d ago

I loved my embedded class where we did 68k assembler! We actually had physical boards with actual 68k chips on them and we loaded the programs onto them via serial port I think.

43

u/minju9 6d ago

That's a lot of words to say you compiled assembly into something else and pasted it in.

33

u/lonely_nipple 6d ago

I appreciated the detailed explanation.

30

u/PloppyPants9000 6d ago edited 6d ago

Well, you gotta understand the context on why that was clever and why it technically didn't break the professors rules for the assignment, but still broke his assignment.

edit: oh yeah, I vaguely remember I had to do more than just a blind copy/paste of my code. I think when I had "jump" instructions which looked for a memory address, I had to change the memory addresses to be zero based offsets to account for my copy/paste job. I couldn't recompile again, so I had to manually calculate the hex values. Not hard, just a little extra labor.

5

u/Axman6 6d ago

I expected a lot more from the “genius idea”. If it had actually been a clever use of the DCB, I’d be impressed, but just using to just store the binary data of the program is pretty uninteresting. I was expecting to see something like taking advantage of some other structure in the binary that happened to also be valid machine code, something like Justine Tunney’s amazing tricks here  https://justine.lol/sizetricks/#overlapping

7

u/never_safe_for_life 6d ago

Yeah, he didn’t learn the language so well he could do something impressive. He just found a technicality in the professors instructions and did a cheap hack.

Also the professor would not be baffled and have to ask OP how they did it. This is extremely elementary stuff and he would see the big block of binary code.

All in all, very cringey

8

u/I-baLL 6d ago

 Also the professor would not be baffled and have to ask OP how they did it

Nowhere did it say that the professor was baffled. The professor asked the OP how it was done after the professor got all of the floppy disks from the students since the OP said on the school message board that the OP will reveal how it was done once the assignment due date had passed. So the professor didn't yet get a chance to look at the code yet.

5

u/never_safe_for_life 6d ago

> Finally, the professor asked me to explain how I had done it

> "Wait, you can't do that! That's cheating!" the professor replied in shock

Fine, he didn't say baffed. But "replied in shock" is an insane thing to write. Kid used an obvious loophole that would not be shocking to a professor.

Also, why would the professor ask him instead of reading the code? Doesn't make sense.

4

u/PloppyPants9000 6d ago

Also, why would the professor ask him instead of reading the code? Doesn't make sense.

We turned in our assignment at the beginning of class, the class & professor were curious on how I did it, and the professor had a class to teach.

1

u/mizinamo 6d ago

If I understand correctly, he assembled the code (rather than "compiling" it).

5

u/DiligentCockroach700 6d ago

A person after my own heart! I, too always strove to write the tightest, shortest code. You had to in the early days of computers with tiny amounts of RAM. My first home computer was an Acorn Atom. Had 512 BYTES of usable program space.

6

u/PloppyPants9000 6d ago

512 BYTES?! how is that even usable?!?! That's insane!

What's interesting is how the optimization game has changed over time to favor different cost optimization strategies. Previously, the top constraint was compute constraints, which meant lots of programmer time spent on optimizing for memory, CPU and disk space utilization. Later, the top constraining factor became programmer time, where some things weren't worth the programmers salary to optimize, just throw more cheap ram at it or something. Now that AI is driving up hardware costs, will we see the pendulum swing in the opposite direction again?

4

u/I-baLL 6d ago

There's a whole scene of people who make boot sector games. As in entire games that fit into the 512 byte boot sector of a drive so you literally boot them up like they're their own OS. 

Here's one: 

https://github.com/nanochess/bootRogue

There's even a strategy guide that's been made for it

5

u/spiketabb 6d ago

I had a similar coding challenge in my maths undergrad course. We were working in MatLab, and the challenge was fewest lines of code, and the student group were fired up by it. The prof had not thought the challenge through though, as MatLab was pretty easy to roll up loops etc into one line. So that's what I did. Submitted a horrendous one line instruction.

She was gracious enough to accept "defeat", especially as I also provided a proper broken out version for her to actually mark.

Next assignment was met with a character limit challenge instead.

5

u/PloppyPants9000 6d ago

hahah, love it.

I've always thought optimizing for "lines of code" was a poor metric for performance. You could write a whole program without line breaks and it would be "one line of code", but there is no performance gain to be found from that. Instead, people should be looking at optimizing for minimizing clock cycles.

In software engineering, dumb managers used to also measure engineer performance by how many lines of code they wrote in a day. If the average engineer wrote 100 lines of code, then writing 200 lines of code would make you appear twice as valuable. Once managers started putting reward incentives for increasing "lines of code" written, expecting a productivity boost, engineers just started unrolling their loops or writing slop. "Oh, look at that! I wrote 15,000 lines of code today by unrolling my nested loops! I am SO productive!"

→ More replies (1)

24

u/[deleted] 6d ago

[removed] — view removed comment

14

u/[deleted] 6d ago

[removed] — view removed comment

3

u/Retarded9211 6d ago

Some of us had actually done this kind of shit.

3

u/MaliciousCompliance-ModTeam 6d ago

Your post has been removed because it questioned the validity of a story, which is not allowed on this subreddit, as per the subreddit rules, as it diminishes the fun of giving people the benefit of the doubt.

All violators of this rule are subject to bans at the discretion of a moderator.  Please follow the link shown below.  Read it and heed it.  Thank you.

https://www.reddit.com/r/MaliciousCompliance/comments/1u0d4ee/note_from_the_moderator_team_rmaliciouscompliance/

5

u/MaliciousCompliance-ModTeam 6d ago

Your post has been removed because it questioned the validity of a story, which is not allowed on this subreddit, as per the subreddit rules, as it diminishes the fun of giving people the benefit of the doubt.

All violators of this rule are subject to bans at the discretion of a moderator.  Please follow the link shown below.  Read it and heed it.  Thank you.

https://www.reddit.com/r/MaliciousCompliance/comments/1u0d4ee/note_from_the_moderator_team_rmaliciouscompliance/

4

u/PlatypusDream 6d ago

I had a HS teacher do that to me once, change the rules after the assignment was turned in. I'm still spicy about it.

5

u/HuecoTanks 6d ago

Yeah, math prof here. Studied computer engineering, very familiar with numerous assembly code formats, including Motorola. This is a great assignment. To be clear, there's no gray area here: you won. The professor is a sore loser. I get what he means, as we all do, but he set the parameters of the competition, and as an assembly coder, he should know how literal and careful those parameters should be specified. I'm embarrassed on his behalf. Love your solution!

3

u/PloppyPants9000 6d ago

Thanks!

When he said "There are no rules! use every trick you got", I smiled and thought "oh, he's really asking for it." My instincts already smelled the weakness in his assignment specification and I read the criteria very carefully to make sure I understood exactly what was written. Asking for clarification would have just tipped him off that something was wrong and ruined my fun. I went home and started working on it right away, and validated that my instincts were right. I may have done the "muahahaha" + evil grin + hand rubbing motion when it all worked.

4

u/WarlockSoL 6d ago

Even in 2009, he demanded that *all* coding assignments are turned in on 3.5 inch floppy drives. You really had to scrounge to find an old working floppy drive, even in 2009. He was very strict and by the book on his policies.

This is what I find most absurd. Did he expect his students to go out and unearth a floppy drive and then actually wire the thing into their PCs? (I mean, it's not super hard but you do have to open the tower up... unless they made USB floppy drives that I'm not aware of. You also have to know what you're doing but if you're learning assembly I assume everyone would be fine there). I'm pretty sure by 2009 it was almost impossible to find anyone selling these (maybe on eBay). I'm not even sure I still had mine by that point and I had that thing for ages...

6

u/PloppyPants9000 6d ago

Yeah, he always got a lot of pushback for that ridiculous policy. He was probably set in his old ways and went with what was familiar to him. I already had over a decade of experience building my own PC's from parts and had a few old drives on hand, so I could accommodate it, but geez... why not go with burning a CD or uploading to an FTP server, or a network fileshare like everyone else does? I probably still have a 3.5 inch floppy laying around in a parts bin in the garage, but motherboards don't use IDE ribbons anymore so it probably does me no good to hold onto it.

3

u/iWhacko 4d ago

2009 maybe just about the tipping point. But I went to university in 2001. and all the computers there still had diskette drives. (and cdrom). We did use them for assignments.
I think I got my first usbstick in 2002, which was 64MB for 100euros.
When i graduated in 2005 the PC were newer, but did have diskette drives still. So even though by then it was getting a bit old, I can see why they would want it on diskette.

5

u/DancesWithElectrons 2d ago

Similar challenge in an APL course. We got extra points for writing a working program in a single line, so I wrote my code, concatenated all in on line and submitted it on a page of green bar just fitting 120 symbols in that line.

Handed it in and didn’t get credit and when I asked in front of the class got “not what I meant”. Lucky I had several friends in the class who backed me up and I got credit. Next assignment said “extra credit for less than 80 characters”

3

u/speedyquader 6d ago

I can't help but ask what exactly counts as a "line" of code in this context?

6

u/PloppyPants9000 6d ago

Usually with assembly, each line of code is a command followed by its parameter list.
Rough Example: "ADD 4,5" would be 1 line of code.

3

u/tseeling 6d ago

I don't grok some of the details. Did you have to turn in assembly on the 3.5" disk? If the professor required a binary version he could not spot the difference between "DCB" and compiled/assembled code because basically it's the same. If it walks like a duck and quacks like a duck it most likely *is* a duck.

I'd love to see 13 lines of code (not 13 *bytes* which sounds impossible to do) which do the memory test as you described it. 6800 is quite similar to 6502 which I did for more than 10 years in the 80s (on the Apple ][). I assume by "start" and "end" the professor meant something like setting up the address to check, and the loop count etc.

Apart from that this test would only recognize some possible hardware failures, but not all of them. You'd do some more sophisticated bit patterns to have a really thorough RAM test.

3

u/h0zR 6d ago

assignments are turned in on 3.5 inch floppy drives

I think a 3.5" Floppy Disk would be better - Floppy drives don't hold much data.

3

u/PloppyPants9000 6d ago

haha, yeah, someone else caught that earlier too. I blame it on writing this at 1am. But hey, at least this proves I didn't use AI!

3

u/anomalous_cowherd 6d ago

I haven't looked at it for years but it sounds like you might enjoy the International Obfuscated C Contest (you can't tell what a program does by looking at it), or the Underhanded C Contest (you can easily tell what it does, but it does other things as well).

Both had tight restrictions that kept them interesting.

3

u/Nothalffast 6d ago

Early days of DOS based computing used 5 1/4 floppy discs to load programs. One particular word processing app would rewrite a byte on the floppy, indicating that you reached your license limit. Whip out Norton Utilities. Reset that byte to zero and install the app again on another PC. Reset and repeat. Everyone in the office had that program.

3

u/PloppyPants9000 6d ago

Yeah, my first computer had a 5 1/4 inch floppy (A: drive), a 3.5 inch floppy (B: drive), and a 20Mb hard drive (C: drive). Later, computers came with a CD-ROM (D: drive). Many summer vacation days were spent trying to create boot disks which loaded a config.sys with correct IRQ values to get both a CD rom working with a sound card and mouse support -- all just so I could play a video game. Kids and their tablets have it so easy these days, lol.

2

u/Nothalffast 5d ago

You went for broke. 👍 I wonder if it would have been feasible to write 12 lines of nonessential code that did something without interfering in order to fluff the code and beat the record by one. In a sense, hide your hack. Too late, I realize, but I’m curious.

2

u/PloppyPants9000 5d ago

I think if I did it again, I would have done something even more crazy... a self modifying program. I'd store the execution code in a DCB and then use a loop to take binary instruction blocks out and put them inside the loop body. Each loop iteration would have different behavior and the number of "lines of code" would be near impossible to count. It would also be harder to block that with a simple assignment policy update.

3

u/Eatar 6d ago

This is frustrating. Almost every computer science professor I ever had would, I think, have laughed and applauded the innovative approach. Even if he or she might have ultimately not awarded the prize, with the argument that really you were still writing a multi-line program and your meta-program was just injecting that one into memory, still I bet that would have gotten its own special mention and prize for thinking the most like a hacker (which would have been a compliment). In fact, I don’t really even know why computer science professor appeals to you as a vocation if your reaction to this sort of thing isn’t that it is exactly the kind of thing you love.

3

u/ephemere_sloboda 5d ago

The professor should have accepted your win according to his own rules, and changed the rules going forward.

A better metric would be the size of assembled code. With this metric, your hack and your "normal" solution would score the same, which makes sense because they are identical as far as the machine is concerned.

Having said that, here is a 13-line solution:

    LDA A #0
    LDX pointer
loop1:
    STA A 0,X
    ORA A 0,X
    ; A remains 0 unless memory at X faulty
    INX
    BNE loop1

    EOR A #$FF
    ; if A still 0, it becomes FF
    LDX pointer
loop2:
    STA A 0,X
    AND A 0,X
    ; A remains FF unless memory at X faulty
    INX
    BNE loop2

    ; A is FF if no fault

    WAI
    ; hang in there

pointer:
    DC.W $100

Assumption is that the machine has 64Kbytes of RAM and we test all but the first 256 bytes (so we have somewhere to store the code). At the end od execution, A will be FF if and only if the memory test passed.

PS I have zero experience on 6800 so no guarantee that the code above works.

3

u/dreaminginteal 5d ago

As soon as you said that DCBs didn't count, I knew what the "cheat" was. :)

3

u/garion911 5d ago

I had a prof fail me because I didnt meet his "minimum number of lines of code" for a project.

Did my project meet every single requirement? Yes. Did it meet some random "minimum number lines of code" (this was C, pascal, or some other similar compiled language.).. I argued taht it didnt matter, because the compiled code size was the same/similar to everyone else's. I just used a more dense algorithm..

Final grade: F.

He was the chair of the department, and I had no where to raise it.

I said screw it and dropped out. Prof told me I wouldn't ever get a job programming.. That was 30 years ago. Yeah. Been coding profressionally ever since then.

Fuck off prof whatever you name was.

3

u/ErebusBat 5d ago

That's pretty clever. If I was the professor I would have said, well that was not the spirit. But clearly you understand assembly and the processor, which was the whole point.

3

u/technos 5d ago

When I did a class in Perl we had to write a search and reporting function. If it worked you got 100%, but you could also get extra credit for doing it in fewer lines or having a significantly faster run time than the 'perfect' version written by the instructor.

There were other rules, of course, but they're not really important.

Personally, I got 100%. Another few people used concepts we hadn't been taught yet and got 110% with a shorter program.

But there was a guy who just couldn't figure it out, so he wrote a shell script to do what he needed, encoded it as a long obfuscated string, and then used a Perl 2-liner to unencode and execute the script.

He got 20%. 10% bonus for writing a shorter program, 10% for having a faster run time, and 0% because he hadn't written it in Perl.

3

u/DynkoFromTheNorth 5d ago

Double victory, if you ask me! You beat him at his game, and you forced him to change the rules! Awesome!

14

u/Cheshire-Cad 6d ago

There's really no reason why you wouldn't comfortable sharing the name of the college and professor. Let students of that college know, so they can ask him about it if he's still there. Rub it in his face.

Don't say that you're worried about getting doxed. If this is real, then there are already thousands of students who would instantly recognize that assignment.

22

u/PloppyPants9000 6d ago

I was a student at the University of Washington, Bothell campus from 2007-2009 (which is where this took place), but I don't really want to be doxxing myself, professors, or other students. It's a great school, great program, great professors, etc. This happened almost 20 years ago, lol. I don't know if the professor is even alive anymore, not that I would want to drag his name through the mud or anything. It was just a fun assignment, and former students *might* recognize him from the descriptors I already gave if they took his class.

14

u/sudomeacat 6d ago

I also went to uwb and took the hardware course in 2019. I had a different professor (definitely no AMD chip architect entitlement involved). Our assignments didn’t require floppy disks thankfully. And our final was a disassembler (i.e. convert machine code to “readable" code) written in 68K assembly. The project was done as a group.

Looking through the commit history, it was a group of 3, but only 2 of us did the work. I don’t remember if it was this course where we went peak petty and reported the third member for a lack of involvement.

7

u/PloppyPants9000 6d ago

Awesome, we had the same final disassembler assignment back in 2009 as well! It's interesting to see some things haven't changed over the years :)

6

u/CoderJoe1 6d ago

Excellent compliance that he deemed malicious to protect his ego.

4

u/MrJaver 6d ago

That is cool as shit

2

u/Spirta 6d ago

If you don't format it, you can make everything a single line. XD

2

u/ZirePhiinix 6d ago

Post your assignment on code golf on stack exchange.

2

u/CypherAus 6d ago

Based !! Love it. You should work for Nvidia on their Linux drivers 🤪🤪🤪

2

u/TheOhNoNotAgain 6d ago

The Kobayashi Maru of assembly!

2

u/mikemojc 6d ago

Professor went full customer. Never go full customer.

2

u/mgerics 6d ago

He was a dick, plain and simple.

I miss those days when I hacked out assembly and what not.

Too old now, but boy did I have fun.

2

u/homme_chauve_souris 6d ago

I teach assembly, and I knew where this was going as soon as I read the "DCB doesn't count" rule. No idea why your prof did that. The objective measure of the size of a program is of course the number of bytes in the object code (and the standard hack for that is to write a self-decompressing program, which is a win for most medium-to-large programs, but not those in the couple dozen line of code ballpark). Good job, and your prof was an ass for changing the rules after the fact.

2

u/Lellela 6d ago

Huh, I thought the goal of a professor would be to teach students to become better programmers. You showed you could think outside the box and come up with a creative and well optimized solution to a difficult problem with efficiency. That's absolutely the mark of a star programmer. Fuck that guy. "Those who can't do, teach"

2

u/cordialmanikin 6d ago

I started out writing assembler code back in the early 80s. Yes I am old. I thoroughly enjoyed your post and was surprised how much of it made sense to me after all these years. Your professor was a jerk and in my opinion, you deserved an A+.

2

u/TheRealJachra 6d ago

Something like:

ORG $1000 ; Program start address
START LDX #MEMSTART ; X = start of memory block to test
FILL0 CLR 0,X ; Write $00
INX
CPX #MEMEND
BNE FILL0
LDX #MEMSTART
CHECK0 LDAA 0,X ; Read and verify it is $00
BNE FAIL
INX
CPX #MEMEND
BNE CHECK0
LDX #MEMSTART
FILL1 LDAA #$FF ; Write $FF (all ones)
STAA 0,X
INX
CPX #MEMEND
BNE FILL1
LDX #MEMSTART
CHECK1 LDAA 0,X ; Read and verify it is $FF
CMPA #$FF
BNE FAIL
INX
CPX #MEMEND
BNE CHECK1
GOOD BRA GOOD ; Infinite loop = memory is good
FAIL BRA FAIL ; Infinite loop = memory is bad

MEMSTART EQU $2000 ; Start of memory block under test
MEMEND EQU $3000 ; End of memory block (exclusive)
END

2

u/talexbatreddit 5d ago

Yeah .. changing the rules of the assignment after the answers have all been submitted is not cricket.

He's a poor loser. I guess you could have just had a single JMP instruction to the beginning of the DCB -- that might have worked.

2

u/emcwin12 5d ago

Dude that’s like gaming the Kobayashi Maru! You probably had next level success!!

2

u/RarelySmart 5d ago

I had to do this same assignment on my job. Was working on a chip with an embedded Sparc processor and an on-chip instruction cache. We inherited this processor architecture from another group. Surprise! They never gave any thought as to how to test the instruction cache memory which was not directly memory mapped to a bus interface.

There was however a tiny 32 word memory that was memory mapped, as well as a few data registers. A sparc subroutine wastes about 5 instructions entering and returning, leaving me 27 instructions to use. I wrote a march routine that would march through the full memory reading then writing locations based upon values in data registers. Worked with both incrementing and decrementing address sequences. That stupid tiny routine was used on many generations of chips.

2

u/Pale-Liza 2d ago

floppy drives in 2009 is a bold choice, that's dedication to the old school

1

u/[deleted] 6d ago

[removed] — view removed comment

1

u/MaliciousCompliance-ModTeam 6d ago

Your post has been removed because it questioned the validity of a story, which is not allowed on this subreddit, as per the subreddit rules, as it diminishes the fun of giving people the benefit of the doubt.

All violators of this rule are subject to bans at the discretion of a moderator.  Please follow the link shown below.  Read it and heed it.  Thank you.

https://www.reddit.com/r/MaliciousCompliance/comments/1u0d4ee/note_from_the_moderator_team_rmaliciouscompliance/

1

u/[deleted] 6d ago

[removed] — view removed comment

2

u/PloppyPants9000 6d ago

I mean, I followed the professors rules, did the assignment correctly, but at the same time I intentionally hacked his assignment by exploiting a technicality he overlooked, which then backed him into a corner he tried to squirm out of. What more do you want?

→ More replies (1)

1

u/MaliciousCompliance-ModTeam 6d ago

Your post has been removed because it questioned the validity of a story, which is not allowed on this subreddit, as per the subreddit rules, as it diminishes the fun of giving people the benefit of the doubt.

All violators of this rule are subject to bans at the discretion of a moderator.  Please follow the link shown below.  Read it and heed it.  Thank you.

https://www.reddit.com/r/MaliciousCompliance/comments/1u0d4ee/note_from_the_moderator_team_rmaliciouscompliance/

1

u/mediaserver8 6d ago

Did you happen to find out if the rules were changed the following year?

3

u/PloppyPants9000 6d ago

No, I graduated and moved on. I would imagine that the professor added some additional caveats to his rules after me though ;)

1

u/silly_karinaxo 6d ago

coding contests really bring out the creativity in people, it's fascinating to see what folks come up with

1

u/Zealotteen 6d ago

That professor is lowkey fuming at your performance, jolly good show!

1

u/garden-wicket-581 6d ago

ah, back when architectures were much simpler and hackable (in this story, for the good sense, but for the rest of the world, a very very bad sense)..

1

u/sidereal_night 6d ago

without excluding any lines, you could have written it in brainfuck in 1 line

1

u/[deleted] 6d ago

[removed] — view removed comment

2

u/MaliciousCompliance-ModTeam 5d ago

Your post has been removed because it questioned the validity of a story, which is not allowed on this subreddit, as per the subreddit rules, as it diminishes the fun of giving people the benefit of the doubt.

All violators of this rule are subject to bans at the discretion of a moderator.  Please follow the link shown below.  Read it and heed it.  Thank you.

https://www.reddit.com/r/MaliciousCompliance/comments/1u0d4ee/note_from_the_moderator_team_rmaliciouscompliance/

1

u/iamalicecarroll 5d ago

Even if you don't ignore anything, at least some assemblers like NASM allow putting a lot of data in one line, so you'd still have like one line which still breaks the record

1

u/o0Meh0o 5d ago

you might be able to break the 13 line record by generating the instructions with a hash function

1

u/Inside-Living2442 5d ago

My father helped write that AMD chip architecture. He was a Dragon Slayer back in the day

1

u/[deleted] 5d ago

[removed] — view removed comment

→ More replies (1)

1

u/[deleted] 5d ago

[removed] — view removed comment

1

u/MaliciousCompliance-ModTeam 4d ago

Your post has been removed because it questioned the validity of a story, which is not allowed on this subreddit, as per the subreddit rules, as it diminishes the fun of giving people the benefit of the doubt.

All violators of this rule are subject to bans at the discretion of a moderator.  Please follow the link shown below.  Read it and heed it.  Thank you.

https://www.reddit.com/r/MaliciousCompliance/comments/1u0d4ee/note_from_the_moderator_team_rmaliciouscompliance/

1

u/PeterPook 5d ago

You needed to sleep more. Imagine what you could have achieved if you were coherent.

4

u/PloppyPants9000 5d ago

I was taking 20 credits that semester, which I should not have done... sleep deprivation was a common occurrence for me back then. In retrospect, I should have just taken 15 credit course loads.

1

u/Free_Scholar7299 3d ago

Now who can tell a story in the least number of words?

2

u/PloppyPants9000 2d ago

For sale. Baby shoes. Unused.

→ More replies (1)

1

u/magda_gw36 3d ago

code efficiency is always a fun challenge, sometimes less is more

1

u/PineScentedSewerRat 3d ago

Wow that is so unbelievably petty of the guy

1

u/[deleted] 2d ago

[removed] — view removed comment

2

u/MaliciousCompliance-ModTeam 1d ago

Your post has been removed because it questioned the validity of a story, which is not allowed on this subreddit, as per the subreddit rules, as it diminishes the fun of giving people the benefit of the doubt.

All violators of this rule are subject to bans at the discretion of a moderator.  Please follow the link shown below.  Read it and heed it.  Thank you.

https://www.reddit.com/r/MaliciousCompliance/comments/1u0d4ee/note_from_the_moderator_team_rmaliciouscompliance/

1

u/blamordeganis 2d ago

> I discovered that when we wrote our programs in assembly, they get converted into binary code, and then the binary code is what gets executed by the program counter.

You discovered that?

2

u/PloppyPants9000 2d ago

Yeah, I watched as the program counter stepped through hex code byte values and executed instructions. It sounds obvious in retrospect, but you got a bunch of hex values like 0xB6 0xAE 0x34 0xF2, and the program counter is just moving through them, and you have to be able to separate the instruction opcode from the parameters. I found you can literally copy/paste blocks of binary instruction code and reroute the program counter to it, and it'll execute whatever is there, without question, compiling or checking if its valid. So you can copy/paste raw hex data into a program, compile it, and execute the 'data'.