๊ด€๋ฆฌ ๋ฉ”๋‰ด

IT’s Portfolio

[System] The Elements of Computing System - 1 ๋ณธ๋ฌธ

Development Study/Rust

[System] The Elements of Computing System - 1

f1r3_r41n 2023. 10. 31. 18:36
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ป The Elements of Computing System - 1

๐Ÿค” ๋ถˆ ๋Œ€์ˆ˜(Boolean Algebra)

  • true/false, ์˜ˆ/์•„๋‹ˆ์˜ค, ์ผœ์ง/๊บผ์ง ๊ฐ™์€ ๋ถˆ๊ฐ’์„ ๋‹ค๋ฃจ๋Š” ๋Œ€์ˆ˜ํ•™
  • ์ปดํ“จํ„ฐ๋Š” ์ง„์ˆ˜๋ฅผ ํ‘œํ˜„ํ•˜๊ณ  ์ฒ˜๋ฆฌํ•˜๋Š” ํ•˜๋“œ์›จ์–ด์ด๊ธฐ ๋•Œ๋ฌธ์— 2์ง„์ˆ˜ ์ž…๋ ฅ์„ ๊ฐ€๊ณตํ•ด 2์ง„์ˆ˜ ์ถœ๋ ฅ์„ ํ•˜๋Š” ๋ถˆ ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•˜๊ณ  ๋ถ„์„ํ•˜๋Š” ๊ฒƒ์ด ์ปดํ“จํ„ฐ ์•„ํ‚คํ…์ณ๋ฅผ ๊ตฌ์ถ•ํ•˜๋Š” ์ฒซ ๋‹จ๊ณ„๊ฐ€ ๋จ

๐Ÿค” ํ•˜๋“œ์›จ์–ด ๊ธฐ์ˆ  ์–ธ์–ด

CHIP Xor {
    IN x, y;
    OUT out;
    PARTS:
        Not(in=x, out=notx);
        Not(in=y, out=noty);
        And(x=x, y=noty, out=w1);
        And(x=notx, y=y, out=w2);
        Or(x=w1, y=w2, out=out);
}
  • HDL program(Xor.hdl)
    • Xor(exclusive or) gate
    • if x<>y out=1 else out=0
  • HDL์˜ ํ—ค๋” ๋ถ€๋ถ„์—์„œ๋Š” ์นฉ ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
  • ์นฉ์˜ ์ด๋ฆ„๊ณผ ์ž…๋ ฅ ๋ฐ ์ถœ๋ ฅ ์ด๋ฆ„์„ ๋ช…์‹œ
  • ํŒŒํŠธ๋Š” ํ•ด๋‹น ์นฉ์˜ ๋‚ด๋ถ€ ๊ตฌํ˜„ ๋‹ด๋‹น
  • ํ—ค๋”์—์„œ ๋ช…์‹œ๋œ ์ž…๋ ฅ์„ ๊ฐ์ข… ๋ถˆ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ์›ํ•˜๋Š” ์ถœ๋ ฅ๊ฐ’์„ ๋งŒ๋“ค์–ด ๋ƒ„
load Xor.hdl
output-list x, y, out;
set x 0, set y 0,
eval, output;
set x 0, set y 1,
eval, output;
set x 1, set y 0,
eval, output;
set x 1, set y 1,
eval, output;
  • Text script(Xor.tst)
  • ํ…Œ์ŠคํŠธ ์Šคํฌ๋ฆฝํŠธ๋Š” ์„ค๊ณ„ํ•œ ์นฉ์„ ์‹คํ–‰์‹œํ‚ด
  • ์‹คํ–‰ํ•˜๊ณ ์ž ํ•˜๋Š” ์นฉ์„ ๋ถˆ๋Ÿฌ์™€์„œ ์ž…๋ ฅ ๊ฐ’์„ ์„ค์ •ํ•˜๊ณ  ์‹คํ–‰ํ•จ
x | y | out
-----------
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 0 
  • Output file(Xor.out)
  • ์‹คํ–‰์ด ๋๋‚˜๊ณ  ๋‚˜๋ฉด ์ž…๋ ฅ ๊ฐ’์˜ ์ถœ๋ ฅ ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ๋กํ•œ .out ํŒŒ์ผ์„ ์ƒ์„ฑ

