- Podcasts
- Programming Throwdown
- Assembly
About this episodeThis show covers Assembly, the lowest level language used to program a computer. This episode talks about the amount of traffic Netflix is…
This show covers Assembly, the lowest level language used to program a computer. This episode talks about the amount of traffic Netflix is generating, how many ebooks Amazon now sells, Apple not standing up for its developers, how young is too young for facebook, working on open source projects, and a new tool called Hype. The tools of the day are FileZilla, a cross platform ftp client, and PuTTY, a Windows SSH tool.
★ Support this podcast on Patreon ★Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Assembly
Hey, so I'm here in the Valley now, which is Silicon Valley. It's an amazing place. I mean, you anywhere you drive, you're surrounded by tons of tech companies, and it's really weird. It's sort of like if I was driving through the internet. It's like I drive on the road, and it's like, oh, there's Intel, there's Microsoft, there's LinkedIn, there's all these different websites. So it's kind of a—I don't know—it's sort of a really cool feeling, but sometimes it can even be kind of eerie, you know? Overwhelming. Yeah, yeah. I guess it's sort of like you don't think that these websites need a bunch of people. You think it's maybe like a few people in a basement or I don't know. Somehow, like I didn't connect websites like LinkedIn with corporate America, but I mean, this makes it all very opaque.
Website? Yeah, yeah, exactly. Like now it's almost like there are two faces. There's the physical manifestation and there's, you know, still, you know, the website. Like there's the LinkedIn building, which is like this red brick kind of old-looking building with a bunch of oak trees, and then there's the website, and you can't help but conflate the two concepts. Huh. Yeah, it's pretty nuts. So what have you been up—
To lately? Yeah, um, pretty much the same stuff as always. It's been really hot here, so you left just in the nick of time, I guess. And it's been really brutally hot and terrible outside, and so that's been kind of interesting. It's doing a number on my grass. So oh yeah, um, but I shouldn't complain anyways. It's nice to have a yard, but it's a pain, a lot of work, and yeah.
Yeah, awesome. Yeah. All right. Well, I guess we go to the news. So the first news item I see here is that Netflix is now the single largest source of internet traffic during prime time in the United States. I guess that is so—that would be what like six to ten, which is when most people sit down and watch TV. Instead of watching their TV, they're watching cable, or instead of watching cable, they're watching Netflix. Yeah.
That's pretty crazy. Now a while ago my wife and I canceled our cable, and we just have our internet. And we do this—we don't even—we just get the few basic network channels that are local, and other than that, we watch all of our video online. And I've tried to encourage people; this is a great way to save money, and most of us watch a lot of video on the internet anyways. So right, yeah, I'm a big proponent.
Of this. Yeah. I just—you know, as part of moving, I made a commitment to, you know, you've always been telling me to switch to Netflix, and you know, I really had no argument against other than being lazy. But with this move and everything, I decided to give it a shot. I love it. I mean, I love the on-demand. I like, you know, renting the or getting the DVDs in the mail. I noticed that there's a lot of—especially newer movies that you can only get on DVD. Do you know why that is? Yeah, so it has to—
The only thing that I really miss going this way is between, you know, Netflix for, you know, movies and older TV series. And then using a website like here in the United States, we have Hulu, which has a lot of the big networks shows on there. Um, the only thing really missed live sports. It's sometimes if you're a big sports fan, it's hard to get those sports games that would appear on a premium sports channel if you
have um if you have cable internet, you know, you automatically have some cable channels, right? Even if you don't have cable television. Like I think you get a small subset of the channels for free. That's right. That's right. I wonder can you pay the however much it is a year to get the sports channel like, like I know you can get the NHL channel for like $100 a year. I wonder if you can get that without cable television? Um normally,
No, they—that's called à la carte pricing. And at least in the United States, uh, the cable providers have been hesitant to go to all the cart pricing where you can kind of just choose I want this channel and I want that channel and I want the other channel. And part of that is because the channels themselves are sold as packages to the internet or to the cable providers. So they have to deal with the fact that uh those companies don't want to sell them just one channel; they want to sell them a package of channels because that's how they make more money. That.
a lot of buzz about this on the internet when this story first hit and people were kind of confused about, you know, exactly what did this mean? Oh, and Amazon must be, you know, counting not counting all of their physical books, like just counting paperback books or just counting hardback books. Um, and then they must be counting on the Kindle side the free books that people download on the Kindle, but Amazon came out and said this does not count. Um the free books that are downloaded—these are only people who buy books, who pay for books. And then also that uh it includes all physical manifestations of books that they sell, so paperback and hardback. So it really is an astonishing number that they have; they sell more ebooks than regular books.
Yeah, I mean this is—I don't know. I mean what do you think this means for publishers? I mean, I can't help but feel like the people in the middle, and this is both for what we talked about earlier with Netflix, you know, with the movie industry and with the, you know, with the book publishing industry, that the middle people are sort of getting completely cut out of the loop.
modern internet era. Yeah, and actually they're very quick to point out that fact, and that's bad because they're going to lose jobs or whatever. And I guess that comes to an economics thing, but you know, I hate to be harsh, but we can't really be responsible for trying to carry along what amounts to dead weight, you know? Right? If they don't have a place, it's kind of like when we—and this is probably cliched and probably not actually accurate—but you know, when automobiles first started coming about, and the people who sold whips for horses, you know, when the car nobody needed to buy those anymore once everybody had cars and nobody kept horses anymore. But it's like we shouldn't. Why should we feel bad for them? They have are some of them adapted and took on new industries and new ways to make money. And that's what these companies need to look to do instead of defending so staunchly their existing ways of making money. They got to find new ways to make money and new ways to provide benefit, not just screwing over their customers to try to get every last penny out of the
Few who stay with them? Yeah, exactly. I remember reading something in historically in the 1940s, 1950s as women were beginning to get suffrage and become part of the workforce and things like that. People were complaining that oh, now you have this surplus in the workforce and it's going to force wages down for everybody and things like that. But looking back on it now with our advance in sociology, no one would take that away and say that women shouldn't be allowed to work as was the case 100 or 150 years ago. So I think that it's similar here where we're getting this pushback because there's this dogma, or people have been entrenched in their core business, but 50 or 100 years from now, we'd probably just—we wouldn't want to look back to this day. Yeah.
And I mean it's one of those interesting things where it's a few people shouting very loudly to be heard because if you're in those industries, you care a lot and you're going to scream very loudly when somebody tries to basically get rid of your job or cut you out. Like it's going to happen in some of these cases where authors can sell directly to consumers, but the authors win, the consumers win. It's a more efficient market. So from an economic standpoint—which I'm not an economist, but that's a better thing—you want markets to be more efficient. You don't want inefficiencies, which is what the middlemen represent. And so they're screaming loudly because they're getting ready to lose their jobs. And then everybody else kind of doesn't really care either way; they just want to be able to buy what they want cheaply and quickly when they want it. So that's why it doesn't seem like they're shouting very loudly, but they actually do care. They just don't know that they care. Yeah, yeah, definitely.
Bridge. Basically, a patent troll is somebody who—a business, a corporation—who does not have a profitable endeavor, does not typically isn't a big player in any particular arena, but has acquired either through their own developers or through purchasing it from another company, has acquired many one or several patents that are of use and essentially hires a strong legal team to sort of go after companies who they feel are violating their often very umbrella um and open-ended patents in an attempt to earn money. So basically what's going on here is the patent trolls want to go after Apple and every large company because these companies are very wealthy and they would often settle at a cost less.
But what's happening is a lot of these companies have entire legal teams. Apple, Google, Microsoft—all these big companies have a whole team of legal enforcers who can bring down the club if they have to on some of these patent trolls. Now, so what the trolls have decided to do is to go after developers, especially small-time developers who are making apps for Apple products like the iPod and the iPad. So the patent troll will go and sue the app developer, who's often a small startup or a five six person company, knowing that they don't have adequate legal representation. And in this case, what this article really elucidates is that the people who are being sued here are just using the Apple SDK. So in other words, Apple provides you with a series of functions; in this case, this particular instance is some functions that let you—I think—in-app purchasing, so let you buy items from while you're inside a particular application. And apparently that violates some patent from this company, Lodsys. So um Lodsys is going and suing every app developer that calls this function. So what this article is sort of hinting at is that or I guess it goes right out and says it is that Apple really should engage their legal team to go after some of these patent trolls because otherwise people won't develop for the platform.
Yeah. I mean, I guess this is something that is gonna have to be handled by our legal system adapting to the fact instead of having a few big companies that sell to people—now it's instead of a what is that? A one-to-many relationship with the store being one and the people being many. Now you have a many-to-many relationship where you have many people buying from many sellers, and many sellers selling to a few people. And so you know, like you said, you can go make an app and only 10 or 20 people buy your app, and that's perfectly fine. But if these people are able to come after you and say, 'Hey, we're going to charge you five thousand dollars because you made a thousand dollars using our patent,' then you're just going to close up shop because you can't afford to pay that, right?
And I mean, just to draw an analogy of how ridiculous this is. Imagine if you are really into model planes and you buy and assemble model planes and you sell them in your store, and you can sell assembled and unassembled, etc. And somebody—you're basically dealing in terms of kits. So you buy a kit which has all of the parts, the wing assembly and the brushless motors, etc., to power the plane. And you'll assemble the plane and then sell it at your store. And let's say that that kit, the wing assembly, is violating some patent. Well, the company that sold you the kit ultimately, in my opinion, should be responsible. Yeah? But it's like now what they're doing is going after you for just taking something that—for buying something that violated a patent. And in this case, it's even more ridiculous because Apple has already settled with this Lodsys company. So Apple's not violating the patent because they paid off this company. So really this company shouldn't have a leg to stand on, in my opinion. Yeah.
But and it looked like this article from the Electronic Frontier Foundation is basically calling to action saying that Apple needs to stand up for their developers and defend them because this isn't fair to let the developers kind of just flap around in the wind without helping them considering that they know that those people can't defend themselves, right?
It's really funny to see an article where the EFF, you know, you just—I guess in this case they're not really siding with Apple. It's more like they're trying to drive Apple to do something, but you know the EFF practically hates Apple, right? Because yeah, that's true. So, just to hear them talking about Apple, it's really a sentiment to Apple and just how pervasive Apple has become in the digital world.
So talking about the way things are changing, you know, I saw an article saying that Mark Zuckerberg wants to be able to let kids younger than 13 use Facebook. Now currently, you have to be the incredibly intelligent individual that has to understand that even if you're under 13, you can still just click the button that says you're over 13 and get on. So actually there's, you know, many reports out there showing that there are, you know, millions of people on Facebook that are under 13, but it's technically not allowed. Like they're not supposed to let them use that because they're not able to decide what should and shouldn't be posted there, and it can just be a problem. And Mark Zuckerberg saying that, 'Look, this is kind of silly; they're already doing it. We should allow them to use it,' you know, and learn about it. To me, it's kind of, you know, even the article here in the title is like a minor controversy, and it's not really that big a deal, but I thought it was interesting to bring up that, you know, when we were growing up, when we were kids, you know, there was no worry about this kind of thing because that opportunity didn't even exist really. And now we have to think about that, you know, if we're going to have kids, what are we going to tell them to do? Like if they want to get on Facebook, you know, they can. So are we going to tell them, 'Look, you're not allowed to get on there,' or are you going to say, 'You know, teach them how to use it appropriately and let them get on'? And then how young is too?
Young. Yeah, I mean these are all really good questions, right? I think that one of the things that this article hints at is that the Facebook for a 12-year-old will look very different from an adult—the adult version of Facebook. And so you know, as long as there's the correct parental supervision, you know, built into like
Yeah, controls and even more so—I guess I don't know what the word is, observation? Maybe like maybe you can see all the profiles that your 12-year-old has clicked on or something like that. You know. Um then yeah, I think it would be great. I mean Disney already does this, right? There's um several Disney massively multiplayer games like The Pirates of the Caribbean MMO, and there's a couple other ones I can't think of off the top of my head. Oh yeah, I've seen
Yeah, yeah. And so they're 13 and under, and you know parental consent and things like that. And when I was at the Disneyland in California, um they had a little demo where you could—you could jump on and play. It was it was a little creepy being like 30 years old running around in this village with a bunch of 12-year-olds, so I wasn't on that game for too long without being weirded out and just leaving. But yeah, no, but I mean, you know the environment's there, and Disney's had tremendous success with that, and I haven't really heard of any bad press or anything. So yeah, I
mean as long as if you, you know, show your kids the, you know, how to handle when something is suspicious or looks wrong or, you know, to not say certain things online, that, you know, I think that's good. But there's a lot of adults who haven't figured out how to use it appropriately. So um I don't know, I think some kids could probably do a better job than many adults, but yeah, it's hard to say. I guess like you said, just as long as if maybe the parents have the option to be able to observe.
Right? And this really gets that sort of—I mean, just going off what you were saying a second ago, a lot of adults really don't understand, you know, privacy and and really how little privacy you have on the internet. You know, some people think, 'Oh, if I post something and I post it to my friends, no one else will see it.' And you know, I mean, I'm sure they know that all someone has to do is copy and paste that, you know, and post it to the whole world. But but maybe they just—they don't think that something like that would happen.' You
know? Yeah, well I mean even people don't understand the permanency of things on the internet, and it's kind of very different the way information exists in the world today. So you know, it used to be before the printing press, before writing, you know, before recorded speech that people would say something, and if you didn't hear it, it became hearsay. It became passed down like it was very ephemeral. But then now and today everything you do can be, you know, even this podcast, right? We'll record this, and then many years later after we've long probably forgotten we ever done this, our kids will probably be able to find this online somewhere floating around or posted somewhere. You know, it'll get copied thousands and thousands of times, and it'll just live on forever in one form or another. You know, so things you do on Facebook, even if you think you delete them or get rid of them, like you said somebody could have copy and pasted it somewhere else taking a screenshot of it. You know, it gets duplicated. And you see this with things like WikiLeaks when that happened, and aside from, you know whether that was right or wrong, just the fact that some of the people, you know, writing to WikiLeaks and saying, 'Can you please delete the copy of, you know, the stuff you have that you shouldn't have? That that's classified. Please delete it.' And it's like—like what does it matter? Like you can't—can you send us back? It's like, you know, I can't send you back to CDs. I sure I can delete it off of a computer. It's been copied out on BitTorrent to thousands of people, like yeah leading off my computers isn't going to change anything. Yeah, I
mean it's extremely true. There's a time when I was using LiveJournal a lot, and I was posting about something—about it was something that was it wasn't offensive or anything, but it was very trite, like something about 'I hated this particular class.' Oh, I really didn't like—I think it was American History. And for the longest time, if you Googled my name, the first link was how, you know, Jason Gauchi, which easily could have been traced to me and was me hated American History. And even as I was applying for jobs and things like that, I had to carry around this fear that like if some American History buff software engineer interviewed me, that you know it just wouldn't go over well. Yeah, so it is true, and it really, you know, especially as as you know this article, you know, draws our attention—if you're a 12-year-old, you really can't think about the permanency of what you say. You know? Yeah, most 12-year-olds just don't have the maturity to do that. So yeah, Facebook's gonna have a tough time, but if they can create an environment that's—that's, you know, safe and regulated and easily observable.
This is one of those no-duh. Yeah, that's right. But I thought this is interesting. I put in here because I know you've done a lot of work on open source projects and helped out with that. And you know, in general, it talks about learning how to communicate, learning how to work on big projects and planning and all this. I mean things that are kind of like no-duh, but I think when you're in school, you have this time, but you kind of think you're busy, but you're not really all that busy. And so if students would take time to actually go join an open source project and actually make contributions—not just to put it on their resume, but to actually experience growth—it'll make them better prepared when they first start their first job, and people will notice there's a difference, and it'll help their careers, right? I mean, the thing about you.
Programming is it really an art? And it's almost—I guess I would say it's a trade similar to like masonry and things like that. But unlike the Freemasons, which is a highly secretive society and probably doesn't do masonry anymore, but unlike those know secret trades of yesteryear, in this case all of that information that trade and that skill can be cultivated on the internet. But to do that, you really have to participate in open source. So, you know, we talk about many different programming languages here, and a lot of them have—as we talk about batteries included—like Python has a zlib compression built into the language. But you know, many languages like C++ and Java, low-level kind of languages you learn when you're first starting, they don't have a lot included. So you really have to sort of understand what are the tools at your disposal. If I want to do cryptography, let's say if I need to do some kind of cryptographic hashing or something, I know of several open source utilities, and I would just download and actually know which ones are good and which ones are painful to work with. And that's just because I've been in so many different open source environments. You know, I've seen you can go into the Mozilla Gecko rendering engine and go into the socket code for Mozilla and find out what crypto and MD5 libraries they use. And then you can visit their websites and move it back. It's sort of like reading research papers. Let's say you're really interested in some kind of—let's say you're interested in the Google car, like that's all open research, right? The autonomous car. You can read that research paper, and it'll probably use a bunch of words that none of us know. You can go and read the papers that are referenced by that paper and start to build the vocabulary and understand what's going on. In a similar way, you can dive into an open source project and end up learning a tremendous amount about programming, and especially about getting stuff done. And you can give yourself a tremendous amount of power to do some amazing applications. Yeah.
I mean, I think it's very easy to get overwhelmed. Even the stuff you just said is very overwhelming. But I mean, that's the same thing that happens to you when you first start a job. It just seems like oh, there's so much to learn. I'm never going to figure it out. But then you do, and you start to make small contributions and bigger and bigger. And some open source projects are probably better suited to this than others. Some are kind of notoriously—you don't want to say mean or hostile, but you know, kind of don't expect you to know a lot when you get there. And others are more welcoming. Even this article mentions the Google Summer of Code, which is particularly specifically targeted at students where Google pays that student to work on the open source project, and so those projects create set tasks for the students to work.
On. Yep. Yeah, those are definitely awesome. I know several people have participated in that. It's very accessible. So if you really get into a particular open source community—like there was a period of time where I was really involved in the Ogre open source graphics rendering engine community—and you can go and request to be a part of the Summer of Code if you have a particular project that's especially engaging, and those people are often very helpful. And they want—a lot of those people who are in charge of open source projects, they're natural leaders. I mean, the reason why Ogre is successful and Joe Schmoe's graphics library is not successful is because Sinbad and some of the other leaders of that community are very charismatic, and they draw developers to go on there and work for free. So they will be more than happy to help you out and get you started. So yeah, definitely if you're in college, definitely take advantage of that.
Many of you out there probably have developed or done some stuff in Flash. If not, I'm sure everybody's used Flash. If you've ever watched a YouTube video, well, now YouTube switched to HTML5, but regardless, many many applications out there on the internet, websites have Flash embedded in them. But to do anything cool with Flash, you have to buy the Flash Studio—what's it called? It's Flash CS5 Professional, which is I think it's like two thousand dollars. And even I remember as a student looking to get it and it was several hundred dollars for even the student edition. So, and plus Flash has other issues as security vulnerabilities, and it doesn't work on the iPhone. There's a hundred different reasons why making Flash stuff is kind of terrible. So what this Hype says is we're going to try and give you the same functionality as Flash, but instead of the output being a Flash video, it's going to be HTML5 with the Canvas tag and the JavaScript WebGL rendering. So you get to do the WebGL.
So it uses Canvas. Now they're looking at making it support WebGL, which would give it the hardware acceleration that Flash has. So basically this Hype is where Flash was when it was 1.0 and it was all software rendering, etc. Okay? But the cool thing about it is it looks, the interface feels like the Flash development environment. So you have the keyframe animation, you have the tweening where you say I want the object to be at position X at time zero and at position Y at time one, and at time 0.5 it's the midpoint of X and Y. So it does the tweening. It does a spline tweening so it can look smooth when things are moving around. All the cool things that Flash can do, and it generates something that you can see on virtually any device. Nice. And so this—
Tokyo. It's... well, that was Godzilla. Yeah, FileZilla defeated. I don't know DirectoryVille. I don't know, but FileZilla is not to be confused with Mozilla. Um, I don't believe they have anything in common. I don't think the communities are in common or anything. FileZilla is an FTP client, um, but its UI is very slick. It has drag and drop from outside the window so you can drag from Finder on a Mac or from Explore. You could just drag folders into the FTP server. It has a bunch of cool features, you know? You could do diffs. You can actually open a text file on the FTP server, and it'll open in your favorite editor. And when you save um and close the file, FileZilla somehow keeps track of the process when you've closed the editor. It uploads the file back, so it has a lot of nifty things, and it's completely open source, so you can put it on any computer. You don't have to pay for.
So I actually get it. Um you know, I'm a big, uh, you know, Mac/Ubuntu Linux fan, and in Mac you can get it through MacPorts, and in Ubuntu you can get it through um through apt-get. So neither of which actually use the website, so I've never actually been on the website. It's my first time, but, uh, but yeah, the FileZilla looks like the server is only for Windows, which is interesting. Okay. Yeah, but, uh, yeah, the client is very effective, and, uh, I'd highly recommend it. One interesting thing too: it has like an auto-updater interface, which is pretty slick even on Windows. Um you know, many of the open source apps, and this is one thing that I've always had a problem with, and maybe if I have some more time, this is something I want to address, is you have NSYS, which is um Nullsoft Scriptable and Solve System. So you know how you see like you download some open source program like FileZilla, for example, and it has your stereotypical like 'Here's a new license,' the new license in like a little install shield, and you click next. It's like the directory installed too. You click yeah.
Yeah, so my tool of the bi-week on the notion of, I guess doing networking tasks is PuTTY, which is a Windows tool for doing um remote connections to computers, so especially like SSH, Telnet—those kinds of things. It supports a whole host of things. There's actually a couple different programs um to do various features like secure copying SCP and stuff like that, and um this is.
To stick it to a comic in the newspaper and make it have the image of it like silly putty. Um sorry. Okay, anyways. Um yeah, but this tool is really good at connecting to SSH stuff on Windows. It's really useful for doing that because I don't think Windows has a native way to even—it has a native Telnet client, but not a native SSH client. And so um this is the thing everybody uses. It's a little confusing to use because it does so much. It's so powerful. Um but once you kind of figure it out, it's able to even do like setting up um proxy tunnels and stuff like that, so you can you know tunnel SSH traffic through it to another computer and do all sorts of interesting things like that. Um so it's really powerful, but just the even the basic ability of just being able to SSH something on Windows is very nice, and this is the de facto thing to go to. And so people who are trying to do this for the first time or using or have never done it before, uh if they don't know about this, they either quickly find it out or if you tell them, they'll be really excited they found it.
Yeah, it's open source and everything, which is important to note when whenever you're dealing with security. That's always a kind of an interesting thing that if you have a closed-source security tool, for instance, like an SSH client, and they don't implement everything exactly right, you could be subject to people getting your traffic even when you think it's not. So open source at least—you know, hopefully people have taken the time to review that or have the opportunity to review it, right? And look
for vulnerabilities. Yeah. So today, this show, we're going to be talking about Assembly. Yeah, and so like assembly lines—yeah, it's kind of like have you ever had to do community service at the soup kitchen, and someone comes up to you and they say, 'Hey, move a 20 to register three.' And the next guy comes up to you and you give him some soup, and he says, 'Hey, you know store three and register five.' It's similar to that, but it happens on the computer. Okay, that's a little bit of a stretch. Yeah, but as you could tell—as you could probably tell—Patrick is definitely the Assembly expert. And well, I can probably count on one hand number of times I've seen Assembly code, really.
kind of sticking with our a little format here: the history of Assembly kind of is the history of programming, I guess. That when you first have a computer that has—you know, just a CPU—we're talking that you kind of have to talk to it somehow. Something has to give it instructions to execute, and those instructions aren't C; they aren't Python; they aren't Java; they aren't Erlang; they aren't C#. Um, so right because
Well, actually not quite. So this is a maybe a knit—maybe a a, you know, something that's really specific and nobody pays attention just; it's semantic. Um, but Assembly actually isn't what runs on the computer directly. Assembly is even one step slightly above that. So the thing that actually runs on the computer are known as opcodes. So this is like raw hex instructions, you know, just like a number, a hex number that represents move, which moves from one register to another register. Oh right.
a register, and then a number that corresponds to a hex number that corresponds to which register, and then a hex address. And so that's basically humanly not readable. You can't read that at all. So one step above that is Assembly, and it—it kind of has to do with what's called mnemonics, which is kind of reassigning a name for something else. And so instead of having to remember that you have to type, you know, FA for move, now it can just have the letters MV or MOV. Um, and so it's a renaming, but it also allows you to have special names for registers so you don't have to remember the hex code for each register and things like that. Um, but what that does introduce is the need for an actual what's called an assembler, which is kind of like a compiler but a lot simpler. Um, and that even some languages—the assembler can be one pass instead of many passes, which we've never talked about that before. But um the way that high-level languages are, the compiler can have to make many passes through a given source code to try to figure everything out, and an assembler is typically either one pass or two pass. And what it does is it goes through, and if you use a variable, it has to figure out where in memory that variable is going to reside. Um it has to figure out what the register names are, and it kind of converts all of those things to offsets into numbers. And then the second pass, it actually does, you know, almost like a transliteration just from the instruction to the hex code—this the instructions that are fed into the CPU which tell it literally how to guide something through the pipeline, through the ALU, you know, moving stuff from one register to another, to do an addition, to do a multiplication, to go fetch something out of RAM, to handle all of that kind of stuff. So what?
of things. Or well, so no, but sometimes and this is a very unique quirk of assembly. So when you talk about higher-level languages, which assembly is kind of the lowest-level language—you know, excluding opcode programming, which nobody does—so assembler, but it is the lowest. And you kind of go up to like C and then to C++. And there's something above that, maybe Java or Python. And so when you move up that stack, you're gaining portability, which is the ability, like when we talk about running on a virtual machine, that you don't care about what CPU you're running on. But the interesting thing with assembly instructions is that they are completely unique to a given processor. So if you're using, you know, an x86 Intel processor and then you try to go run on a machine that has something different—so, you know, Macintosh computers used to run on PowerPC, older computers might run on Alpha processors, or even like the Android phones are using ARM processors. And actually the iPhone does as well; it uses an ARM processor. Those all those processors have different, completely different instruction sets. And so the assembly language and the routine supported—the instruction supported can vary greatly between those. For instance, that on one way that an instruction is done, if you say have a move and you want to move from one register to another register, you may list the, you know, origin register first and the destination register second. And then in another processor it may be reversed where it's the destination register first and the source register second. Oh, I see. So you got to be careful. And then also the number and you know complexity of the instructions can vary. So that has to come with something called the difference between CISC and RISC. And CISC is a CISC, which is Complex Instruction Set Computer. And then RISC is a Reduced Instruction Set Computer. And so originally the CPUs were very basic and kind of were RISC by definition, but they weren't called that because there was no alternative. They could only support very few instructions, right? And then as they grew, they became more complicated to support things. Even like you were talking about, like you may have a single assembly instruction that allows you to sort an array or yeah, an array of like eight numbers. Um and it can do it in one instruction. Now that instruction may take many cycles to execute, but you can have one assembly instruction that does that, and it's going to be very optimized because it's not implemented in software at that point; the hardware actually implements that sorting, and that's right.
Do you want to take a shot at that or do you want me to go? I'll give it a shot, and then maybe you can clean up. Yeah, go ahead. Yeah, I'm not too good at the low level, but so basically for what I understand, you know, everyone knows about main memory. So you have, you know, you go to the store to Best Buy and you say, 'I want a computer with four gigs of RAM.' So you end up with, you know, a bank of four gigabytes. And um, you know, applications are given what's called an address space, you know, protected address space inside of that four gigabytes. So when you start Microsoft Office or something, um, you know the operating system in this case Windows gives Office a certain amount of memory, like you can have this block of 128 megs, let's say. And so Microsoft Office can go in that memory and allocate deallocate memory and you know put numbers in there and put your Excel spreadsheet in there, etc. Um now the computer, the CPU, it's sitting on a chip on your motherboard, and it's, you know, in terms of the motherboard, it's far, far away from the memory. So um the memory is it takes incredible amount of time, like on the order of milliseconds, to get data from the memory to the processor, or maybe it's faster than that, like microseconds or something. But the processor itself can run in terms of nanoseconds. So the processor needs the ability to sort of look at data and put data into places very quickly, much faster than the memory can support. So there are things called registers, which are sitting right next to the processor. So actually in the processor, right next to the logic unit—so you know the units that are responsible for adding two numbers, right next to that there's a small bank, usually let's say 10 to 20, you know, registers that can hold things which are going to be used immediately.
Yeah, that was for, you know, something that could take a very long time to explain. That's a really good explanation, and it's kind of talked about as memory hierarchy. So you can kind of imagine it like a pyramid. So like you were pointing out RAM, you have gigabytes of RAM, um but then a process—registers. You may only have like, you said 32. Um they're normally in powers of two, so like 16 or 32 registers. Um and each one of those only holds a single. If you have a 32-bit computer, it'll hold a single 32-bit number, or if you have a 64-bit computer, it'll hold a 64-bit number. And that's where those—a 32-bit processor, 64-bit processor—that's where that comes from is what the size of the native um amount that it works with is. And then so the hierarchy is that close to the CPU, it's very, very limited memory. So you may have 32 numbers. Um and then as you go up, you go through something called cache, which is a little bit bigger and a little bit farther away. And you keep going out all the way out to main memory, and then to the hard disk, which does take, you know, milliseconds to access. And if you think about um, you know, you say it's far away, and this was an illustration that helped me when I was learning about computer architecture, but um the processor today runs at a couple gigahertz. And if you think about uh the frequency of one gigahertz in one cycle, so that the gigahertz measures how many times the computer's clock ticks up and down per second. So a one gigahertz computer is what—what's giga? Is a billion because a megahertz is a million, and then a giga is a billion. So a billion times in one second it it you know counts. And so in each of between each of those counts if you actually look at how far light can travel in one cycle, it only amounts to, you know, about uh, you know arms' width. So if you raise your arms up and hold them about shoulder width apart or whatever, that's about how far light can travel in one cycle, which is not very far—so a couple feet, right? And so even though the things on the board, you say, oh they're only a couple inches apart. Well, yeah, but we're talking about speed so fast that even in one clock cycle you cannot go out to main memory and get back.
right. That's right. And it isn't a direct connection. There's actually if you think about how far it has to travel, it's like a veritable maze between the process where you are in the processor all the way out to main memory. It's not a straight line, right? And there's a controller, a memory controller between the two. It's very complicated. Yeah. Um so yeah, so the registers like you said there's a bank of um holding cells of one one number each in each one, and you explicitly operate on those when you write an assembly instruction. And so one of the differences between RISC and CISC is that in a RISC, for instance, it will only allow you to do multiplication taking from two registers and putting into another register. So multiplications, additions, subtractions, you know, divisions can only be done on register-to-register basis. You cannot go out to main memory and then you have so you have those kind of basic instructions. You also have what's called a load and store. So a load says go out to main memory and bring it into a register address, and a store says take something that's in a register and stick it out to main memory. And those ones can operate outside of registers. Um and then you can have something says move where you might need to move from one register to another register, so essentially do a copy from one to another. Uh then so that's kind of talking about data memory. There's also something that you have to be aware of, which is program memory—program data, which is the instructions that are executing. So there's kind of two, and depending on your machine, there's kind of two can be together, it can be separate, but there's two kinds of data: there's data that you operate on, and then there's the instructions. And so the instructions have to be fed into the computer as well. And so what that is is you have an instruction pointer, which is the address and RAM that the current assembly instruction you're executing—the current opcodes are held. So on a 32-bit machine, those normally, you know, that's 32 bits is divided up between uh the what the opcode is, what a register is, and what the, you know, source register is, what the destination register is. And so when the when the CPU loads that instruction, it then has to know what to do with the instruction pointer. And so if it's for instance just a move or a load or a store or an add, what it'll do is just increment the instruction pointer by the size of that instruction and so just kind of go to the next instruction. But that doesn't support any sort of conditional stuff. So you're if you—if you didn't—if you just had those instructions, you would never be able to do anything different. Your program would be completely deterministic. You would just start it and always would do exactly the same thing, and nothing would ever change, and that'd be really
boring, right? I mean, we know that when we write C code or any other language that there are sections of the code that we do or don't step through at runtime. So we might say if some variable is greater than 20, then do this code; otherwise it's going to skip that that block of code. And so when these languages—higher-level languages—get compiled down to assembly, that corresponds to a jump. That's right. Well, actually there's yeah.
Depending on a couple different things, but one could be a jump. So a jump would be like a go to another instruction that isn't the next instruction. So you could jump to a different address, and that's where the assembler helps versus writing in pure opcodes. Is that that jump can go to a label in the computer, in your file, in your source code, which the compiler, the assembler will be able to figure out what that address is later. If you had to do it by hand, you would have to calculate how many bytes to skip in your jump, and that would be confusing and annoying.
had a void function and you're returning, that would just be a jump. Yep, and it would jump—that actually like it's confusing; we'll ignore that for now. Um, but yeah, so a jump just kind of goes there wherever you tell it an address, and it just picks up—it changes the instruction pointer to that new address and picks up from that point and just starts going right. The other option is a branch, and so a branch basically like the word implies takes one of two paths, and those two paths are normally based on some sort of conditional. So you could have 'branch if equal,' 'branch if not zero,' 'branch of zero'—these kind of instructions. And depending on your processor will depend on what you have, but for instance, if you say 'branch if not zero,' then what you can do is previously you can have something that evaluates whether or not a given number—you might do a subtraction, and if that subtraction isn't zero, or if you have something that's greater than zero, then it sets a register to have a value that you're going to key off of. And when you say 'branch if equal' or 'branch if not equal' or 'branch of zero,' then it goes and looks at that register and it says, does this register meet my criteria? If so, then I just go to the next instruction. If it doesn't, then I'm going to go branch and do a jump to some other portion of code. And that amounts to like you were saying before the 'if' block. So if you know 'if true,' right, then execute what's in this block. So it's just going to keep going to the next instruction, but if not, it needs to skip over that block and pick up somewhere else. And so those kind of make up the basic instructions that you have, and it seems really simple, almost like—you know, I don't know about you, but the first time I learned binary, it was like didn't make sense to me that you could represent every number in binary, right? It's like no, you can't do every number; there's got to be some number you can't do. And then slowly it dawns on you, wait, you can do every number. So assembly is kind of the same way where when you learn it, there are actually computers that have been theoretically proven that only have one instruction and you could write every possible computer. It's called Turing complete, that basically means you're able to prove that you can write every possible program with just one kind of instruction. But that's not necessarily efficient or the best way, but it can be done. And so with very, very few instructions, you can build all the complex things that we have in our high-level languages. Yeah.
Mean just think—you know, the Java, um, you know, I guess Virtual Machine. Um, so in other words, if you're writing essentially assembly code for the Java machine, um, it just has a stack; it doesn't even have registers, just as a single stack. So I guess in a sense as infinite registers, but basically you can only look at one register at a time. Yeah. So and that is able to do anything that you can code in Java, which is as we've talked about before, which is—you know, just just about anything. Yeah. Um, that you've seen on the computer can be done in
Java, and all of those design choices have trade-offs with them. Um, engineering is all about making trades. It's about understanding there's no one right answer; that it's about understanding the choices you make. And part of programming—throwdown what we're trying to do is say that there's all these different languages and they all have their advantages and disadvantages, and help you understand better what those are and help you make the intelligent choice. So for instance, the difference between CISC and RISC. You might say, 'Well, why is there a reduced instruction set? Why doesn't everybody just provide as many instructions as possible and make them really efficient?' But when you do that, your processor becomes more complex, and it's also harder for the processor to do certain optimizations where if it's RISC, instead of spending all those extra um transistors trying to implement these complex instructions, you can have it be smarter. So take a few instructions and work with them more intelligently and do things like reordering them and stuff like that.' And so these are all trade-offs they get
made. Yeah. I mean, if you can—you know, tighten the bounds on your expectations for, you know, for your instruction. So in other words, uh, if one of your instructions is, Patrick said earlier, is to sort a list that might take a long time, the bounds on that instruction might take anywhere from a nanosecond to 300 nanoseconds. And versus a RISC processor where you could say definitively, you know, every instruction is going to take one to let's say 20 nanoseconds. And so if you can tighten those bounds, then you can better predict what the future is going to look like, and prediction is key to making assembly—to making, you know, CPUs run faster. That's right.
That's right. And we could talk endlessly about this. I mean, understanding assembly is understanding computer architecture, and understanding computer architecture, I believe, is key to writing efficient code. And you got to know the system you're working on. If you don't know the system you're working on, even if no matter what language you're writing in, you're not going to write the most efficient code. And you don't always have to write the most efficient code, but if you kind of take a few minutes to understand what you're working with, it's going to help you avoid, you know, doing grossly unnecessary uh things that are very inefficient, right?
Kind of the first place I learned it was in school, and when I was at the university, they talked—when we used embedded processors, so kind of Digital Signal Processors. They often don't have an operating system, don't have even something like C needs a library of code to be able to call for functions like printf or you know how to what was a for loop really do? And they rely on helper functions, right? These don't have those. And so you have to write in assembly. So we use assembly to be able to program those. We also had to learn how to design our own CPUs and design our own assembly language, and of course, we program those in assembly. Actually, we program those in pure opcodes like we were talking about. Oh wow, that's one use, and that really helps you understand what's going on. And it's that's pretty cool, but it's a lot of work. It's kind of scary. So, but kind of in the real world that's still used today, even with all the advances, there are still times when you have to use assembly because there's nothing else to use, right?
And just think, you know, right now as Patrick is saying, we have the ARM processor. Which is actually the ARM processor is quite old, but you can imagine as new processors come out, somebody has to write the assembly language, you know, assembler for those processors. And that person is writing in straight opcodes. That's right. That's right. Um
So, so that's kind of one option. The other reason to use it is, you know, if you want to squeeze every bit of performance out of a system, you typically will use assembly. And so one of the paradigms is important is to not optimize too early. But once you've determined this code is executed, you know, a million times every frame of my game—let's say I got to do this one thing a million times—then you want to go in and say that's slowing my system up because it's taking too long. You can go in and write that specific routine in assembly and make it just blazing fast because you're going to do things as efficiently as possible. Because for instance, instead of going out to memory, you can say, hey, how do I use my registers more effectively than maybe the compiler is able to do? Because the compiler is working at a much higher level, has a lot more things to do, and it can't be perfectly efficient all the time, right? Another thing is if you need precise timing. So if you need to know exactly how long something's going to take, you oftentimes will write it in assembly. And then we talked last week about reverse engineering, and we talked about how that if you write something in C, compile it—that's a lossy operation. That going the other way isn't going to get you back to exactly where you started. And so what one thing you can do is even if you've compiled stuff in C or C++, or even for instance compiled it into Java bytecode and reverse engineer that, if you actually look at those opcodes that were generated and write the assembly for that without going to a higher-level language—which is going to be more confusing in some ways—you can look at what the actual instructions that were generated were and begin to recover what the structure was, what was it doing? Um, how was it accessing memory in what ways? And you can actually begin to understand what the program was doing even if it wasn't written in assembly by looking at the assembly. Yeah, definitely I think.
Another area where you see the assembly code is in areas that, as you mentioned earlier, that have high performance requirements. So I know if you look at the Quake III source code, I believe there's some blocks of assembly in there where they're dealing with things particular to the physics which had to be executed, possibly hundreds or thousands of times a
Important. Yeah, you're working in a very specific niche—niche—when you're doing those kind of things, right? Right. The other thing that I mentioned that's used a lot is interrupt service routines. Because interrupt service routines kind of take the highest priority in the system. So when an interrupt happens, it has to get serviced, and you want to get in and out as fast as possible because you don't want to miss other interrupts. You don't want your program to be paused while that's occurring. So oftentimes those will be written in assembly because the object of the ISR is to basically capture what happened, store that somewhere, and then be done and let somebody else do the processing and handling for it. And so in order to make that even faster, those will often be written in assembly, right? Right. And then of course, in an operating system, many parts are written in an assembly language because you don't have the liberty of using other stuff that relies on the operating system because you're writing it. Yeah.
And so of course over time we kind of move up the higher-level language ladder, as it were. So you'll find people who have been programming for 20, 25 years remember having the only option be writing in assembly. And then as C came out at first people mistrusted it, right? Oh, there's no way it can be better than me at writing assembly, you know. And they were right, and it was not nearly as good. But then over time it became better and better, and it increased your efficiency at writing. So even though your program a C program will never be as fast as a handcrafted assembly thing—well, I shouldn't say never, almost never will be as fast as somebody who hand-coded assembly to do the same thing—but it can get close enough that for almost every purpose it doesn't matter.
Right. And even if you know it's two times slower, um you know the productivity, you know one of the things that's really interesting is, you know, computers are increasing at an exponential rate, but the productivity of engineers is actually decreasing or staying constant, let's say. And the complexity of the system, the amount of code, you know, an effort that's required to build systems is increasing. Um you got a linear rate. So what what's happening? Long story short is that computers are getting much, much faster, but we humans who program them are not. And so you know if you have if you're going to program in C instead of assembly, even if it's twice as slow, if it makes you as a programmer twice as fast or 10 times as fast, it's worthwhile. Yeah, definitely. And the kind...
Of idea here is if you waste cycles, it's not a big deal because in a few months it'll—it'll be well, that's the way it always used to be. Now that's changing today, but um still it it's still kind of in effect at some level that don't worry about wasting cycles because if it's something that only gets executed once, it's not a big deal. But like we said, but if it's something that get executed, you know, many, many, many times, um then that might be something you want to look...
Definitely. So it's—we've sort of hinted at this, but you know, the strengths of Assembly language are that you have complete control of the hardware. You're not coding to any virtual machine, as in Python or Java, and you're not relying on some expensive and lossy and—and—sort of somewhat, you know, bloated with respect to hand-coded Assembly. A bloated compiler like C or C++. You know, you directly know what's going on with the memory and the processor, and you can very accurately, you know, estimate the timing of a certain block of Assembly. And it really sort of makes you one with the hardware. Your zen with the hardware is much increased. Yeah.
But it does lead to a bunch of weaknesses. Well, not a bunch. One is just absolute tediousness. If you had to write a large-scale program—you know what? Might be a 10,000-line C program in Assembly. Oh, it would be ridiculous and very, very hard to maintain. And I'm not saying that nobody has ever done it, but it's just the maintainability is a lot.
Worse. Right? I mean, just think of this simple expression: X equals Y. Well, in Assembly, you have to find where Y is in memory. You have to load that into one of your registers. You'd have to load X into—or actually let's say it was—sorry, let's say it was X equals Y plus Z. You would have to load Y. You'd have to load Z. Then you'd have to perform the add operation and put that result in a new register, and then you have to put that register into X. So I mean, all these different instructions for something that's just five or six characters? And see, that's right. That's right there.
Yeah, for and now I should mention that if you, for instance, code for a Core 2 Duo processor, which is an Intel x86 architecture, what that x86 architecture that you hear people talking about, and the ability to run executable on one Windows PC and on another Windows PC or a one MacBook and another MacBook that may have different specific processors but they're in the same family that has to do with the fact that they have the same opcode—that x86 family is the same set of opcode instructions. So they're binary compatible with each other, right? Yeah. Oh, and that actually brings in a lot more, but we'll skip it for now. Now I did want to say as far as if you're interested, I wouldn't recommend Assembly as the first language you learn, but I definitely do recommend it as something to at least spend a little bit of time with and learning because it will teach you a lot about how a computer really works at the lowest level. But you don't have to learn on a complicated machine like an x86 instruction set or an ARM instruction set. They actually have toy languages and toy—I don't mean they're in a demeaning way, but very simplistic CPU architectures and assemblers that will work for those so that you can practice on a, you know, four-register eight-bit CPU that you know has only like two or three instructions and practice moving stuff around. And actually, they'll have the simulator—will show you where the instructions are moving, how the processor is executing, and that. And that's a very informative and enlightening thing, and I don't have any right now to recommend. They're all out there if you just search around for them. You'll find them. And yeah, that's something I recommend.
Make a shameless plug for an open-source project I work on called MAME, which is a multiple arcade machine emulator. And what MAME does is, as the name suggests, it emulates the processors that were used for just about any of the arcade machines that were from all the way from Pong all the way up to around the mid-'90s. So you can go into any of these processor drivers and what you'll see is a software assembler. So you'll see something which can read in the assembly language for that processor and convert each of the opcodes into or represent each of the things in C. So, for example, the command that loads a variable from memory to a register—if you look at the main source code for any one of those processors, what you'll see the load instruction do is it will just essentially copy the variable from one location to another because it's all done in C. So, in other words, someone has written a C emulator for the machine, and you can sort of get a feel for what assembly looks like and what an assembler does by looking at that source code without having to actually mess with x86. Yeah.
Also a lot of good books because the way, like I said, this is the only thing people used to have. Now we have many choices of programming languages. You know, 20 years ago you didn't have as many, and so there's a lot of learning material out there, a lot of good books that are written. And then you know, a lot of people—and I think I'm one of these people—I think that if you really want to be really good at writing programs at some point, you're going to have to learn assembler, even if you never write a real program in assembly for your work, for your job. Understanding is going to be invaluable to helping you write good
Gonna say thank you for those of you writing reviews. I saw we had a couple more, so I definitely thank you for that. We're very grateful for you guys are saying really nice things. It helps us keep going knowing that you guys are out there enjoying this and tell your friends about it. Email some people, get your parents to listen. You know whoever. We don't really care one and all welcome to the Programming Throwdown, and learn something. Yeah, definitely.
Yeah, and so if you again want to check out our website, it's programmingthrowdown.blogspot.com. So feel free to go there. We post show notes, the links to the news we talked about, and kind of a summary of what we discussed about the programming language, and also a link to the download, which obviously you've already found because you're listening to this. Or of course, you can subscribe to us on iTunes and get it that way. Whatever works for you.
Yeah, we got a mail from Justin. We probably shouldn't give away his last name. Yeah, that's because I hate when people do that to me. But yeah, just wrote to us. He said he wanted to hear some more about network security, which is—I you know, I've never really gotten into network security, but you know, I have a lot of friends who are really into like cryptography and all that stuff, and it's one of those things that you know I don't understand personally, but I know a lot of people who are allured by network security. So we will definitely try to talk about that, and there's definitely more that we can say about that. Yeah, I know he asked.
guys who write self-modifying code because like I said, you know instructions are just some other place in memory so you can write code that modifies itself. And some modern operating systems prevent you from doing that for good reason because most of the time if you're doing that, you're a virus. Right? But yeah, it's like you can write code that modifies itself on the fly.
Yeah, well thanks Justin for writing. And yeah, if anyone else has any more comments or anything else that they want to tell us, send us an email at programmingthrowdown@gmail.com. All right. Well, I think that's a wrap till next time. Have a good one guys. Okay, the intro music is Axo by Binar Pilot. Programming Throwdown is distributed under a Creative Commons Attribution-ShareAlike 2.0 license. You're free to share, copy, distribute, transmit the work, to remix, adapt the work, but you must provide an attribution to Patrick and I, and ShareAlike, and kind.
