Question

All solutions must have both code and data segments Write a sequence of assembly language instructions...

All solutions must have both code and data segments

  1. Write a sequence of assembly language instructions to subtract each entry of an array B of five two’s complement 16-bit binary integers from the corresponding entry of an array A of five two’s complement 16-bit binary integers and construct a third array C of two’s complement 16-bit binary integers. i.e. C[i] = A[i] - B[i].

Use the following data for the arrays A and B.

            A: 10, -15, 20, 4, -5

            B: 25, -5, -30, 6, 10

2. Rewrite the assembly language instructions of question 1 for DEBUG environment.

3. Write a sequence of assembly language instructions to subtract 5 to each zero or positive entry and add 3 from each negative entry in an array A of 10 word two's complement binary integers.

Use the following data for array A: 6, 10, 25, -5, -30, 4, -5, 10, -15, 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class GFG
{
  
// Returns '0' for '1' and '1' for '0'
static char flip(char c)
{
return (c == '0') ? '1' : '0';
}
  
// Print 1's and 2's complement of binary number
// represented by "bin"
static void printOneAndTwosComplement(String bin)
{
int n = bin.length();
int i;
  
String ones = "", twos = "";
ones = twos = "";
  
// for ones complement flip every bit
for (i = 0; i < n; i++)
{
ones += flip(bin.charAt(i));
}
  
// for two's complement go from right to left in
// ones complement and if we get 1 make, we make
// them 0 and keep going left when we get first
// 0, make that 1 and go out of loop
twos = ones;
for (i = n - 1; i >= 0; i--)
{
if (ones.charAt(i) == '1')
{
twos = twos.substring(0, i) + '0' + twos.substring(i + 1);
}
else
{
twos = twos.substring(0, i) + '1' + twos.substring(i + 1);
break;
}
}
  
// If No break : all are 1 as in 111 or 11111;
// in such case, add extra 1 at beginning
if (i == -1)
{
twos = '1' + twos;
}
  
System.out.println("1's complement: " + ones);;
System.out.println("2's complement: " + twos);
}
  
// Driver code
public static void main(String[] args)
{
String bin = "1100";
printOneAndTwosComplement(bin);
}
}

Add a comment
Know the answer?
Add Answer to:
All solutions must have both code and data segments Write a sequence of assembly language instructions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT