# Calculate the two's complement of a given 16 bit number

• Comp Sci
Member warned that some effort must be shown
Homework Statement:
Machine Language
Relevant Equations:
Simpsim
I'm working on an assignment for a computer science course. The professor did not give very good instruction, and I can't find very much information about the subject online. We are supposed to use this http://www.anne-gert.nl/projects/simpsim/ program to perform various operations including adding, subtracting, multiplying, and dividing values. If I just had something to read or an example of how to use the program, it would be very helpful.

My Attempts:
1- Write an assembly program that calculates two’s complement of a given 16 bit number in 0000 0001
2- Modify your program so that it works for a 32bit number given in 0000 0001 0002 0003
3- Write an assembler program that computes the average of sixteen 8 bit numbers stored in memory and writes the result into 0000.

Thanks.

## Answers and Replies

phinds
Science Advisor
Gold Member
First, tell us what your understanding is of 2's complement and show an example of adding two 2's complement numbers so we can be sure you've gotten at least that far on your own

Mark44
Mentor
1- Write an assembly program that calculates two’s complement of a given 16 bit number in 0000 0001
What does 0000 0001 mean? Is it a binary number? If so, that's only 8 bits. Is it in hexadecimal? If so, that's 32 bits.
2- Modify your program so that it works for a 32bit number given in 0000 0001 0002 0003
The number you show can't be binary, but if it's hexadecimal, it's 64 bits, not 32.
3- Write an assembler program that computes the average of sixteen 8 bit numbers stored in memory and writes the result into 0000.
An 8-bit number would be ##b_7b_6b_5b_4 b_3b_2b_1b_0##, where each ##b_i## would be either 0 or 1. If 0000 represents a number in hex, that would be 16 bits; i.e., four bits for each hex digit.