K Hinds 2018 www.kumarhinds.net Page 1

HEX to Conversion e.g.: Convert C0DE to Decimal

Hexadecimal Digit Notes These values are statically assigned, they Digit Positions (n) 3 2 1 0 grow to the left. This part's easy, plug your hex values in Hex Digits Sorted C 0 D E from right-to-left. Convert A-F 12 0 13 14 Convert hex values A-F to 10-15. Multiply by 16n 12 × 163 0 × 162 13 × 161 14 × 160 The exponent of 16 is the position, n. The product of hex digit and the power of Resulting Products 49152 0 208 14 16. Sum Up All 49374 Our decimal equivalent! Products

Computer Organization

The Central Processing Unit (CPU) is also known as the microprocessor or processor. The processor contains three sections called the Arithmetic Logic Unit (ALU), the Control Unit and Registers.

K Hinds 2018 www.kumarhinds.net Page 2

Random Access Memory (RAM) Read Only Memory (ROM) Definition Random Access Memory or RAM is a Read-only memory or ROM is also a form form of data storage that can be of data storage that can not be easily altered accessed randomly at any time, in any or reprogrammed. Stores instructions that order and from any physical location., are not necessary for re-booting up to make allowing quick access and the operate when it is switched manipulation. off. They are hardwired. Use RAM allows the computer to ROM stores the program required to read data quickly to run applications. It initially boot the computer. It only allows allows reading and writing. reading. Volatility RAM is volatile i.e. its contents are lost It is non-volatile i.e. its contents are retained when the device is powered off. even when the device is powered off. Types The two main types of RAM are static The types of ROM include PROM, EPROM RAM and dynamic RAM. and EEPROM. Control unit: The Control Unit makes decisions and sends the appropriate signal down its lines to other parts of the computer. It controls the timing of operations in the computer and controls the instructions sent to the processor and the peripheral devices. Arithmetic/logic unit (ALU): The ALU carries out arithmetic and logic functions. It carries out all the calculations and makes decisions on the data sent to the processor.

CPU Registers/Memory

Registers are lightning fast computer memory used to speed the execution of computer programs by providing quick access to stored values during program execution. These registers are the top of the memory hierarchy and are the fastest way for the system to manipulate data. They can drive their data onto an internal bus in a single clock cycle. The result of ALU operation is stored here and could be re-used in a subsequent operation or saved into memory. Registers are normally measured by the number of they can hold, for example, an “8- register” or a “32-bit register”. There are several other classes of registers:

 Accumulator: It is most frequently used register used to store data taken from memory. Its number varies from microprocessor to microprocessor.  General Purpose registers: General purpose registers are used to store data and intermediate results during program execution. Its contents can be accessed through assembly programming.  Special purpose Registers: Users do not access these registers. These are used by computer system at the time of program execution. Some types of special purpose registers are given below:  Instruction Register (IR): IR holds the instruction currently being executed or decoded. When one instruction is completed, next instruction is fetched in memory for processing.  Program Counter (PC): The program counter, PC, is a special-purpose register that is used by the processor to hold the address of the next instruction to be executed. The PC is continually updated to point to the next instruction during the op-code decode cycle.

K Hinds 2018 www.kumarhinds.net Page 3

Fetch-decode-execute cycle The main job of the CPU is to execute programs using the fetch-decode-execute cycle (also known as the instruction cycle). This cycle begins as soon as you turn on a computer. To execute a program, the program code is copied from Secondary Storage into Primary Memory. The CPU's PC is set to the memory location where the first instruction in the program has been stored, and execution begins. The program is now running.

In a program, each machine code instruction takes up a slot in the main memory. These slots (or memory locations) each have a unique . The PC stores the address of each instruction and tells the CPU in what order they should be carried out. When a program is being executed, the CPU performs the fetch-decode-execute cycle, which repeats repeatedly until reaching the STOP instruction.

Summary of the fetch-decode-execute cycle

1. The processor checks the PC to see which instruction to run next. 2. The PC gives an address value in the memory of where the next instruction is. 3. The processor fetches the instruction value from this memory location. 4. Once the instruction has been fetched, it is stored in the IR and it needs to be decoded and executed. For example, this could involve taking one value, putting it into the ALU, then taking a different value from a register and adding the two together. 5. Once this is complete, the processor goes back to the PC to find the next instruction to load into the IR. 6. This cycle is repeated until the program ends.

K Hinds 2018 www.kumarhinds.net Page 4

Data Manipulation Data manipulation involves transferring data and operating on data with math Functions, data conversion, data comparison and logical operations. Each instruction requires two or more words of data memory for operation. The words of data memory are referred to as Registers.

Input/Output

The instruction copies data from a source word to a destination word and vice versa. Data transfer instructions involve the transfer of the contents from one word to another. Data transfer instructions are Output instructions. The MOVE instruction is used to copy the value in one word to another word. Conversely, the LOAD instruction inputs information to a register for processing

