Playback speed
×
Share post
Share post at current time
0:00
/
0:00

Paid episode

The full episode is only available to paid subscribers of Computer, Enhance!

Simulating Memory

Memory loads and stores are last thing we need before we can examine real programs.
27

This is the ninth video in Part 1 of the Performance-Aware Programming series. Please see the Table of Contents to quickly navigate through the rest of the course as it is updated weekly. The homework files (listing 51 52, and optionally 53) are available on the github.

A lightly-edited transcript of the video follows.

As I've said many times throughout this section, our goal is not to emulate an 8086, it's to get a solid feel for how machine code works on the x86 line of processors. We've almost accomplished that goal. The only thing we have not looked at yet is the interaction between the CPU and memory.

Before starting this course, a lot of people might have thought that assembly language was inscrutable — that they couldn't read it, and it would be very hard to learn to read it. But if you've managed to do the regular homework so far, you’ve basically learned how to read and understand assembly language. Yes, you don’t know the thousands of instructions that are in a modern x64 core. But no one really does! Even programmers who read assembly language often tend to know only a subset of the instructions by heart, and they look up the other ones when they need to. If you’re done the homework in this course, you now know how to do exactly that, as you’ll see when we move on to the next section.

In this post I’d like to finish our tour of basic x86 instructions by implementing memory-to-register and register-to-memory mov instructions. They are the last piece of the simulation puzzle that will allow us to write a whole variety of real programs if we want to. It may seem strange, but just mov, add, sub, cmp, and conditional jumps are more than enough to build very complicated programs if you want to!

So let’s finish mov. From the decoding homework, we know we can include memory addresses in the mov instruction as either the source or the destination of a mov:

The full video is for paid subscribers

Computer, Enhance!
Programming Courses
A series of courses on programming topics.
Authors
Casey Muratori