Skip to content

An attempt to make a calculator in assembly with only bitwise arithmetic

License

Notifications You must be signed in to change notification settings

ImaginaryResources/x86-Calculator

Repository files navigation

x86-Calculator

An attempt to make a calculator with custom Arithmetic Instructions such as xor, and, shifts, and rotations and using the Irvine Library to read and write to the console

Bitwise operations will be created to add, subtract, multiply, and divide

I want to make as much as I can from scratch

Bitwise Addition: Assembly vs C++

Assembly

 A1:
      mov eax, input1          ;Store input1 to perform XOR
      xor eax, input2          ;Bitwise operation XOR performs 'add' 
      mov ebx, eax             ;'Add' xor to Sum

      mov eax, input1          ;Store input1 to preform AND
      and eax, input2          ;Bitwise operation AND shows which positions need a carry

      shl eax, 1               ;Shift left to check for carries

      mov input1, ebx          ;Store 'sum' into input1
      mov input2, eax          ;Store shifted carry into input2

      jnz A1                   ;If a carry still exist loop again
      
      ;final sum is stored in input1

C++

int addition(int input1, int input2) {
     while (input2 != 0) {                       //Loop until carry doesn't exist

          int xorStore = input1 ^ input2;        //Store result of xor operation from inputs
          int andStore = input1 & input2;        //Store result of and operation from inputs

          input1 = xorStore;                     //Store 'sum' into input1
          input2 = andStore << 1;                //Shift left to check for carries
     }
     return input1;                              //Return result stored in input1
}

Resources:

For Calculator_Irvine32.asm, builtin MASM using Irvine Library

For Calculator_MASM.asm, MASM

Understanding DOS Function Calls (int 21h)

Used to make UML comments: ASCII Flow

About

An attempt to make a calculator in assembly with only bitwise arithmetic

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published