๐Ÿค” Nand ๊ฒŒ์ดํŠธ

x y | Nand(x, y)
----------------
0 0 |     1
0 1 |     1
1 0 |     1
1 1 |     0 
  • ๋‹ค๋ฅธ ๋ชจ๋“  ๊ฒŒ์ดํŠธ๋“ค์˜ ๊ธฐ์ดˆ๊ฐ€ ๋˜๋Š” ๊ฒŒ์ดํŠธ

๐Ÿค” ๊ธฐ๋ณธ ๋…ผ๋ฆฌ ๊ฒŒ์ดํŠธ

  • Not
    • ๋‹จ์ผ ์ž…๋ ฅ Not ๊ฒŒ์ดํŠธ๋Š” 'converter'๋ผ๊ณ ๋„ ๋ถˆ๋ฆฌ๋ฉฐ, ์ž…๋ ฅ๊ฐ’์„ ๋ฐ˜์ „์‹œํ‚ด
  • And
    • ์ž…๋ ฅ๊ฐ’์ด ๋‘˜๋‹ค 1์ผ ๊ฒฝ์šฐ์— 1์„, ๊ทธ ์™ธ์—๋Š” 0์„ ๋ฐ˜ํ™˜
  • Or
    • ์ž…๋ ฅ๊ฐ’ ์ค‘ ์ ์–ด๋„ ํ•˜๋‚˜๊ฐ€ 1์ผ ๋•Œ 1์„, ๊ทธ ์™ธ์—๋Š” 0์„ ๋ฐ˜ํ™˜
  • Xor
    • 'exclusive or'์ด๋ผ๊ณ ๋„ ๋ถˆ๋ฆฌ๋ฉฐ, ๋‘ ์ž…๋ ฅ๊ฐ’์ด ๋‹ค๋ฅผ ๊ฒฝ์šฐ 1, ๊ทธ ์™ธ์—๋Š” 0์„ ๋ฐ˜ํ™˜
  • Multiplexor
    • '์„ ํƒ ๋น„ํŠธ' ์ž…๋ ฅ์— ๋”ฐ๋ผ์„œ ๋‘ ๊ฐœ์˜ '๋ฐ์ดํ„ฐ ๋น„ํŠธ' ์ž…๋ ฅ ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ด ๋ฐ˜ํ™˜
  • DeMultiplexor
    • ๋ฉ€ํ‹ฐํ”Œ๋ ‰์„œ์™€ ์ •๋ฐ˜๋Œ€ ๊ธฐ๋Šฅ์„ ํ•จ
    • '์„ ํƒ ๋น„ํŠธ'์— ๋”ฐ๋ผ ๋‘ ์ถœ๋ ฅ์„  ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ด ์ž…๋ ฅ ์‹ ํ˜ธ๋ฅผ ๋ฐ˜ํ™˜

๐Ÿค” ๊ตฌํ˜„

CHIP Not {
    IN in;
    OUT out;

    PARTS:
    // Put your code here:
    Nand(a=in, b=in, out=out);
}
  • Not
CHIP And {
    IN a, b;
    OUT out;

    PARTS:
    // Put your code here:
    Nand(a=a, b=b, out=nandAB);
    Nand(a=nandAB, b=nandAB, out=out);
}
  • And
CHIP Or {
    IN a, b;
    OUT out;

    PARTS:
    // Put your code here:
    Not(in=a, out=Nota);
    Not(in=b, out=Notb);
    Nand(a=Nota, b=Notb, out=out);
}
  • Or
CHIP Xor {
    IN a, b;
    OUT out;

    PARTS:
    // Put your code here:
    Not(in=a, out=notA);
    Not(in=b, out=notB);
    And(a=a, b=notB, out=AandNotB);
    And(a=notA, b=b, out=BandNotA);
    Or(a=AandNotB, b=BandNotA, out=out);
}
  • Xor
CHIP Mux {
    IN a, b, sel;
    OUT out;

    PARTS:
    // Put your code here:
    Not(in=sel, out=Notsel);
    And(a=sel, b=b, out=bsel);
    And(a=Notsel, b=a, out=aNotsel);
    Or(a=aNotsel, b=bsel, out=out);
}
  • Multiplexor
