Skip to content

Implement the prefix SWAP instructions  #22

@bleasey

Description

@bleasey

Things to be done

Refer to the last portion here for additional details. Also refer this pdf for details on the instructions.

Decode the instruction

  • The first two bits of op will determine which family of instructions to execute. 00 corresponds to the Rotate/Shift family of instructions.
  • The next three bits determine the exact function (110 corresponds to SWAP).
  • The last three bits determine the register whose value should be checked. The data member register_operands_map (note that it is renamed, no pfx word) of the CPU class can be used for this purpose.

Description

SWAP: Swap upper & lower nibles of n.

Flags affected:

  • Z - Set if result is zero.
  • N - Reset.
  • H - Reset.
  • C - Reset.

Create the methods

Follow a similar approach as you did last time!

Files to be edited

  • CPU.h
  • ins_prefix.cpp

Read this again!

Again, since everyone is working on the same file simultaneously, we will follow certain conventions to reduce merge conflicts and ensure uniformity in code.

  • Use only simple nested if-s for decoding. Although not optimal, we can later optimize these and convert them to if-else ladders or switch case statements in another issue. For example:
void PFX()
{
    ...
    if( <check if first two bits correspond to 0b00 for Rotate-Shift family>)
    {
        ...
        if(<check for 0b100: SLA> { ... }
        ...
        if(<Add your if condition here>) { ... }
        ...
    }
    ...
}

Note: Among the above nested, the final one is meant to throw an error to check if SLA (0b100) was not found as that was the only instruction implemented in the last commit. REMOVE THIS IF STATEMENT AND ADD YOURS AT THE END. Also make sure to use the variables already available unless necessary.

Reminders

  • Add (if) any new data members you create in the private section at the bottom of the CPU.h file. Avoid if not necessary as variables are already available.
  • Add any new member functions you create along with the other functions similar to them in the header file. For example, define any prefix related functions in the header file in the Prefix Instructions section.
  • No global/static variables unless there's a very good reason
  • Add only brief comments to clarify things if the code is not very intuitive or involves tricks, for other cases, try using long descriptive names for the variables instead so comments aren't very necessary.
  • Use camel case only for type/class/structure names and snake case for everything else.
  • Proper indentation xD

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions