4
$\begingroup$

Next semester I will be TAing a computer organization/assembly language course. I will be full-fledgedly (co-)teaching the lab. The first lab will take place before the first lecture, so me and the other TA will partly be responsible for preparing the students to not resent this class they're forced to take. At this point, the students have taken an intro class with Python and a class on OO concepts in Java, and they might be taking a language-agnostic algorithms class at the same time. The professor's standard way of motivating the concept on the first day is showing how going through an array column by column is slower than row by row even though they give the same result using the same approach.

Therefore, I have to motivate on two fronts: why is assembly programming (or even C) interesting/relevant, and why is computer organization interesting/relevant. The latter may seem obvious if you're already in the know, but it sure didn't for me before I took this very course.

Here are some of the points that I already intend to include in my opening spiel (everything that starts with a backslash is spurious):

"If you go into data science: the information in this course will explain why certain programs are slow, which is important if you're churning a lot of data.
\You will learn how to write faster programs in general.
You will understand how computers actually work, no magic [I don't have to mention that they won't learn everything].
\This class might make you interested in systems-level programming, even considering a career.
Do you ever feel awed at those other guys with their cool Arduino or Raspberry Pi projects? This class will teach you how to do what they do."

What are some other motivators that I can include?

EDIT: Just to be clear: I have no control over the lab, and definitely none over the lecture. I won't even be present for the professor's lecture. What I have control over is what I explain as I explain the pre-baked labs, which in the first three weeks include an introduction to ssh, C, certain binary algorithms, and pointers. Aside from the ssh, these are supposed to segue everyone into asm.

