210 likes | 369 Views
C OMPUTER ARCHITE C T U R E ( Simulation at algorithm level using SMALL). Assoc.Prof . Stasys Maciulevičius C omputer Dept . sta sys @ ecdl .lt. S. A. 1 2 6. Algorit h m description (an example).
E N D
COMPUTER ARCHITECTURE(Simulation at algorithm level using SMALL) Assoc.Prof. Stasys Maciulevičius Computer Dept. stasys@ecdl.lt
S A 1 2 6 Algorithm description(an example) • Suppose we want to describe astructurefor multiplication of positive integersat algorithm level • Operandsare 6 bit long, integer number’s format is: • S – sign bit,A – value field (5 bits) S.Maciulevičius
Multiplication using shift of multiplicand (from lsb) • Let us multiply the integers25 and 19: 25 × 19 = 475 • In binary system: 0.11001× 0.10011 = 0.0111011011 • Manual multiplication looks so: 0.11001 × 0.10011 011001 011001 011001 0111011011 S.Maciulevičius
Multiplication using shift of multiplicand (from lsb) • We start multiplicationfrom least significant bits and use shift of multiplier (B) • Therefore, we expand the multiplicand (A) to double length adding zeros on the left: A B 0.0000011001 0.10011 S.Maciulevičius
Multiplication using shift of multiplicand (from lsb) A B C0.0000011001 0.10011 0.0000000000 +0.00000110010.0000110010 0.01001 0.0000011001 +0.00001100100.0001100100 0.00100 0.00010010110.0011001000 0.00010 0.00010010110.0110010000 0.00001 0.0001001011 +0.01100100000.1100100000 0.00000 0.0111011011 S.Maciulevičius
Multiplication using shift of multiplicand (from lsb) • You see, we shift the multiplicand(A) to left, and multiplier (B)– to right (by one bit at time) • If the least significant bitof B is 1, the multiplier (A) should be the added to partial sum of products (C) • Cycle is carried out as many times as multiplier length is (5 in our case) • We use 3 bit cycles counter S.Maciulevičius
Multiplication using shift of multiplicand (from lower bits) • Considering these circumstances, we have such an algorithm: • Input the multiplicand and multiplier values • Clear partial sum of products and set cycle counter to 5 • Check the lsb of multiplier. If it is equal to 1, add multiplicand(A) to the partial sum of products (C) • Shift multiplicand to the left, and the multiplier (B) – to the right • Decrease cycle counter. If the counter unequal to zero, return back tostep 3 • End S.Maciulevičius
Small • We will use a simple, similar to C, a hardware description language Small • Key elements of Small will be presented using examples in next slides S.Maciulevičius
Small – numbers and names • Numbers: 181d =10110101 = 0B5h Binary numbersare presented without indicator of number system • Names: A, A1, a1. Namesare case-sensitive • First symbol of reserved words (excluding if) is capital letter: Reg, Cnt S.Maciulevičius
Small - declarations • Types of structure elements: Reg - register, Cnt - counter, Trg - trigger, Examples: • RegA[8], B[8], c[16], z[1];- here are 8 bit registersAandB, 16 bit register cand 1 bit register z (equivalent to Trgz;) declared • CntSk[3]; - hereis3bit counterSk (it cancount from 0 to 7 orvice versa) declared S.Maciulevičius
Small - variables • Examples of variables (they are declared as above): • A- 8 bit register A (whole) • A[8] - 8’thbitof register A • B[5:8] – four rightbits of register B • A.B - word composed using concatenation of registers Aand B (complex variable) S.Maciulevičius
Small - expressions • Logic operations: & - AND, | - OR, # - EXOR • Examples of expressions (variables are declared as above): • A + B- sum of two 8 bit registersAandB • c[1:8] + A - Ais added to higher partof register c • c[1:8] + ^A + 1 - (-A)is added to higher partof register c (using two’s complement code) • A|B - OR (logical sum) of 8 bit registersAandB • A[1] #B[1] - EXOR (sum module 2) offirst bits (sign bits) of registersAandB S.Maciulevičius
Small - shifts • Shift operators: RLS - log. shiftto right, LLS - log. shiftto left, RCS – rotating to right, LCS - rotating to left, RAS - arithmeticshiftto right • Examples of shift operations (variables are declared as above): • RLS(A)orA = 0.A[1:7] - logicalshiftto right of register’sAcontent • LLS(A.B)orA.B = A[2:8].B.0 - logicalshiftof registers’AandB contents to left, when higherBbit will be “inserted” intoA S.Maciulevičius
Small - conditional statements • Syntaxof conditional statements: < conditional operator> ::= if <logicexpression> { < list of operators> } [ELSE { < list of operators> } ] • Example of conditional statement: if b[6]==1 { c=c+a; } S.Maciulevičius
Small • Every statementends by a semicolon (;) • Don’t write a semicolon after BEGIN, END! • Basicwords and standardnames are not case-sensitive • Names of structure elementsshould be writtenso, as they were declared (they are case-sensitive) S.Maciulevičius
Multiplication algorithm in Small • This multiplication algorithm can be presented asdescription of multiplicationunit: UnitMultiplication; Reg a[11], c[11]; Reg b[6]; Cnt sk[3]; Begin a=input; b=input; Print a,b; sk=5d; Print “Start of Cycle"; S.Maciulevičius
Multiplication algorithm in Small • Continued: Loop: if b[6]==1 { c=c+a; } a = LLS(a); b = RLS(b); sk = sk-1; Print sk, a, c; if sk<>0 { GotoLoop; } Print c; End S.Maciulevičius
Small window S.Maciulevičius
Simulation using Small2W • When you click Run, program ask to enter operands: S.Maciulevičius
Simulation using Small2W • Simulation protocol: Unit Multiplication a[1:11]=00000011001 b[1:6]=010011 "Start of Loop" sk[1:3]=100 a[1:11]=00000110010 c[1:11]=00000011001 sk[1:3]=011 a[1:11]=00001100100 c[1:11]=00001001011 sk[1:3]=010 a[1:11]=00011001000 c[1:11]=00001001011 sk[1:3]=001 a[1:11]=00110010000 c[1:11]=00001001011 sk[1:3]=000 a[1:11]=01100100000 c[1:11]=00111011011 c[1:11]=00111011011 • ResultC = 00111011011 = 475 S.Maciulevičius
Simulation using Small2W • Program checks, if a carry out will be generated. If it can be ignored, you can do in such a way: descibe one bit length register and write this carry into this register • For instance: c=c+a produces such result: c[1:8]=11100111 a[1:8]=11001100 Calculation result is too big to save it to `c` at line 27 Then we can improve our program in following way: Reg x[1]; x.c = c + a; S.Maciulevičius