0x73EE (opcode)
73: high byte
7 high nibble, 3 low nibble
EE: low byte
E high nibble, E low nibble
Representation:
c: high byte, high nibble
x: high byte, low nibble
y: low byte, high nibble
d: low byte, low nibble
To extract nibbles, we perform the & operation with F and then right shift the remaining bits.
for example: opcode = 0x8014
c = (opcode & 0xF000) >> 12 = 8 (means arithmetic/logical operations between registers)
x = (opcode & 0x0F00) >> 8 = 0 (register index 0, V0)
y = (opcode & 0x00F0) >> 4 = 1 (register index 1, V1)
d = (opcode & 0x000F) >> 0 = 4 (add register 1 to 0)
The CALL opcode (0x2nnn, here nnn is a memory address) sets program_counter to nnn, the address of a function.
Calling a function is a three-step process: > Store the current memory location on the stack. > Increment the stack pointer. > Set the current memory location to the intended memory address.
The RETURN opcode (0x00EE) sets program_counter to the memory address of the previous CALL opcode.
Returning from a function involves reversing the calling process: > Decrement the stack pointer. > Retrieve the calling memory address from the stack. > Set the current memory location to the intended memory address