Appendix C problem -- Machine Language Subtraction

  • #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: 399
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 ?
 

Similar threads

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