CHIP DMux {
    IN in, sel;
    OUT a, b;

    PARTS:
    Not(in=sel, out=Notsel);
    And(a=in, b=Notsel, out=a);
    And(a=in, b=sel, out=b);
    // Put your code here:
}
  • DeMultiplexor
/**
 * 16-bit multiplexor: 
 * for i = 0..15 out[i] = a[i] if sel == 0 
 *                        b[i] if sel == 1
 */

CHIP Mux16 {
    IN a[16], b[16], sel;
    OUT out[16];

    PARTS:
    Mux(a=a[0], b=b[0], sel=sel, out=out[0]);
    Mux(a=a[1], b=b[1], sel=sel, out=out[1]);
    Mux(a=a[2], b=b[2], sel=sel, out=out[2]);
    Mux(a=a[3], b=b[3], sel=sel, out=out[3]);
    Mux(a=a[4], b=b[4], sel=sel, out=out[4]);
    Mux(a=a[5], b=b[5], sel=sel, out=out[5]);
    Mux(a=a[6], b=b[6], sel=sel, out=out[6]);
    Mux(a=a[7], b=b[7], sel=sel, out=out[7]);
    Mux(a=a[8], b=b[8], sel=sel, out=out[8]);
    Mux(a=a[9], b=b[9], sel=sel, out=out[9]);
    Mux(a=a[10], b=b[10], sel=sel, out=out[10]);
    Mux(a=a[11], b=b[11], sel=sel, out=out[11]);
    Mux(a=a[12], b=b[12], sel=sel, out=out[12]);
    Mux(a=a[13], b=b[13], sel=sel, out=out[13]);
    Mux(a=a[14], b=b[14], sel=sel, out=out[14]);
    Mux(a=a[15], b=b[15], sel=sel, out=out[15]);
}
  • 16๋น„ํŠธ Multiplexor
    • 1๋น„ํŠธ ๊ฒŒ์ดํŠธ๋ฅผ ์ด์–ด๋ถ™ํ˜€ ์„ค๊ณ„ํ•จ
/**
 * 4-way 16-bit multiplexor:
 * out = a if sel == 00
 *       b if sel == 01
 *       c if sel == 10
 *       d if sel == 11
 */

CHIP Mux4Way16 {
    IN a[16], b[16], c[16], d[16], sel[2];
    OUT out[16];

    PARTS:
    // Put your code here:
    Mux16(a=a, b=b, sel=sel[0], out=muxAB);
    Mux16(a=c, b=d, sel=sel[0], out=muxCD);
    Mux16(a=muxAB, b=muxCD, sel=sel[1], out=out);
}

  • ํ† ๋„ˆ๋จผํŠธ ํ˜•์‹์œผ๋กœ ์ผ์ „์— ์„ค๊ณ„ํ•œ 2x1 Mux๋กœ 4๊ฐœ์˜ ์ž…๋ ฅ์„ 2๊ฐœ๋กœ ์ถ”๋ฆฌ๊ณ  ์ถ”๋ ค์ง„ 2๊ฐœ์˜ ์ž…๋ ฅ ์ค‘ ๋งˆ์ง€๋ง‰ Mux๋กœ ์ตœ์ข… ์ถœ๋ ฅ๊ฐ’ ๊ฒฐ์ •
  • ์ด ๋•Œ, ์„ ํƒ ๋น„ํŠธ๋ฅผ 2bit๋กœ ๋Š˜๋ ค์„œ ์ฒซ ์—ฐ์‚ฐ๊ณผ ๋งˆ์ง€๋ง‰ Mux ์—ฐ์‚ฐ์— ๊ฐ๊ฐ ์„ ํƒ ๋น„ํŠธ ํ•œ ๊ฐœ์”ฉ์„ ์‚ฌ์šฉํ•จ
728x90
๋ฐ˜์‘ํ˜•

'Development Study > Rust' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[System] The Elements of Computing System - 3  (1) 2023.11.08
[System] The Elements of Computing System - 2  (1) 2023.11.04
[Rust] How to study Rust? - "Copycat" (6)  (0) 2023.09.24
[Rust] How to study Rust? - "Copycat" (5)  (0) 2023.09.23
[Rust] How to study Rust? - "Copycat" (4)  (0) 2023.09.23
Comments