I wrote this throwaway piece of code while working on lc-3 vm:
#include <iostream>
#include <cassert>
#include <bitset>
using namespace std;
void decode(int instruction) {
I wrote this throwaway piece of code while working on lc-3 vm:
#include <iostream>
#include <cassert>
#include <bitset>
using namespace std;
void decode(int instruction) {
Implementing LC-3 in zig and it seems like a good time to take some notes on how they work (or how to intuitively tell what they are doing.
From my understanding, the form a << b
can get turned into a * (2 ^ b)
mathematically. So 1 << 2
becomes 1 * (2 ^ 2)
, which is 4.
From a more natural view, taking 1 to binary with 5 bits gives 00001
. If we say shift it left 2 times, it will become 00100
, which is 4. Very nice.
The form a >> b
can get turned into quotient(a / (2 ^ b))
mathematically. So 14 >> 2
becomes quotient(14 / (2 ^ 2))
, which is 3. 14 / 4
is 3.5, the quotient of which is 3.