$\endgroup$
  • 2
    $\begingroup$ "Going through an array column by column is slower than row by row even though they give the same result using the same approach." Seems like that's a result of how you represent the array, rather than an inherent property of arrays. $\endgroup$ – Acccumulation Nov 8 '19 at 5:37
  • $\begingroup$ ...ooh, maybe I misunderstood the professor. Isn’t incrementing the pointer by the size of the objects in the array less expensive than multiplying by the length of the array? Wouldn’t going column by column require n*n multiplications rather than n multiplications, making it slower for increasingly large values? $\endgroup$ – JohnnyApplesauce Nov 8 '19 at 12:33
  • $\begingroup$ Presumably, you are discussing an array in which each element is itself an array, and this array represents a two-dimension array. And you're saying that when you iterate, it's faster to match your iteration nesting to the array nesting (outer iteration loop iterates over outer array). So far so good. But then your position seems to be resting on the unstated assumption that the inner arrays represent rows. $\endgroup$ – Acccumulation Nov 10 '19 at 22:27
  • 3
    $\begingroup$ My point is that your wording makes it sound like there is some difference between "rows" and "columns", but it is more accurate to word it in terms of inner and outer arrays. That going by rows is faster is an aspect of the representation, not anything intrinsic to "rows". As far as the actual data is concerned, there are no rows or columns. That's just an abstraction we place on top of it. $\endgroup$ – Acccumulation Nov 10 '19 at 22:27
  • $\begingroup$ @JohnnyApplesauce, many processors (CISCy ones, at least) have special addressing modes that multiply a displacement by an assortment of small (basic data sizes, mostly) constants, so "address the next data item" if it is up to 8 bytes long is free. Also, accessing the item next in memory is faster than grabbing one far away (today's machines rely heavily on cache, typical RAM access time is hundreds (!) of instructions worth). $\endgroup$ – vonbrand Apr 22 at 12:00
7
$\begingroup$

First, just a disambiguation: are you teaching Assembly language or C? Cos, they are not same as your question seems to suggest. C is a high-level procedural clean code language with tremendous abilities to speak to the bare metal similar to but not as Assembler pls. It may help you bridge to assembly but it is not assembly. Let that be clear to your students.

Never taught machine programming/ASM. But your question touches something in me: the need to wow! the student; I have same predilection with students. So I felt obliged & did some talking with friends in the know and some research.

Here’s the widow’s mite I pieced together. Hope it helps: You can add the following to your first lab “sales pitch’:

  1. Let the first lab be a NO CODE, no Technical stuff class. Just getting familiar with selves and ASM in a general way with nothing too technical and thus “intimidating” or “off-putting”. The class should be (pardon my cliché): sugar and spice and all things nice. Toward this:

  2. Add to your spiel, a history of Assembly telling them of Kathleen Booth & others etc. Make it interesting. Search & find some spectacular successes and exploits using ASM and also some disasters of sloppy ASM. Apart from sparking interest and discussion, the last part will have the additional pedagogic value of sensitising the students to their power as oracles speaking to the small dumb “god” in the machine. Also it will put them on notice of the enormous responsibilities their heightened power as bare metal oracles imposes on them to avoid sloppy code (not only for ASM but programming generally).

  3. Let the students see how the higher level languages with their swagger and leaky algorithms are actually, mostly dependent on ASM and C. Let them see that a lot of our higher level constructs e.g. macro were borrowed from Assembler.

  4. As @Buffy I. rightly pointed out, talk alone can’t win a non-committal or skeptical mind. To give them something interesting: show them some good things (e.g. games) made in Assembler and display for them on slide (s) the assembly code snippets that made such things. In this regard I found some of these online and hope they may help or stimulate some interesting ideas: https://spectrum.ieee.org/geek-life/reviews/three-computer-games-that-make-assembly-language-fun.amp.html

https://www.quora.com/What-are-some-cool-assembly-language-projects-I-can-do?top_ans=21546329

https://brianslam.wordpress.com/2014/04/06/assembly-is-fun-sort-of/

https://news.ycombinator.com/item?id=16710543

This one is a Compendium of Assembly Coding Practices from Coding Project. It may help illuminate your teaching: https://www.codeproject.com/Articles/1116188/40-Basic-Practices-in-Assembly-Language-Programmin

| improve this answer | |
$\endgroup$
4
$\begingroup$

You may not win if you just use words. Instead, give them interesting but challenging exercises to do.

One of the most fun exercises I ever did was to produce a Quine in assembly language. But, instead of producing a textual version of itself, as most Quines do, it produces a running copy in memory and then executes (branches to) that copy. The copy seems to act as if the program is moving through memory. As such, the program is called an Animal. This was once a standard exercise at Dartmouth, and I learned it from faculty and students there.

A more elaborate version will erase the old copy as it creates the new.

The book XINU (XINU Is Not Unix) by Douglas Comer has some interesting things. One of which is a microkernel for an OS.

Unfortunately, this is also one of the skills needed by machine level hackers.

To run such a program you need to assure that the OS won't get in your way, however, so you might need to do this on a simulator.

You can also do interesting things with race conditions and such that are harder to teach in higher level languages.

| improve this answer | |
$\endgroup$
  • $\begingroup$ I appreciate your enthusiasm, but the students won’t even be able to do that by the end of the class, let alone the beginning. I’m pretty sure no one but the well self-studied (whom I don’t need to reach) can even write a Python or Java quine. $\endgroup$ – JohnnyApplesauce Nov 6 '19 at 19:34
  • $\begingroup$ Actually a machine language Quine is a lot easier than one in Java. You don't have to carry as much of the structure of a program to get it done. Try it yourself. $\endgroup$ – Buffy Nov 6 '19 at 19:35
2
$\begingroup$

Forth is very interesting language which can run on bare metal, and also be as high level as you want (I've see a compiler/interpreter of subset of Pascal implemented in 11 pages) and will stretch brain of your students. I know it did mine :-)

And is trivial to code some definitions in Assembly if you want.

Code is incredibly compact, ideal (and still used) for embedded systems.

| improve this answer | |
$\endgroup$
  • $\begingroup$ I am only a TA. Also, these students will likely freak out knowing that they will be introduced to three new things (C, x86-64 asm, and Forth). Your suggestion can help other teachers though! $\endgroup$ – JohnnyApplesauce Nov 12 '19 at 23:17
  • $\begingroup$ @JohnnyApplesauce - It depends how much you want to stretch you students' brain. C is close enough to other languages to be of little comparable (to Forth) interest. You can ignore ASM, to understand Forth student just to have understand the RAM memory and stack (no ASM commands are necessary). And Forth has interactive commandline interpreter, very easy (and fun) to poke around. $\endgroup$ – Peter M. - stands for Monica Nov 13 '19 at 22:17
2
$\begingroup$

I may be late to game, but you should target four "wow"s:

  • "wow, how small .exe file is!"
  • "wow, how fast this program is compared to Python!"
  • "wow, and THAT is how it's done!"
  • "wow, I'm a hacker now!"

For first one, you should compare compiled sizes of some Go, C++, C and assembler programs which all do a same thing. (Mandelbrot fractal generator in Asm is 61 bytes! Check https://github.com/leto/asmutils/blob/master/src/bonus/mandelbrot.asm, it is runnable)

For second you should show implementation of some number crunching algorithm (beware GPU computing -- try to find example, which can't be sped up with GPUs or optimized by SIMD)

For third one, I like to explain the MBR (even though it is no longer popular). You can put a small command line in 512 bytes of MBR, and load it as floppy in QEMU or from USB on real hardware. It often looks like miracle that you can run code without OS. (http://www.osdever.net/tutorials/view/hello-world-boot-loader)

For fourth one, show how to disassemble code in a disassembler, edit some string, save and run it with new string. Patching binaries no longer will look like mystery.

| improve this answer | |
New contributor
danbst is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
  • $\begingroup$ Swell answer! Can you expand on last para? Which disassembler? Also the 61 byte asm... Which assembler is it? Nasm? $\endgroup$ – Rusi yesterday
  • $\begingroup$ @Rusi as for 61 byte -- this is in 16bit mode mode fasm. I have a blogpost about it, but it is in Ukrainian :/ danbst.wordpress.com/2010/03/01/os_interpreter , full source code in the end. As for disassembler -- IDApro or Ollydbg are the h4ck3r tools. $\endgroup$ – danbst yesterday
  • $\begingroup$ Looks impressive. And google goes a long way with the Ukrainian $\endgroup$ – Rusi yesterday
1
$\begingroup$

I would argue the best way to do this is have some demonstrations prepared: things they can build with the tools you're teaching that "look" flashy and exciting. Show some cool programs written in C, demonstrate some sort of Arduino-based program that looks interesting (a relatively simple one I've seen waters plants), something in assembly that looks interesting, and so forth.

Make them say, "I want to build that!" before you give them the tools to build it or things like it.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Could you provide links to such Arduino videos, preferably ones that have source-code attached? $\endgroup$ – JohnnyApplesauce Nov 16 '19 at 23:17
  • $\begingroup$ @JohnnyApplesauce here's Make's description of how such a project could work, with a link to the source code and an instructable. No video, but pictures. I'd suggest googling 'cool arduino projects' or 'cool [technology] projects' and it'll give you stuff you're looking for. $\endgroup$ – heather Nov 17 '19 at 0:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.