Wednesday, June 2, 2010

New interview questions

1) There is a waveform

    in _____|====|________
    out_____|=|___|=|______

    The output is "high" when the input change the value.

    Verilog code
   
    always@(posedge clk or reset)
   begin
      if(!reset)
      begin
        in_reg <= 1'b0;    // initial value
        out      <= 1'b0;
     end
    else
    begin
             if(in != in_reg)
             begin
                      out <= 1'b1;
                      in_reg <= in;
             end
            else
                     out <= 1'b0;
    end
   end

   After synthesis, what will it be look like?

   It's like a D-FF and a XOR

   in -----D_FF------in_reg---|XOR|  ___   out
         |__________________|        |

2)   How to write a C or C++ code for Strlen

Answer:
     
    int strlen (char *s)
     begin
          for (int len =0; *s='\0'; s++)
               len++;
          return (len);
     end
  
    Use recurve way

    int strlen_r (char *s)
    begin
             if(*s='\0')  return 0;
             else  return (1 + strlen_r(s+1));   
     end
   

   
  


    

No comments:

Post a Comment

Search This Blog