Appendix C problem -- Machine Language Subtraction

  • Context: Comp Sci 
  • Thread starter Thread starter altoaviactus
  • Start date Start date
  • Tags Tags
    Language Machine
Click For Summary
SUMMARY

The discussion focuses on the implementation of subtraction using two's complement in machine language, specifically addressing the inversion of bits for the subtrahend. The participants highlight the importance of understanding the method of complements for effective subtraction in computer architecture. The conversation references John F. Wakerly's "Microcomputer Architecture and Programming" as a valuable resource for foundational knowledge. The use of registers and specific instructions, such as 5RST, is emphasized for practical application in machine language programming.

PREREQUISITES
  • Understanding of two's complement representation
  • Familiarity with machine language instructions
  • Knowledge of register operations in computer architecture
  • Basic concepts of binary arithmetic
NEXT STEPS
  • Study the method of complements for subtraction in binary systems
  • Learn about specific machine language instructions for bit manipulation
  • Explore the use of emulators for practicing machine language programming
  • Read John F. Wakerly's "Microcomputer Architecture and Programming" for deeper insights
USEFUL FOR

Students and professionals in computer science, particularly those interested in machine language programming, computer architecture, and binary arithmetic operations.

altoaviactus
Messages
1
Reaction score
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

Physics news on Phys.org
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:
Still here ?
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 20 ·
Replies
20
Views
4K