Input/Output, Arithmetic & Logic commands can be summarized as follows:

 LOAD (Input) – Loads in a value to main memory  MOV (Move) —Moves the source value to the destination.  AND (And) —Performs a bitwise AND operation.  OR (Or) —Performs a bitwise OR operation.  NOT (Not) —Performs a bitwise NOT operation.  ADD -  MUL -  SUB -

Instruction Length – Fixed & Variable

Fixed Length: On some machines, all instructions have the same length; Having all the instructions be the same length is simpler and make decoding easier but often wastes space

Variable Length: On others there may be many different lengths based on the operation required; so, the Opcode and the Operand is varied. This method wastes less space and is more efficient, however they are more difficult to decode.

Instruction Format

Instructions are decoded as a set of sequenced Operations. These operations instruct the ALU and Control Unit inside the CPU. Operations consist of a set of instructions and data. Operations are made up of Opcodes and Operands. The opcode performs an action on an operand.

K Hinds 2018 www.kumarhinds.net Page 5

Opcode The opcode tells the processor the job that needs to be done. A simple operation might be 'ADD', ‘MUL’ or 'SUB'. If we use the analogy of a recipe, the opcode might be 'chop' or 'mix'. Each opcode instruction is very limited in what it can tell the processor to do. A CPU's instruction set contains the opcodes that it will accept. There are two types of opcode:

1. An opcode that tells the circuitry which operation to carry out. E.g. POP, PUSH, ADD, SUB, MUL, MOD, DIV, LOAD

2. An opcode along with some data to be processed: e.g. ADD A,B; LOAD A

Zero, One, Two and Three Address Instruction Computer perform task on the basis of instruction provided. An instruction in computer comprises of groups called fields. These field contains different information and depending on the computer – or x64 architecture, everything is in 0 and 1; so each field has different significance on the basis of what a CPU decide to perform. Most machines however have similar instructions sets – instruction sets tell the CPU what to do: ADD, SUB, MOVE, LOAD, etc. An instruction format defines the layout of the bits of an instruction, in terms of its separate parts (Zero, One, two or Three). An instruction format must include an opcode and, implicitly or explicitly, zero or more operands. Typical operations in a computer system may either Infix, Prefix and Postfix Expressions Infix With an arithmetic expression such as B * C, the form of the expression states that variable B is being multiplied by the variable C, since the multiplication operator * appears between them. This type of notation is referred to as infix since the operator is in between the two operands. Order of Operations Consider an infix example, A + B * C. The operators + and * still appear between the operands, each operator has a precedence level. Operators of higher precedence are used before operators of lower precedence. The only thing that can change that order is the presence of parentheses. The precedence order for arithmetic operators’ places multiplication and division above and subtraction. If two operators of equal precedence appear, then a left-to-right ordering or associativity is used. Prefix Consider the infix expression A + B. What would happen if we moved the operator before the two operands? The resulting expression would be + A B. Prefix expression notation requires that all operators precede the two operands that they work on: A + B * C would be written as + A * B C in prefix. The multiplication operator comes immediately before the operands B and C, denoting that * has precedence over +. The addition operator then appears before the A and the result of the multiplication. K Hinds 2018 www.kumarhinds.net Page 6

Postfix Consider the infix expression A + B. If we move the operator to the end, we would get A B +. Postfix requires that its operators come after the corresponding operands. In postfix, the expression A + B * C would be written as: A B C * + Again, the order of operations is preserved since the * appears immediately after the B and the C, denoting that * has precedence, with + coming after. Although the operators moved and now appear either before or after their respective operands, the order of the operands stayed the same relative to one another. Infix Expression Prefix Expression Postfix Expression A + B + A B A B + A + B * C + A * B C A B C * +

Zero Address Instruction Infix: X = (A + B) * (C + D) With Zero address instructions, we are specifically operating with stack operations. As such we cannot pass large arguments inside a register to the CPU. Infact, we are very limited in the operations we can perform at any given time. All operations using Zero address instructions must be written in Post fix notation: [Note: respect the brackets] X = (AB+) (CD+)* OPCODE Operand (Data) POP

MUL PUSH A This is the stack. PUSH B D Think of it as a long ADD list with the operations C at the bottom executed PUSH C first. First-In-Last-Out PUSH D ADD ADD B MUL A POP

K Hinds 2018 www.kumarhinds.net Page 7

One Address Instruction Infix: X = (A + B) * (C + D) This instruction format uses a special purpose register called the ACCUMULATOR for data manipulation. One operand of an instruction is in the accumulator (AC) and other is in a register or memory location M[x]. The CPU already know that one operand is in accumulator so there is no need to specify it. We push the Accumulator contents to memory stores after each operation. NOTE: we leave the expression in INFIX notation.

OPCODE Operand/Address of Operand Mode

