Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Numbers

CISC 221 - Assignment 2

Due: February 3, 2023, 11:59pm

Part A

Twos complement encoding (3 marks)

•    Implement a C function with the following prototype

o  int subtract2sc_issafe(int x, int y)

which returns 1 when computing two’s complement subtraction does not cause overflow, and returns 0 otherwise.

•    Do not assume width of type int; you should use sizeof(int) to find out instead.

•    You will need to write your own main() function to test your code, but do not submit main().

•    Submit the single file twoscomplement_aux .c.

o  Ensure that your source code is well-documented and readable.

o Make sure it is tested on the CASLab machines.

Part B

Meditate

(Not submitted)

1.     (Page 88, 3ed) Principle: detecting overflow of unsigned addition

2.   (Page 92, 3ed) Principle: detecting overflow in twos complement addition

Short answer questions

(Submitted as a single PDF file, a2_b .pdf.)

1.    (1 mark) Encode the following decimal numbers with 8-bit two’s complement binary, or indicate that number would overflow the range:

a.    4910

b.   –3110

c.    12010

d.   – 12810

e.   12810

2.   (2 marks, page 140 of CSAPP 3ed) Homework problem 2.91

 

Deliverables

To OnQ:

1.    twoscomplement_aux.c, and

2.   a2_b.pdf