Appendix C problem -- Machine Language Subtraction

In summary, the conversation discusses the topic of two's complement and how to invert a number in this representation. The main issue is figuring out which instruction(s) would be useful for a given register. The use of textbooks and lecture notes is highlighted as a helpful tool in understanding this concept.
  • #1
altoaviactus
1
0
Homework Statement
This is the application that we have to use https://joeledstrom.github.io/brookshear-emu/ . I am attempting to subtract 16-15. The instruction set is also attached. I'm not very good at 2's complement, but I am trying to figure this out. Addition is much easier and straightforward, but I can't seem to make a good algorithm to make a negative converter. Here are the questions: 1. Using the model CPU demonstrated in class, write code using the simple machine language of Appendix C to solve the following problem: 16 - 15. Store the result in memory location F0.
2.Using the model CPU demonstrated in class, write code using the simple machine language of Appendix C to solve the following problem: 9 + 27 – 16. Store the result in memory location FF.
I think I only need help on one as I could figure out the other from it.
Relevant Equations
1 RXY LOAD register R with the contents of the memory cell at address XY.

2 RXY LOAD register R with the value XY.
3 RXY STORE the contents of register R at memory location XY.
4 0RS MOVE the contents of register R to register S.
5 RST ADD the integer contents of registers S and T and leave the result
in register R. Integers are stored using two's complement notation.

6 RST ADD the floating-point contents of registers S and T and leave the
result in register R.

7 RST OR the contents of registers S and T and place the result in register R.
8 RST AND the contents of registers S and T and place the result in register R.
9 RST EXCLUSIVE OR the contents of registers S and T and leave the result in register R.
A R0X ROTATE the contents of register R one bit to the right X times.
B RXY JUMP to the instruction located at memory address XY if the
contents of register R equals that of register 0.

C 000 HALT
2010
210F
Can only get this far without running into issues
 

Attachments

  • Machine Language.pdf
    46.7 KB · Views: 392
Physics news on Phys.org
  • #2
Hello @altoaviactus ,
:welcome: !​
altoaviactus said:
Can only get this far without running into issues
That's not very far :wink: . At this point you have decimal 16 in register 0 and 15 in register one. Time for some action.
The first issue in question being "How to invert a number in two's complement" -- right ?

Because you studied the two's complement in your textbook or wiki lemma and under "subtraction" were referred to method of complements and there, under practical uses in computers you finally found what to do:
wiki said:
  • If two's complement representation is used, subtraction requires only inverting the bits of the subtrahend and setting a carry into the rightmost bit.
(you can really see the usefulness of textbooks and lecture notes from this: everything is presented in context on a silver platter and you don't have to hop from one huge page to another. Unfortunately I don't have your textbook, just John F Wakerly, Microcomputer architecture and programming from 1981 :biggrin:).

So: which instruction(s) might be useful for register 1 ?
You have 0F sitting there and want something else. Something that you can add to the contents of register 0 using 5RST

[edit] I played with the emulator and had endless fun! I really envy nowadays students for having such nice toys !

##\ ##
 
Last edited:
  • #3
Still here ?
 

FAQ: Appendix C problem -- Machine Language Subtraction

What is "Appendix C problem -- Machine Language Subtraction"?

"Appendix C problem -- Machine Language Subtraction" is a problem that is commonly found in computer science textbooks and assignments. It involves writing a program in machine language to perform subtraction operations on two numbers.

What is machine language?

Machine language is the lowest level of programming language that is directly understood by a computer's central processing unit (CPU). It consists of binary code, which is a series of 0s and 1s that represent specific instructions for the computer to execute.

Why is subtraction important in machine language?

Subtraction is an important operation in machine language because it is a fundamental mathematical operation that is used in many different programs and algorithms. It is also essential for performing more complex operations, such as division and square roots.

What is the process for writing a machine language subtraction program?

The process for writing a machine language subtraction program involves understanding the binary code for the subtraction instruction, identifying the memory locations of the numbers to be subtracted, and using the appropriate commands to perform the subtraction and store the result in a designated memory location.

Is machine language subtraction still relevant in modern computing?

Yes, machine language subtraction is still relevant in modern computing. While it may not be used directly by programmers, it is the foundation of all other programming languages and is still used by computer hardware to execute instructions. Additionally, understanding machine language can help programmers write more efficient and optimized code.

Similar threads

Replies
17
Views
1K
Replies
6
Views
2K
Replies
4
Views
2K
Replies
1
Views
9K
Replies
1
Views
1K
Replies
2
Views
2K
Replies
20
Views
3K
Back
Top