{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

c07_ps03_sol - Program name Subtraction using add...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
C7 1. Write an algorithm to implement the subtraction operation for two positive integers in assembly language. 1. Let the numbers be A, B and the operation be A-B 2. Convert A into binary 3. Convert B into binary 4. Compute 2’s complement of B i. Invert the bits in B using B xor 11111111 ii. Add 1 to B 5. Add A and the 2’s complement of B. 2. Implement your algorithm in the assembly language describe in the machine language handout. Test your implementation using the SimpleSim simulator.
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ; Program name : Subtraction using add only ;Programmer : Joe B ;Last Modified : Sep 16 2003 load R1, 1 ;1 added for computing 2's complement load R2, FFh ;mask for flipping the bits load R3,first_number ; load R4, second_number ; xor R5, R4,R2 ; flip the 0's and 1's in the second number addi R5,R5,R1 ; add 1 to the flipped bits to get the 2's complement addi R5,R5,R3 ; add the numbers to obtain A - B halt first_number: db 8 ;A in A-B second_number: db 5 ;B in A-B...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern