C7
1. Write an algorithm to implement the subtraction operation for two positive
integers in assembly language.
1.
2.
3.
4.
Let the numbers be A, B and the operation be A-B
Convert A into binary
Convert B into binary
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.
; Program name
;Programmer
;Last Modified
load
load
load
load
xor
addi
addi
halt
: Subtraction using add only
: Joe B
: Sep 16 2003
R1,1
;1 added for computing 2's complement
R2,FFh
;mask for flipping the bits
R3,first_number;
R4, second_number;
R5, R4,R2
; flip the 0's and 1's in the second number
R5,R5,R1
; add 1 to the flipped bits to get the 2's complement
R5,R5,R3
; add the numbers to obtain A - B
first_number:
second_number:
db 8
db 5
;A in A-B
;B in A-B
C7 Solutions
of 1
Report
Tell us what’s wrong with it:
Thanks, got it!
We will moderate it soon!
Free up your schedule!
Our EduBirdie Experts Are Here for You 24/7! Just fill out a form and let us know how we can assist you.
Take 5 seconds to unlock
Enter your email below and get instant access to your document