Is there any way to see what my CPU is doing at the "assembly level"?

3

2

I was looking at how Assembly Language works, because I want to learn how the complex and fancy things my computer does actually happen at the CPU register/hardware levels. Is there any way to see what's going on during normal computer use?

I want to learn like, what kind of things go in and out of the various registers while I'm say, browsing the internet or playing a game, etc. Though even if I could watch this I am not sure how I could correlate it to specific computations that I can see happening at a higher level. That is, I don't know how I would know if this hex code going into this register at this time is related to Firefox processing SSL encryption, etc.

MetaGuru

Posted 2012-09-14T17:52:51.460

Reputation: 3 589

I dont think this is possible and even if it was how you would be able to see it. Even when your computer is idle, its doing a lot – Keltari – 2012-09-14T17:55:20.530

Answers

5

You realize that these CPUs run at 3GHz or so - if you wanted to run at real time, there's no way that your (or my) puny brain could keep up.

And a minor quibble: you don't look at assembler on the CPU, you strip away some info and go straight to machine code. There's no "branch to the print routine", it will be "branch to the location 227015ED42AB12F2 or whatever. You'll have to remember what that location does. Again, overwhelming your neural net. You'll have to "reverse assemble" what's happening to make sense of it. Very hard.

That said, you have a few options that don't do exactly what you want.

1) Get a debugger, run your program under the debugger. They usually show machine code/assembly (they use the C symbols like an assembler would). This will show some info, but remember that even a simple program can be millions, maybe billions of instructions. By the time you get to machine code, the source code has been compiled, optimized, and linked with system libs. This will be hard.

2) Look for simulators. These will show a subset of code and run slower, something you can keep up with. I had a C64 and an Atari 800, and played with Apples, so the Virtual 6502 seems fun to me.

Id also suggest, if you want to see the algorithms, seeing source code run, not machine code, is probably the level you want to try.

Rich Homolka

Posted 2012-09-14T17:52:51.460

Reputation: 27 121

Of course I don't want to watch it in real time, reading a log would be the only sensible thing. Thanks for the info! – MetaGuru – 2012-09-14T18:14:22.490

@libertas 1) a log would be huge, even for a minute you'd have 180 billion (3GHz * 60) rows 2) You'd have to dump full register state every instruction. say even 100bytes of data a row, and you'd have Terabytes of logs per minute. – Rich Homolka – 2012-09-14T19:15:24.947

1You may be able to get somewhere with an x86 emulator (NOT virtualizer) such as Bochs. I don't know if you can get a live real-time log or view of the CPU and emulation but there's quite a few tools for it. Of course you may not be able to run modern versions of Windows but I've successfully ran DOS/Windows 3.1 on Bochs before and the architecture is backwards compatible. – LawrenceC – 2012-09-14T19:37:27.660

@RichHomolka True! Fun to think about either way. – MetaGuru – 2012-09-14T19:38:41.510

3

You can step through an individual program with debugger, one instruction at a time, examining register contents, but it won't be meaningful unless it's a program you wrote or understand pretty well. To watch everything a machine is doing, you need two machines, one running a kernel debugger against the other. But that also is unlikely to be meaningful or even practical for most users.

Nicole Hamilton

Posted 2012-09-14T17:52:51.460

Reputation: 8 987