Lukasvg / Thumb399

ECE399 VHDL Repository
1 stars 0 forks source link

NZ flags #4

Open Lukasvg opened 9 years ago

Lukasvg commented 9 years ago

The design needs to be extended with N and Z flags based on the result of the instruction. Please check the manual to determine which instructions set flags. The C flag should already be set by some ADD instructions.

Lukasvg commented 9 years ago

NZC flags

Set flags for all instructions previously implemented, including arithmetic, logical and shift instructions. The V flag does not yet have to be implemented.

chow004 commented 9 years ago

NZC conditional flags for previous instructions (ADD, ADC, shift instructions, MOV, logical instructions) have been appropriately updated and tested. The merged fixes test bench however currently fails since we are not branching to appropriate place in instruction memory to test them.

When trying to update the conditional flags, if we try to base it off of our result in most cases, because the result is simultaneously being updated the update procedures don't execute on the correct values. To fix this the instruction procedures uses a variable in order to get a value that is updated before the flag update procedures are called (because variable seem to essentially use blocking assignment, while signals do not).

I also noticed some aforementioned instructions, such as the shift instructions, used a integer range 0 to 31 as a parameter. This is false as the shift instructions that shift according to the value in a register can shift up to a 32-bit value integer. However, we cannot specify an integer range large enough to encompass a 32-bit integer without getting a compile error. We must also remember that, in most cases, any shift that is of value 32 or greater is all the same result. To protect against users from trying to pass in an integer out of range, I added an if check in the shift instruction cases that will simply insert the integer 32 if the parameter is greater than 32.

For the rotate procedure this is different since we are continuously rotating the bit values. Therefore, when calling the rotate procedure, I only consider the lower 5 bits of the register specifying the rotate value. This is because if we rotate 32 positions we get the same output as our input, therefore we only need to consider the remainder values below 32.

If a shift instruction is called with a shift value of zero, I do not update the carry flag as appropriate. If I did not check for a shift value of 0 it would update the carry flag incorrectly, so this is specified by an if-else condition in the shifting procedures.