Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 111 – Sept. 16 Machine language examples Instruction execution

Similar presentations


Presentation on theme: "CS 111 – Sept. 16 Machine language examples Instruction execution"— Presentation transcript:

1 CS 111 – Sept. 16 Machine language examples Instruction execution
Don’t memorize… Instruction execution Closer look at operations in instruction set Commitment: Please read sections 2.5 and 2.6. Quiz next Wednesday.

2 More instructions Opcode 1 is for loading a memory value into a register Expects a register operand (4 bits), and a memory address from which to load (8 bits). Ex means to go out to memory at address [20], grab the contents and load it into register 8. (It does not mean put the number 20 in register 8.) Opcode 3 is a store = opposite of load Ex means to take the value in register 9, and put it into memory at location [21]. (It does not mean put the number 9 into memory location 21.) Opcode C (hex code for 12) is for telling CPU it’s done. Expects operand to be 12 zero-bits.

3 Some practice Refer to appendix C…
How would we put the number 64 into memory at address 12? How would we add the numbers 6 and 8 and put the result in register 1? How would we add register 7 to register 5 and put the answer in memory at address 32? More examples: p. 91

4 Execution In our example, each instruction is 2 bytes long.
Program counter (PC) begins at address of first instruction. For each instruction: Fetch (and increment PC by 2) Decode Execute Examples pp Note that RAM contains both instructions and data, separated from each other. For example, addresses 0-99 could be reserved for code.

5 Logic operations Work just like gates, but we do several bits in parallel. Examples AND AND Try the same examples with “OR” and “XOR” Observations: What happens when you AND with a 1? With a 0? What about OR’ing with a 1 versus a 0? What about XOR?

6 Shift operations Given a bit pattern like , we can shift the bits left to obtain: If we shift to the right instead, becomes this: We can even shift by more than one position. Shifting by 3 bits right  Sometimes when we shift, 1’s fall off the edge. Shifting by 2 bits left  When we shift, the “vacated” bits are usually 0.

7 Why shift? One application of a shift operation is to:
Multiply by 2: left shift Divide by 2: right shift Try some examples – should look familiar with our earlier work on binary numbers. One funny exception: dividing a (signed) negative number by 2. In this case, we want the vacated bit to be 1 Example: –12 in signed is If we shift right by 1, we get , but it should be this:

8 Rotate Rotate operations work the same as shift… except that the vacated bits come from the other end of the number. So, instead of 1’s falling off the edge, they rotate. For example, rotated left by 2 becomes Also: rotated right by 3 becomes: Examples pp


Download ppt "CS 111 – Sept. 16 Machine language examples Instruction execution"

Similar presentations


Ads by Google