English subtitles

← For Each Loop cs348 unit3new

Get Embed Code
1 Language

Showing Revision 1 created 04/14/2013 by Cogi-Admin.

  1. Before we finish the packet tcm, let's have a look at the for each construct.
  2. The for each construct basically looks like this, for each (local_var) in
  3. . This loop will go over each element of this list. And in
  4. each iteration, you have the index, which gives you the loop-index, and the
  5. local_var point to the list[index]. So, you always have the element you're
  6. looking at. This is a very handy loop, because you don't need to know how long
  7. the list is. It will work for any list. For example, if you had for each
  8. (pkt_byte) in lob, this would be equivalent to this C style loop, so you would
  9. do i=0, i++, i
  10. to lob[i]. And also, a local variable called index, which is i. So, back to the
  11. packet driver. We've packed all of the interesting fields in lob and here we go
  12. on for each byte. So, we use this for each loop. And first, we need to
  13. synchronize, we need to wait for the suspend_p$ to be 0. So, here we ask the
  14. question, is it true that suspend is equal to 0? If that is the case, we fall
  15. through. If it isn't, we write here. Next, we do a signal assignment. So, we
  16. use. The port access modifier dollar sign, in an assignment on the left hand
  17. side, this means we assign pkt_byte to this data_p$t. We also need to assign
  18. valid, valid needs to be 1 for all bytes apart from parity. So, here we have
  19. just an if condition we say okay, if (index+1) < lob.size validp$=1. If it
  20. isn't, so it would be equal. This is the last byte, valid_p$=0. We wait one
  21. further clock cycle, this is the only real wait. We go around in this loop
  22. again. This allows us to send every byte as long as suspend is zero.