Tagged: Programming/Coding Toggle Comment Threads | Keyboard Shortcuts

  • CG 9:55 pm on October 29, 2010 Permalink | Reply
    Tags: , Programming/Coding, , ,   

    Tristate buffer 


    LIBRARY ieee;
    USE ieee.std_logic_1164.ALL;

    ENTITY bidir IS
    PORT(
    bidir : INOUT STD_LOGIC_VECTOR (7 DOWNTO 0);
    oe, clk : IN STD_LOGIC;
    inp : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
    outp : OUT STD_LOGIC_VECTOR (7 DOWNTO 0));
    END bidir;

    ARCHITECTURE maxpld OF bidir IS
    SIGNAL a : STD_LOGIC_VECTOR (7 DOWNTO 0); -- DFF that stores
    -- value from input.
    SIGNAL b : STD_LOGIC_VECTOR (7 DOWNTO 0); -- DFF that stores
    BEGIN -- feedback value.
    PROCESS(clk)
    BEGIN
    IF clk = '1' AND clk'EVENT THEN -- Creates the flipflops
    a <= inp;
    outp <= b;
    END IF;
    END PROCESS;
    PROCESS (oe, bidir) -- Behavioral representation
    BEGIN -- of tri-states.
    IF( oe = '0') THEN
    bidir <= "ZZZZZZZZ";
    b <= bidir;
    ELSE
    bidir <= a;
    b <= bidir;
    END IF;
    END PROCESS;
    END maxpld;

     

    Advertisements
     
    • Budi Rahardjo 12:11 am on October 30, 2010 Permalink | Reply

      Ok I can see that the tri-state is happening. Try this approach with your design and see if it can utilize tri-state in sharing the look-up table.

      • CG 5:51 am on October 30, 2010 Permalink | Reply

        haih, bikin tri-state aja susah gini ya 😀

  • CG 2:30 pm on October 21, 2010 Permalink | Reply
    Tags: , , Programming/Coding, , register,   

    Adder with register 


    library ieee;
    use ieee.std_logic_1164.all;

    entity adder2bitwithregjuga is
    port
    (clock: in std_logic;
    Ain: in std_logic;
    Bin: in std_logic;
    shift: in std_logic;
    CI: in std_logic;
    S : out std_logic_vector(1 downto 0);
    C0: out std_logic);
    end adder2bitwithregjuga;

    architecture arch of adder2bitwithregjuga is
    -- Specify the Full Adder subcircuit
    component Full_Adder
    port
    (AI,BI,CYI: in std_logic;
    SUM, CYO :out std_logic);
    end component;

    --Reserve a few signals for internal connections
    --signal CY0, CY1, CY2: bit;
    signal flag: std_logic;
    signal CY0: std_logic;
    signal A,B : std_logic_vector(1 downto 0);
    begin
    FA0: Full_Adder port map (A(0), B(0), CI, S(0), CY0);
    FA1: Full_Adder port map (A(1), B(1), CY0, S(1), C0);
    process(clock)
    begin
    flag <= clock and shift;
    if rising_edge(flag) then
    A(1) <= A(0);
    A(0) <= Ain;
    B(1) <= B(0);
    B(0) <= Bin;
    end if;
    end process;

    end arch;

    entity Full_Adder is
    port
    (AI,BI,CYI: in bit;
    SUM, CYO : out bit);
    end Full_Adder;

    architecture FA of Full_Adder is
    component Half_Adder
    port
    (W,X: in bit;
    Y,Z: out bit);
    end component;
    signal Y0,Z0,Z1: bit;
    begin
    HA0: Half_Adder port map(AI, BI, Y0, Z0);
    HA1: Half_Adder port map(CYI, Y0, SUM, Z1);
    CYO <= Z0 or Z1;
    end FA;

    entity Half_Adder is
    port
    (W,X: in bit;
    Y,Z: out bit);
    end Half_Adder;

    architecture HA of Half_Adder is
    begin
    Y <= W xor X; -- This is the sum bit
    Z <= W and X; -- This is the carry bit
    end HA;

     
    • Bobby 4:46 pm on October 21, 2010 Permalink | Reply

      HORRROOOORRR

    • Budi Rahardjo 2:03 pm on October 23, 2010 Permalink | Reply

      liat tuh di kodenya sampe ada yang ketawa (smiley)… he he he

      • CG 6:38 pm on October 23, 2010 Permalink | Reply

        itu bukan smile tapi lagi teriak “HORRROOOORRR! ” hihihihihi

  • CG 11:02 pm on October 10, 2010 Permalink | Reply
    Tags: generating clock, Programming/Coding, ,   

    Generating clock in quartus 

    After spending days finding answers on how to generate clock in quartus, I finally found the answer here:

    This is very easy. That’s why people always say RTFM.

    But later I still want to try this:

    1. http://www.stefanvhdl.com/vhdl/html/clk_rst.html
    2. http://www.doulos.com/knowhow/vhdl_designers_guide/tips/clock_generation/
    3. http://www.excamera.com/articles/23/clock.html
    4. http://www.edaboard.com/thread132686.html
     
  • CG 5:35 pm on October 1, 2010 Permalink | Reply
    Tags: , Programming/Coding, ,   

    Adder 299bit – too many to fit in the selected device 

    if the adder cannot fit in, how to make an elliptic curve point multiplier can?

     
    • asp 12:53 pm on October 2, 2010 Permalink | Reply

      Kayaknya dibiarin dulu saja, terusin tidak masalah. Adder kan sebetulnya tidak harus keluar pin-nya.
      Kan hanya salah satu blok diagram dalam chipnya. Sekarang ke multiplier…

    • CG 6:02 pm on October 3, 2010 Permalink | Reply

      maybe i need the full version of quartus.

  • CG 6:30 pm on September 29, 2010 Permalink | Reply
    Tags: full adder, , Programming/Coding, ,   

    Debugging Full Adder 

    the carry is always zero.

    no wonder. the code is wrong. huh.

    it should be added one more line.

    now. it’s correct.

    Notes:
    ngaco nih contoh2x di internet!!! emang musti bikin sendiri dari depan kali. haduh.

     
    • asp 7:30 pm on September 29, 2010 Permalink | Reply

      Contoh2 di internet itu kan gunanya supaya bisa mulai dari analisis yg kemudian dimodifikasi untuk kebutuhan sendiri. Hal itu yang buat lebih cepet.
      Analoginya, akan lebih lambat kalo belajar coding dari buat “project” dulu sendiri dari nol, dibanding dari project yang sudah bisa dicompile lalu dimodifikasi kesalahan substansinya.
      (*jadi inget diskusi soal learning dan technology*)

      • CG 10:44 pm on September 29, 2010 Permalink | Reply

        ya tapinya tetep harus di debug.

    • Budi Rahardjo 7:34 pm on September 29, 2010 Permalink | Reply

      jangan-jangan kalau contoh ini ngaco, terus dicontoh orang lagi 🙂 hi hi hi
      sekarang tinggal buat skala yang lebih besar ya.

      • CG 10:40 pm on September 29, 2010 Permalink | Reply

        kebayang gak kalau ini gak di debug, trus langsung tempel dipake di modul yang lebih besar trus di ujung sampe botak2x mikirnya ini kok “not on curve” ya? hi hi hi 😀

  • CG 8:23 am on September 3, 2010 Permalink | Reply
    Tags: , Programming/Coding,   

    A simple lookup table in vhdl 


    library ieee;
    use ieee.std_logic_1164.all;

    entity simplelutCG is
    port
    (
    clk : in std_logic;
    e : in std_logic;
    r : in std_logic;
    data : out std_logic_vector(3 downto 0)
    );
    end entity simplelutCG;

    architecture behavioral of simplelutCG is
    signal i : integer range 0 to 3:=0; -- change the range value
    signal enable : std_logic:='0';
    type lut is array ( 0 to 2**2 - 1) of std_logic_vector(3 downto 0);
    constant my_lut : lut := (
    0 => "0000",
    1 => "0001",
    2 => "0010",
    3 => "0011");

    begin
    process (e)
    begin
    signal
    if e'event and e = '1' then
    enable <= '1';
    end if;
    end process;

    process (clk)
    begin
    if rising_edge (clk) then
    if (enable = '1') then
    data <= my_lut(3);
    end case;
    end if;
    end process;

    end architecture behavioral;

     
  • CG 9:55 am on April 30, 2010 Permalink | Reply
    Tags: , Programming/Coding,   

    Encryption – Decryption finally works 

    With the help of this debugger and that debugger, changing the data from this:

    into this:

    make the code works. It’s because the data occupied more space than the capacity of the number of words.


    lss-67-39:Rosing Experiments CG chika$ ./test_elgamal_CG
    poly_prime =
    8 0 0 0 0 c9
    setting up curve

    the curve after setting up:
    form: 1
    a2: 0 0 0 0 0 2
    a6: 0 0 0 0 0 1

    counter = 0
    inc = 5
    Base point
    x: 5 63323eab 10fc68f8 254d4d11 d2d518f2 9979dd24
    y: 4 883e6269 de8bf93e f6c224e3 330dbf7f 2dd25ec1

    create side 2's private key

    Side 2 secret:
    5 5d0be8bb a913fcdb 91edee60 4da6d486 295d85ac

    Generate side 2's public key

    Side 2 public key
    x: 0 60838c40 7580aec4 b658d152 729f7f67 51d694bd
    y: 0 1be3f90c c4a81de1 848ff01b d63e97a4 6b46c459
    data =
    0 68616c6c 6f0a0000 0 0 60000000

    Hide data on curve and send from side 1 to side 2

    curve before send_elgamal:
    form: 1
    a2: 0 0 0 0 0 2
    a6: 0 0 0 0 0 1

    Their_public before send_elgamal:
    x: 0 60838c40 7580aec4 b658d152 729f7f67 51d694bd
    y: 0 1be3f90c c4a81de1 848ff01b d63e97a4 6b46c459
    =====IN send_elgamal=====
    data (in send_gamal function) :
    0 68616c6c 6f0a0000 0 0 60000000
    Base point
    x: 5 63323eab 10fc68f8 254d4d11 d2d518f2 9979dd24
    y: 4 883e6269 de8bf93e f6c224e3 330dbf7f 2dd25ec1
    Base curve
    form: 1
    a2: 0 0 0 0 0 2
    a6: 0 0 0 0 0 1

    random value:
    5 3a0f94f6 e0caf9a7 2d189f04 8591c5e5 3935d4dc
    Random point C1
    x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06
    y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6
    counter = 0
    inc = 0
    raw point M (after poly_embed)
    x: 0 68616c6c 6f0a0000 0 0 60000000
    y: 0 7a64a103 a296a42d 4130d375 23ef2cf2 3f1a3ec0
    Their_public:
    x: 0 60838c40 7580aec4 b658d152 729f7f67 51d694bd
    y: 0 1be3f90c c4a81de1 848ff01b d63e97a4 6b46c459
    hidden point (after poly_elptic_mul)
    x: 7 1f5fceb7 8269106c c1708600 cde8821b 38e0c7ee
    y: 2 d752fec4 40840001 be4a3e7f 347e7013 7f36ce97
    Hidden data (C2):
    x: 6 a8a348b9 60a911b7 852a3bb9 8ba949df 5a157ae
    y: 0 239b098 7584aea3 af4431db 2f3fa3f4 312c5ea9
    Random point (C1):
    x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06
    y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6
    =====OUT send_elgamal

    AFTER send_elgamal
    curve after send_elgamal:
    form: 1
    a2: 0 0 0 0 0 2
    a6: 0 0 0 0 0 1

    Hidden data (C2)
    x: 6 a8a348b9 60a911b7 852a3bb9 8ba949df 5a157ae
    y: 0 239b098 7584aea3 af4431db 2f3fa3f4 312c5ea9
    Random point (C1)
    x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06
    y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6

    Recover transmitted message

    IN receive_elgamal
    Base curve in receive_elgamal
    form: 1
    a2: 0 0 0 0 0 2
    a6: 0 0 0 0 0 1

    Hidden_data (in receive_elgamal) :
    x: 6 a8a348b9 60a911b7 852a3bb9 8ba949df 5a157ae
    y: 0 239b098 7584aea3 af4431db 2f3fa3f4 312c5ea9
    Random point
    x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06
    y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6
    hidden_point (d*C1):
    x: 7 1f5fceb7 8269106c c1708600 cde8821b 38e0c7ee
    y: 2 d752fec4 40840001 be4a3e7f 347e7013 7f36ce97
    &raw_point:
    x: 0 68616c6c 6f0a0000 0 0 60000000
    y: 0 7a64a103 a296a42d 4130d375 23ef2cf2 3f1a3ec0
    raw_point.x
    0 68616c6c 6f0a0000 0 0 60000000
    &raw_data (point):
    x: bffff630 bbe72787 d25ef6fb 139332fc 90db35c4 fd129391
    y: 0 2 d6670f0 ab08aca3 8818adbe cf36881d
    raw_data (point):
    x: 0 68616c6c 6f0a0000 0 0 60000000
    y: 0 68616c6c 6f0a0000 0 0 60000000
    &raw_data (field):
    bffff630 bbe72787 d25ef6fb 139332fc 90db35c4 fd129391
    raw_data (field):
    0 68616c6c 6f0a0000 0 0 60000000
    =====OUT receive elgamal

    sent data
    0 68616c6c 6f0a0000 0 0 60000000
    received data (field)
    0 68616c6c 6f0a0000 0 0 60000000

     
  • CG 4:42 am on April 25, 2010 Permalink | Reply
    Tags: hg init, programming tool, Programming/Coding, splint, versioning   

    Interesting to read 

    1. http://en.wikipedia.org/wiki/Splint_%28programming_tool%29
    2. http://splint.org/
    3. http://hginit.com/
     
  • CG 5:04 pm on April 23, 2010 Permalink | Reply
    Tags: , , Programming/Coding   

    “problems in gcc” solved 

    After fussing about the compiler since yesterday and having nightmare last night about cannot finish the grad study before dec, apparently there’s nothing wrong with the compiler (hopefully). It’s only “typos”!

    Oh my! 😀 S**t happens. Especially during grad school 😀

     
    • Budi Rahardjo 5:21 am on April 24, 2010 Permalink | Reply

      grrrr …

      • Bobby 1:07 pm on April 24, 2010 Permalink | Reply

        paraaaah, makanya pakai editor yang rada bagusan, pake terminal mulu sih. ato settingan editornya pakai backgound yang warnanya jadi bikin mata ga cape walau koding lama banget.

        • CG 4:45 am on April 25, 2010 Permalink

          itu terlalu kontras ya untuk koding lama2x?

      • CG 4:44 am on April 25, 2010 Permalink | Reply

        @rahard: ampun 😀

        • Bobby 2:10 pm on April 26, 2010 Permalink

          @cg, sangat ga nyaman, mata akan lebih santai klo cahaya nya redup. coba aja pelototin lampu, ga enak kan.

  • CG 5:55 pm on April 17, 2010 Permalink | Reply
    Tags: , pointer, Programming/Coding   

    Pointers are so cruel… 

    They’re bad! And mean!

    After weeks of debugging, and still cannot get the plaintext back, now I’m moving to the next: building ECC on composite fields.

    Note: below is the result of the codes with printf-s everywhere. With the help of this debugger.

    The algorithm seems correct but the data recovered looks weird.


    poly_prime =
    8 0 0 0 0 c9
    setting up curves

    the curve after setting up:
    form: 1
    a2: 0 0 0 0 0 2
    a6: 0 0 0 0 0 1

    counter = 0
    inc = 5
    Base point
    x: 5 63323eab 10fc68f8 254d4d11 d2d518f2 9979dd24
    y: 4 883e6269 de8bf93e f6c224e3 330dbf7f 2dd25ec1

    create side 2's private key

    Side 2 secret:
    5 5d0be8bb a913fcdb 91edee60 4da6d486 295d85ac

    Generate side 2's public key

    Side 2 public key
    x: 1d5ba6c2 5378466 ae5d1cce 48770132 e9d6d710 a7448cd1
    y: 4 85500816 ccee8906 56a133dc 19c325f8 4bb9ffa6
    data =
    68616c6c 6f0a0000 0 0 0 60000000

    Hide data on curve and send from side 1 to side 2

    curve before send_elgamal:
    form: 1
    a2: 0 0 0 0 0 2
    a6: 0 0 0 0 0 1

    Their_public before send_elgamal:
    x: 1d5ba6c2 5378466 ae5d1cce 48770132 e9d6d710 a7448cd1
    y: 4 85500816 ccee8906 56a133dc 19c325f8 4bb9ffa6
    =====IN send_elgamal=====
    data (in send_gamal function) :
    68616c6c 6f0a0000 0 0 0 60000000
    Base point
    x: 5 63323eab 10fc68f8 254d4d11 d2d518f2 9979dd24
    y: 4 883e6269 de8bf93e f6c224e3 330dbf7f 2dd25ec1
    Base curve
    form: 1
    a2: 0 0 0 0 0 2
    a6: 0 0 0 0 0 1

    random value:
    5 3a0f94f6 e0caf9a7 2d189f04 8591c5e5 3935d4dc
    Random point C1
    x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06
    y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6
    counter = 0
    inc = 0
    counter = 0
    -- pnt->x =
    x: bffff4b8 a00754ec bffff4d8 a0073a58 a a
    y: 68616c6d 6f0a0000 0 0 0 60000000
    raw point M (after poly_embed)
    x: 68616c6d 6f0a0000 0 0 0 60000000
    y: 1 2c310f6b e4c3751c 2ef637ef ce837cb2 88e21c99
    Their_public:
    x: 1d5ba6c2 5378466 ae5d1cce 48770132 e9d6d710 a7448cd1
    y: 4 85500816 ccee8906 56a133dc 19c325f8 4bb9ffa6
    hidden point (after poly_elptic_mul)
    x: 6 987b3fe3 f486168f 19bba08c b943f599 c43cfa22
    y: 1 6a16b493 afad94b4 f93c6f41 40281e42 8c448f24
    Hidden data (C2):
    x: 68616c6c d3ba4b92 8c4b46c0 a6c78778 afcaf788 5187c979
    y: 68616c69 372ef71c 96586e6d bad28a2 ff127133 b48ca3de
    Random point (C1):
    x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06
    y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6
    =====OUT send_elgamal

    AFTER send_elgamal
    curve after send_elgamal:
    form: 1
    a2: 0 0 0 0 0 2
    a6: 0 0 0 0 0 1

    Hidden data (C2)
    x: 68616c6c d3ba4b92 8c4b46c0 a6c78778 afcaf788 5187c979
    y: 68616c69 372ef71c 96586e6d bad28a2 ff127133 b48ca3de
    Random point (C1)
    x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06
    y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6

    Recover transmitted message

    IN receive_elgamal
    Base curve in receive_elgamal
    form: 1
    a2: 0 0 0 0 0 2
    a6: 0 0 0 0 0 1

    Hidden_data (in receive_elgamal) :
    x: 68616c6c d3ba4b92 8c4b46c0 a6c78778 afcaf788 5187c979
    y: 68616c69 372ef71c 96586e6d bad28a2 ff127133 b48ca3de
    Random point
    x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06
    y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6
    hidden_point (d*C1):
    x: 7 1f5fceb7 8269106c c1708600 cde8821b 38e0c7ee
    y: 2 d752fec4 40840001 be4a3e7f 347e7013 7f36ce97
    &raw_point:
    x: 68616c6a de301be6 24719966 c269b54f ef049a08 8c7af389
    y: 3 fae10821 85e832bb b9c6d8ab cc4439f4 eb7441ea
    raw_point.x
    68616c6a de301be6 24719966 c269b54f ef049a08 8c7af389
    &raw_data (point):
    x: bffff670 10700ccf af82abf6 b46a9779 16316b62 7df7f7d
    y: 4037177 debca93c 4b16e65 77a8ff5a 70c28f88 1d5ba6c1
    raw_data (point):
    x: 68616c6a de301be6 24719966 c269b54f ef049a08 8c7af389
    y: 68616c6c 6f0a0000 0 0 0 60000000
    &raw_data (field):
    bffff670 10700ccf af82abf6 b46a9779 16316b62 7df7f7d
    raw_data (field):
    68616c6a de301be6 24719966 c269b54f ef049a08 8c7af389
    =====OUT receive elgamal

    sent data
    68616c6c 6f0a0000 0 0 0 60000000
    received data (point)
    x: 68616c6a de301be6 24719966 c269b54f ef049a08 8c7af389
    y: 68616c6c 6f0a0000 0 0 0 60000000
    received data (field)
    68616c6a de301be6 24719966 c269b54f ef049a08 8c7af389

     
    • Budi Rahardjo 7:11 pm on April 17, 2010 Permalink | Reply

      masih belum selesai debuggingnya. kayaknya mau ngerapihin code-nya dulu

      • CG 8:15 pm on April 17, 2010 Permalink | Reply

        be careful. the pointers like to behave unexpectedly anytime we alter the code. bad pointers! grrrrrr!!!

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel