machine-code

Calculate memory accesses

拈花ヽ惹草 提交于 2020-07-22 06:39:27
问题 xor dword [0x301a80], 0x12345 How many memory access when we know the op code and addressing mode is 2 bytes? If I understand correctly, even thought it is 0x12345, this is acctually still 4 bytes and we cant attach it to 0x301a80, right? So we have here: 2 + 4 + 4 bytes (And not 2 + 3.5 + 2.5 = 8) which is 4 memory access. Am I think right? 回答1: The total instruction size is 10 bytes (in 32-bit mode). That takes probably 0 to 2 I-cache accesses on a modern x86 to fetch in aligned 16-byte

How does a CPU know if an address in RAM contains an integer, a pre-defined CPU instruction, or any other kind of data?

≯℡__Kan透↙ 提交于 2020-07-09 08:44:40
问题 The reason this gets me confused is that all addresses hold a sequence of 1's and 0's. So how does the CPU differentiate, let's say, 00000100 (integer) from 00000100 (CPU instruction)? 回答1: First of all, different commands have different values (opcodes). That's how the CPU knows what to do. Finally, the questions remains: What's a command, what's data? Modern PCs are working with the von Neumann -Architecture ( https://en.wikipedia.org/wiki/John_von_Neumann) where data and opcodes are stored

How are Mathematical Equality Operators Handled at the Machine-Code Level

徘徊边缘 提交于 2020-06-28 03:37:35
问题 So I wanted to ask a rather existential question today, and it's one that I feel as though most programmers skip over and just accept as something that works, without really asking the question of "how" it works. The question is rather simple: how is the >= operator compiled down to machine code, and what does that machine code look like? Down at the very bottom, it must be a greater than test, mixed with an "is equal" test. But how is this actually implemented? Thinking about it seems rather