Description LOAD A AC = M[A]; load A into Accumulator ADD B AC = A[C] + M[B]; Add B to Accumulator STORE T M[T] = AC; Store Accumulator contents to another location T LOAD C AC = M[C]; Push C into Accumulator ADD D AC = AC + M[D]; Add D to Accumulator MUL T AC = AC * M[T]; Multiply Accumulator with Memory store T STORE X M[X] = AC; Push Accumulator to Memory location X Two Address Instruction Infix: X = (A + B) * (C + D) Two address can be specified in the instruction. Unlike earlier in one address instruction the result was stored in accumulator, here the result can be stored at different location rather than just the accumulator but require more bits to represent addresses.

NOTE: Destination address can also contain operand and we use INFIX notation OPCODE field specifies the OPCODE Destination Address Source Address Mode operation to be performed like ADD, SUB, etc. Description MOV R1, A R1 = M[A]; Load A into Register R1 – Save result to R1 Address field ADD R1, B R1 = R1 + M[B]; Add B to R1- Save result to R1 contain the MOV R2, C R2 = C; Load C into R2- Save result to R2 location of ADD R2, D R2 = R2 + D; Add D to R2- Save result to R2 operand, i.e., MUL R1, R2 R1 = R1 * R2; Multiply R1 and R2- Save result to R1 register or MOV X, R1 M[X] = R1; Move R1 into X - Save result to X memory location.

Mode field specifies how operand is to be

found.

K Hinds 2018 www.kumarhinds.net Page 8

Three Address Instruction Infix: X = (A + B) * (C + D) This has three address fields to specify a register or a memory location. Programs created are much short in size but number of bits per instruction increase. These instructions make creation of program much easier, but it does not mean that program will run much faster because now instruction only contain more information but each micro operation (changing content of register, loading address in address bus etc.) will be performed in one cycle only. Destination OPCODE Source Address Source Address Mode Address

Description ADD R1, A, B R1 = M[A] + M[B]; Add A and B, save to R1 ADD R2, C, D R2 = M[C] + M[D]; Add C and D, save R2 MUL X, R1, R2 M[X] = R1 * R2; Multiply R1 and R2, save to X

Processor Capacity (Word Size)

Capacity refers to the number of bits that a CPU can process at one time. Processors with many different word sizes have existed though powers of two (8, 16, 32 and 64 bits) have predominated for many years. A processor's word size is often equal to the width of its external data bus. Today the 32- and 64-bit word sizes are the standard instruction sets for issuing a single instruction to a CPU.

Multi-Core Processors

A multi-core processor is a single computing component with two or more independent actual processing units (called "cores"), which are the units that read and execute program instructions. The instructions are ordinary CPU instructions such as add, move data, and branch, but the multiple cores can run multiple instructions at the same time, increasing overall speed for programs. Processors are made as duo core, quad core and recently as octal core.

Processor Cache (Processor Memory) Most processors today need an Immediate Access Store (Primary Memory) located within or on the CPU for direct access to instructions at high access and response speeds. To facilitate this memory, processors carry Cache memory. L1 and L2 are levels of cache memory in a computer. If the computer processor can find the data it needs for its next operation in cache memory, it will save time compared to having to get it from random access memory. L1 is K Hinds 2018 www.kumarhinds.net Page 9

"level-1" cache memory, usually built onto the microprocessor chip itself. For example, the Intel MMX microprocessor comes with 32 thousand of L1. L2 or L3 (that is, level-2 or level -3) cache memory is on a separate chip (possibly on an expansion card) that can be accessed more quickly than the larger "main" memory. A popular L2 cache memory size is 1,024 kilobytes (one megabyte). Clock Speed This is the number of pulses per second generated by an oscillator inside the processor. Clock speed is usually measured in MHz (megahertz, or millions of pulses per second) or GHz (gigahertz, or billions of pulses per second). Some processors execute only one instruction per clock pulse. More advanced processors can perform more than one instruction per clock pulse. The latter type of processor will work faster at a given clock speed than the former type. The clock speed is determined by a quartz-crystal circuit, similar to those used in radio communications equipment. Access Methods and Access Speed Access speed is a measure of how fast the data can be transferred from one point to another in a computer. For example, the access speed of L1 cache is very much faster than L2 cache, which is faster than RAM – which is faster than the HDD. Access Methods refer to the way information is read from memory. The two types of Access Methods used today are Sequential and Direct/Random access. Magnetic tapes are sequential access media because their information must be read from beginning to the point the user requests. [Imagine seeing the cool part of Barney or Teletubbies that you like above all else at 1 hour 20 minutes; you would have to fast forward from the tapes current position that point] Conversely, direct access allows direct access to the data stored on a memory device. Flash drives, CD’s and HDD are directly accessed. [This time, you do not have to fast forward to see Barney or Teletubbies; you can just skip to it! You are now the cool dude/dudette on the block. Go forth and achieve greatness]

Please turn over for CSEC CAPE Computer Science Past Paper Question

K Hinds 2018 www.kumarhinds.net Page 10

Exercise : Question No.1

Question No.2

K Hinds 2018 www.kumarhinds.net Page 11

Question No.3

Question No.4