Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use Modelsim to debug and compile a while loop statement syntax: while () module

ID: 3795787 • Letter: U

Question

Use Modelsim to debug and compile a while loop statement syntax: while () module while_example (); reg [5:0] location; reg [7:0] data; always @ (data or location) begin location = 0;//If Data is 0, then location is 32 (invalid value) if (data == 0) begin location = 32; end else begin while (data [0] == 0) begin location = location + 1; data = data >> 1; end end $display ("DATA = %b LOCATION = %d", data, location); end initial begin #1 data = 8'b11; #1 data = 8'b100; #1 data = 8'b1000; #1 data = 8'b1000_0000; #1 data = 8'b0; #1 finish; end endmodule After running and simulating this code, printout the results. Provide explanation in a short paragraph (few lines) what this 'while' example did (in the code), based on your output.

Explanation / Answer

After runnig this code i got the following output:

Data=00000011 LOCATION= 0
Data=00000001 LOCATION= 2
Data=00000001 LOCATION= 3
Data=00000001 LOCATION= 7
Data=00000000 LOCATION=32

so lets start with the first if condition, if data is 0 then location 32,as we can see the 5th data value is 0 location is 32.

coming to else part, while loop works as follows:

data[0] means first element of the data if it is 0 the increment location by 1 and perform binary right shift adding 0 to msb of the data say 00000011 >> 1 will give 00000001, this while continues till data[0] is 0.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote