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

IT’s Portfolio

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

Development Study/Rust

[System] The Elements of Computing System - 2

f1r3_r41n 2023. 11. 4. 13:05
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ป The Elements of Computing System - 2

๐Ÿค” 2์ง„์ˆ˜

  • ์ปดํ“จํ„ฐ๋Š” ์ˆ˜๋ฅผ 2์ง„์ˆ˜๋กœ ๋‹ค๋ฃธ
  • 10์ง„์ˆ˜ : 21
    • 2์ง„์ˆ˜ : 10101($2^4\times1+2^2\times1+1$)

๐Ÿค” 2์ง„ ๋ง์…ˆ

  • ์ตœํ•˜์œ„ ๋น„ํŠธ๋ถ€ํ„ฐ ์ตœ์ƒ์œ„ ๋น„ํŠธ๊นŒ์ง€ ๊ฐ™์€ ์ž๋ฆฌ์˜ ์ˆ˜๋ผ๋ฆฌ ์ž๋ฆฌ์˜ฌ๋ฆผ์ˆ˜๊นŒ์ง€ ๊ณ ๋ คํ•ด ๋”ํ•จ
  • ๋งˆ์ง€๋ง‰ ๋น„ํŠธ๋ฅผ ๋”ํ•˜๊ณ  ๋‚˜์„œ ์ž๋ฆฌ์˜ฌ๋ฆผ์ˆ˜๊ฐ€ 1์ด๋ผ๋ฉด, ์˜ค๋ฒ„ํ”Œ๋กœ ๋ฐœ์ƒ

๐Ÿค” ๋ถ€ํ˜ธ๊ฐ€ ์žˆ๋Š” 2์ง„์ˆ˜

  • ์ปดํ“จํ„ฐ๋Š” 2์˜ ๋ณด์ˆ˜(2's complement) ๋ฐฉ์‹ ์‚ฌ์šฉ
  • $x$์˜ ๋ณด์ˆ˜ = $2^n-x$
    • 0์€ 1๋กœ, 1์€ 0์œผ๋กœ ๋’ค์ง‘์€ ๋’ค +1 ํ•ด์ฃผ๋ฉด ์Œ์ˆ˜๊ฐ€ ๋จ
    • ๋ชจ๋“  ์Œ์ˆ˜ ์ฝ”๋“œ๋Š” 1๋กœ ์‹œ์ž‘ํ•จ

๐Ÿค” ๋ฐ˜๊ฐ€์‚ฐ๊ธฐ

  • ๋‘ ๋น„ํŠธ๋ฅผ ๋”ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ•จ
  • ๋ง์…ˆํ•œ ๊ฐ’์˜ ์ตœํ•˜์œ„ ๋น„ํŠธ๋ฅผ sum, ์ตœ์ƒ์œ„ ๋น„ํŠธ๋ฅผ carry๋ผ๊ณ  ํ•จ

๐Ÿค” ์ „๊ฐ€์‚ฐ๊ธฐ

  • ์„ธ ๊ฐœ์˜ ๋น„ํŠธ๋ฅผ ๋”ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ•จ
  • ์ถœ๋ ฅ์€ ๋ฐ˜๊ฐ€์‚ฐ๊ธฐ์™€ ๊ฐ™์Œ

๐Ÿค” ๊ฐ€์‚ฐ๊ธฐ

  • ๋ฉ”๋ชจ๋ฆฌ์™€ ๋ ˆ์ง€์Šคํ„ฐ ์นฉ์€ n๋น„ํŠธ ํŒจํ„ด์œผ๋กœ ๋œ ์ •์ˆ˜๋ฅผ ์ €์žฅํ•˜๊ณ , n์€ ํ”Œ๋žซํผ์— ๋”ฐ๋ผ 16, 32, 64 ๋“ฑ๋“ฑ์˜ ๊ฐ’์ด ๋จ
  • ์ด๋Ÿฐ ์ˆซ์ž๋ฅผ ๋ง์…ˆํ•˜๋Š” ์นฉ์„ ๋ฉ€ํ‹ฐ๋น„ํŠธ ๊ฐ€์‚ฐ๊ธฐ ํ˜น์€ ๊ฐ€์‚ฐ๊ธฐ๋ผ ๋ถ€๋ฆ„

๐Ÿค” ์ฆ๋ถ„๊ธฐ

  • ์ฃผ์–ด์ง„ ์ˆซ์ž์— 1์„ ๋”ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ•จ

๐Ÿค” ์‚ฐ์ˆ  ๋…ผ๋ฆฌ ์—ฐ์‚ฐ ์žฅ์น˜(ALU)

  • Arithmetic Logic Unit
  • x์™€ y๊ฐ€ ์นฉ์˜ ๋‘ 16๋น„ํŠธ ์ž…๋ ฅ์ด๊ณ , 16๋น„ํŠธ ์ถœ๋ ฅ ๊ฐ’์„ ๊ฐ€์ง
  • ์ฃผ์–ด์ง„ 2์ง„ ๊ฐ’๋“ค์— ๋Œ€ํ•ด ALU๊ฐ€ ์–ด๋–ค ์—ฐ์‚ฐ์„ ํ• ์ง€๋Š” '์ œ์–ด ๋น„ํŠธ'๋ผ๋Š” 6๊ฐœ์˜ ์ž…๋ ฅ ๋น„ํŠธ๋ฅผ ํ†ตํ•ด์„œ ๊ฒฐ์ •ํ•จ

๐Ÿค” ๊ตฌํ˜„

CHIP HalfAdder {
    IN a, b;    // 1-bit inpus
    Out carry,    // Left bit of a + b
        sum;    // Right bit of a + b

    PARTS:
    // Put you code here:
    And(a=a, b=b, out=carry);
    Xor(a=a, b=b, out=sum);
}
  • Half-Adder
  • sum์€ Xor๊ณผ ๊ฐ™์Œ
  • carry๋Š” And์™€ ๊ฐ™์Œ
CHIP FullAdder {
    IN a, b, c;    // 1-bit inputs
    OUT carry,    // Left bit of a + b + c
        sum;    // Right bit of a + b + c

    PARTS:
    HalfAdder(a=a, b=b, carry=carryAB, sum=sumAB);
    HalfAdder(a=sumAB, b=c, sum=sum, carry=carrySumABSumC);
    Or(a=carryAB, b=carrySumABSumC, out=carry);
}
  • Full-Adder
  • a์™€ b๋ฅผ ๋ฐ˜๊ฐ€์‚ฐ๊ธฐ๋กœ ๋”ํ•œ sum์„ c์™€ ๋”ํ•˜๋ฉด ์ตœ์ข… sum ๋„์ถœ
  • ๊ฐ๊ฐ์˜ ๋ฐ˜๊ฐ€์‚ฐ๊ธฐ์—์„œ ๋ฐœ์ƒํ•œ carry๋ฅผ Or ์—ฐ์‚ฐํ•˜๋ฉด ์ตœ์ข… carry ๋„์ถœ
CHIP ALU {
    IN  
        x[16], y[16],  // 16-bit inputs        
        zx, // zero the x input?
        nx, // negate the x input?
        zy, // zero the y input?
        ny, // negate the y input?
        f,  // compute out = x + y (if 1) or x & y (if 0)
        no; // negate the out output?

    OUT 
        out[16], // 16-bit output
        zr, // 1 if (out == 0), 0 otherwise
        ng; // 1 if (out < 0),  0 otherwise

    PARTS:
    // Put you code here:
    Mux16(a=x, b[0..15]=false, sel=zx, out=zX);     // zx๊ฐ€ 1์ด๋ผ๋ฉด x๋ฅผ 0์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค. 
    Not16(in=zX, out=notZx);                        
    Mux16(a=zX, b=notZx, sel=nx, out=znX);          // nx๊ฐ€ 1์ด๋ผ๋ฉด ํ˜„์‹œ์ ์˜ x๊ฐ’์„ ๋ฐ˜์ „์‹œํ‚จ๋‹ค. 

    Mux16(a=y, b[0..15]=false, sel=zy, out=zY);     // zy๊ฐ€ 1์ด๋ผ๋ฉด y๋ฅผ 0์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค. 
    Not16(in=zY, out=notZy);
    Mux16(a=zY, b=notZy, sel=ny, out=znY);          // ny๊ฐ€ 1์ด๋ผ๋ฉด ํ˜„์‹œ์ ์˜ y๊ฐ’์„ ๋ฐ˜์ „์‹œํ‚จ๋‹ค. 

    And16(a=znX, b=znY, out=andznXY);               
    Add16(a=znX, b=znY, out=addznXY);
    Mux16(a=andznXY, b=addznXY, sel=f, out=fout);       // f๊ฐ’์œผ๋กœ and, add ์ค‘ ์–ด๋–ค ์—ฐ์‚ฐ์„ ํ• ์ง€ ๊ฒฐ์ •ํ•œ๋‹ค. 
    Not16(in=fout, out=nfout);
    Mux16(a=fout, b=nfout, sel=no, out[0..7]=out1, out[8..15]=out2, out[15]=ng, out=out);   // no๊ฐ’์ด 1์ด๋ฉด ๊ฒฐ๊ณผ๊ฐ’์„ ๋ฐ˜์ „์‹œํ‚จ๋‹ค. ์ตœ์ข… ์ถœ๋ ฅ๊ฐ’์ด ์Œ์ˆ˜๋ผ๋ฉด ng๋ฅผ 1๋กœ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค. 

    Or8Way(in=out1, out=orOut1);
    Or8Way(in=out2, out=orOut2);
    Or(a=orOut1, b=orOut2, out=orOut);      // ์ถœ๋ ฅ๊ฐ’์„ ์•ž, ๋’ค๋กœ ๋‚˜๋ˆ„์–ด์„œ or์—ฐ์‚ฐ์„ ํ•ด, 1์ด ์กด์žฌํ•˜๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค. 

    Not(in=orOut, out=zr);  //  or์—ฐ์‚ฐ์˜ ์ตœ์ข…๊ฐ’์— ๋”ฐ๋ผ์„œ zr์„ ๊ฒฐ์ •ํ•œ๋‹ค. 
}
  • ALU
728x90
๋ฐ˜์‘ํ˜•

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

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