Question

In: Computer Science

In a language of your own choosing, write a computer program that implements the Restoring Twos...

In a language of your own choosing, write a computer program that implements the Restoring Twos Complement Division process. In addition to program source code, provide a screenshot showing the tasks below. Use 8 bits for all registers.

  1. Provide an output that shows your input decimal values.
  1. Provide an output that shows the initial values in registers A, Q, and M.
  1. Demonstrate that your program works in the following cases by showing the output in registers A and Q after the final cycle and the final value in 2s complement for negative numbers:
    1. divide two positive numbers with no remainder
    1. divide two positive numbers with a remainder
      1. divide two negative numbers with no remainder
      1. divide two negative numbers with a remainder
      1. divide a positive number by a negative number with a remainder
      1. divide a positive number by a negative number without a remainder
      1. divide a negative number by a positive number with a remainder
      1. divide a negative number by a positive number without a remainder
  1. Show the output of your result in decimal format yRx where y is the integer value and x is the remainder value. e.g. 4R0 would be 4 with a remainder of 0, -4R-2 would be -4 with a remainder of -2.

Solutions

Expert Solution

Program in C

#include<stdio.h>
#include<stdlib.h>

void division(char x, char y)
{
register char A, M, Q;

unsigned char t, s, r;

int i;

Q = x;
M = y;
A = 0;

//display initial values in A, Q and M
printf("Initially: A = %d Q = %d M = %d\n", A, Q, M);

Q = abs(x);
M = abs(y);

r = sizeof(char)*8;

t = 1 << (r-1);

for(i=0; i < r; i++)
{
//shift left AQ
A = A <<1;
s = Q & t;
s = s >> (r-1);
Q = Q << 1;
A = A | s;

//A = A -M
A = A - M;

//MSB of A
s = A & t;
s = s >> (r-1);

//check MSB
if(s==0)
//Q[0] = 1
Q = Q | 1;
else
{
//Q[0] = 0
Q = Q | 0;
//restore A
A = A + M;
}
}
if(x<0) A = ~A + 1;

if(x<0 && y>0 || x>0 && y<0) Q = ~Q + 1;


//display Quotient and Remainder
printf("Quotient = %d\t", Q);
printf("Remainder = %d\n", A);

printf("%dR%d\n", Q, A);

}

int main()
{
int a, b;

//a. divide two positive numbers with no remainder
printf("divide two positive numbers with no remainder\n");
a = 8; b = 4;
division(a, b);

//b. divide two positive numbers with a remainder
printf("divide two positive numbers with a remainder\n");
a = 8; b = 3;
division(a, b);

//c. divide two negative numbers with no remainder
printf("divide two negative numbers with no remainder\n");
a = -8; b = -4;
division(a, b);

//d. divide two negative numbers with a remainder
printf("divide two negative numbers with a remainder\n");
a = -8; b = -3;
division(a, b);

//e. divide a positive number by a negative number with a remainder
printf("divide a positive number by a negative number with a remainder\n");
a = 8; b = -3;
division(a, b);

//f. divide a positive number by a negative number without a remainder
printf("divide a positive number by a negative number with a remainder\n");
a = 8; b = -4;
division(a, b);

//g. divide a negative number by a positive number with a remainder
printf("divide a negative number by a positive number with a remainder\n");
a = -8; b = 3;
division(a, b);

//h. divide a negative number by a positive number without a remainder
printf("divide a negative number by a positive number without a remainder\n");
a = -8; b = 4;
division(a, b);
}

Output:


Related Solutions

In a language of your own choosing, write a computer program that takes as input a...
In a language of your own choosing, write a computer program that takes as input a decimal (base 10) floating point number, and converts this number into a binary floating-point representation. The binary floating-point representation should consist of 1 bit for the sign of the significand; 8 bits for the biased exponent; and 23 bits for the significand. In addition to program source code, provide a screenshot showing the tasks identified below. Provide an output that shows your input decimal...
Write an assembly language program that will print out the message of your choosing #NOTE #write...
Write an assembly language program that will print out the message of your choosing #NOTE #write in a simple way, so that i can execute it from command window using masm
Write a program in C language that implements the logic of Binary Trees with the following...
Write a program in C language that implements the logic of Binary Trees with the following requirements: 1- Elements of the tree should be read from the user. 2- Keep the binary tree heigh-balanced that is the absloute value of ((hight of left sub-tree) - ( height of right sub-tree)) should not be greater than 1. If so, then the binary tree is no longer balanced. Hint: The best approach is to maintain balance during insertion. *Remember, we are talking...
Write an MSP430 assembly language program that implements the following algorithm: a macro called "vdot" that...
Write an MSP430 assembly language program that implements the following algorithm: a macro called "vdot" that calculates the "dot product" of two vectors "a" and "b", implemented as “arrays” (following the “C” language convention), of 3 elements. the macro should receive 2 pointers to the first element of each vector and return the result in R13. I have another file where I save my vectors called, "vars.c" here I save: int a[] = { 14, 65, 9} int b[] =...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called 'numadd' that...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called 'numadd' that sums up all the numeric characters present in a phrase ("string" that follows the "C" language convention). By For example, if the phrase is "Today is the 28th of month 9", the subroutine must perform the following sum: 2 + 8 + 9 = 19. The subroutine must receive the address of the first character of the corresponding phrase in the "stack", and return...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called ‘numadd’ that...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called ‘numadd’ that sums up all the numeric characters present in a sentence (“string” that follows the “C” language convention). For example, if the phrase is "Today is the 21st of month 5", the subroutine must perform the following sum: 2 + 1 + 5 = 8. The subroutine must receive the address of the first character of the corresponding phrase in the " stack ”, and...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called "vdot" that calculates the "dot product" of two vectors "a" and "b", implemented as “arrays” (following the “C” language convention), of 3 elements. the macro should receive 2 pointers to the first element of each vector and return the result in R13.
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x +...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x + y – z + A[j] x and y should be in reserved memory words using the .word directive and labeled as x and y. Initialize x=10 and y=200. Read in z from the console. Input the value -8. This is the value for z, not for –z. Store this value in memory with the label z. To begin, you could just initialize z to...
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS...
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will generate a random series of 50 requests and service them according to each of the algorithms you chose. The program will be passed the initial position of the disk head as a parameter on the command line and report the total amount of head...
Write a program in C++ that efficiently implements a skip list that holds integers. Your program...
Write a program in C++ that efficiently implements a skip list that holds integers. Your program should: 1. Accurately implement the skip list ADT using a random number generator and nodes that contain an integer as well as the addresses of adjacent nodes to the left, right, up, and down. 2. Correctly implement the Insert, Search, and Delete operations. 3. Read a series of unique, newline-delineated integers from a file and insert them (one at a time in the order...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT