xComputer Demonstration - Department of Computer and

Download Report

Transcript xComputer Demonstration - Department of Computer and

Department of Computer and Information Science,
School of Science, IUPUI
CSCI 230
Information Representation:
Machine Instructions Demo
Dale Roberts, Lecturer
IUPUI
[email protected]
Dale Roberts
xComputer Applet
xComputer applet – a java applet that simulates a simple
model computer (which is also called xComputer). The
model computer is discussed in Chapter 3 of The Most
Complex Machine. The xComputer consists of a Central
Processing Unit (CPU) and a main memory that holds
1024 sixteen-bit binary numbers. The CPU contains an
Arithmetic-Logic Unit (ALU) for performing basic
arithmetic and logical computations. It also contains
eight registers, which hold binary numbers that are
being used directly in the CPU's computations, a Control
circuit, which is responsible for supervising the
computations that the CPU performs, and a clock, which
drives the whole operation of the computer by turning
its single output wire on and off.
Dale Roberts
xComputer Instructions
xComputer uses 16 bits per instruction. 6 bits
are dedicated to the opcode, leaving 10 bits for
the operand.
The type of information stored in the operand is
dependent on the instruction being executed.
A listing of xComputer opcodes can be found at
http://www.cs.iupui.edu/~aharris/n301/xMachine.html.
The xComputer applet can be run from http://www.cs.iupui.edu/~aharris/n301/alg/tmcmjava-labs/labs/xComputerLab1.html.
Dale Roberts
Sample Opcodes
Code
Assembly Name
Add-to-AC
000000 ADD
Example Description
ADD 12 AC = AC + (12)
SUB 12
AND 12
AC = AC – (12)
Logical-OR-with-AC
OR 12
Bitwise OR with
(12)
000100 NOT
Logical-NOT-of-AC
NOT
Bitwise NOT of AC.
Parm ignored.
000101 SHL
000110 SHR
Shift-AC-Left
SHL
SHR
shift left 1 bit
000111 INC
001000 DEC
Increment-AC
INC
DEC
AC++
000001 SUB
000010 AND
Subtract-from-AC
000011 OR
Logical-AND-with-AC
Shift-AC-Right
Decrement-AC
Bitwise AND with
(12)
shift right 1 bit
AC--
(12) refers to the contents of address 12
Dale Roberts
Semantic Gap
Machine languages: Native tongue of a particular kind of computer.
Each
instruction is a binary string. The code is used to indicate operations to be
performed and the memory cells to be addressed. This form is the easiest form for
computers to understand, but is the most difficult for a person to understand.
Assembly languages:
Again, specific to one type of computer. Uses
descriptive names for operations and data, e.g. “LOAD value”, “ADD delta”, “Store
value”. Assemblers translate this to machine language. Intermediate level.
Somewhat descriptive, but basically follow the machine instructions.
High-level languages:
Write program instructions called statements that
resemble a limited version of English. e.g. “value = value + delta”. Portable,
meaning it can be used on different types of computers without modification.
Compilers translate them to machine languages. Example are Fortran, Pascal,
COBOL, C, C++, Basic, etc.
Semantic gap between statements in a high-level language and
machine/assembly language. Each high level statement may represent many
hundreds of machine instructions. Compilers must bridge this gap.
Complex machine instruction computer try to reduce this gap by
implementing high-level language opcodes. This diminishes the semantic gap but
makes the machine instructions more complex, and therefore makes the CPU
circuitry more complex.
Dale Roberts
Real-life Example: Pentium 4.
The instruction set information for the Pentium 4 process can be found at
ftp://download.intel.com/design/Pentium4/manuals/25366520.pdf.
Dale Roberts
Pentium 4 ADD
Description
Adds the first operand (destination operand) and the second operand
(source operand) and stores the result in the destination operand. The
destination operand can be a register or a memory location; the source
operand can be an immediate, a register, or a memory location.
(However, two memory operands cannot be used in one instruction.)
When an immediate value is used as an operand, it is sign-extended to
the length of the destination operand format. The ADD instruction
performs integer addition. It evaluates the result for both signed and
unsigned integer operands and sets the OF and CF flags to indicate a
carry (overflow) in the signed or unsigned result, respectively. The SF
flag indicates the sign of the signed result. This instruction can be used
with a LOCK prefix to allow the instruction to be executed atomically.
Operation
DEST ← DEST + SRC;
So you can see that the instructions are a little more complicated in real life than in
xComputer. But the same principles apply.
Dale Roberts
Pentium 4 Add (cont)
Dale Roberts
Acknowledgements
Several graphics and terms were obtained from Jonathan Michael Auld Central
Queensland University.
xComputer and its machine instructions were developed by David Eck.
Dale Roberts