A2 P2 - Random Input Error on LH

117 views
Skip to first unread message

Colin Yuen

unread,
Oct 8, 2020, 2:27:29 PM10/8/20
to cmpt-295-sfu

SFU ID: cya107
Github username: cya107
Line and file: Part2.c - Line 306-312 & 385-408
Expected behavior: Error in Random Test - Instruction 7 (LH)
Observed behavior: Expected no errors & to pass
Question: Ran LocalCI to test, but failed in Random.input, tried to trace the problem and I believe it has issue with LH, not sure what the issue is in LH.

Arrvindh Shriraman

unread,
Oct 8, 2020, 3:54:47 PM10/8/20
to cmpt-295-sfu

Colin Yuen

unread,
Oct 8, 2020, 3:58:08 PM10/8/20
to cmpt-295-sfu
Hi,

I added the sign_extend_number in the load function for each of the different lengths to make it 32 bits. Is that not the correct way to do it?

Arrvindh Shriraman

unread,
Oct 8, 2020, 4:04:14 PM10/8/20
to cmpt-295-sfu
Read the link on how to implement lh and lb.

Colin Yuen

unread,
Oct 8, 2020, 4:19:44 PM10/8/20
to cmpt-295-sfu
Sorry, I still don't understand, please correct me if I'm wrong.

For Load Halfword,
(From the document)
"A 16-bit value is fetched from memory and moved into register RegD. The memory address is formed by adding the offset to the contents of Reg1. The value is sign-extended to the full length of the register."

I get the memory address from [instruciton.itype.R1 + sign_extend(instruction.itype.imm, 12)]
Then from that memory address, I only take the first 16 bits, so when I am doing ORs for my word, I only do the first 8 bits, memory[address + 1] << 8,
At the end of that, I sign extend it back to the full length of the register (32 bits) and return that.
 
I believe that is what I did in my Part2.c Line 395 - 407

Arrvindh Shriraman

unread,
Oct 8, 2020, 4:34:00 PM10/8/20
to cmpt-295-sfu
Include images of your output and mark exactly which register and where in the trace.
Also if your program is stalled, describe how (infinite loop, not run to the end etc).

I was just responding to the fact that you said the error is in LH and I told you what the common issue is.

Colin Yuen

unread,
Oct 8, 2020, 4:41:16 PM10/8/20
to cmpt-295-sfu
Sorry for not being clear.
I haven't run into any infinite loops or seg faults after yesterday's lab (Thanks Minh!)

The solution/reference file is on the left, and my solution is on the right.
At Register 9,
the expected solution was 0xfffff7ff
and my result was: 0x000000ff

Arrvindh Shriraman

unread,
Oct 8, 2020, 5:30:12 PM10/8/20
to cmpt-295-sfu

1. There are many places where load() is used including for reading instructions.
You may not want to sign extend in there but move it to the actual lb and lh instruction.

2. Check your stores; Given that you seem to be reading 7ffs etc. A store error will not reflect in the registers but when you actually read the load like you are doing.

3. use printf statements to check if the MEMORY[] Array holds the correct value (ff) at the load point, if not then your stores are the problem. 

Hope this helps. 

Colin Yuen

unread,
Oct 8, 2020, 6:02:53 PM10/8/20
to cmpt-295-sfu
Thank you for the hints, I'll try my best to debug and see if it is actually my other functions

Colin Yuen

unread,
Oct 8, 2020, 6:25:42 PM10/8/20
to cmpt-295-sfu
Haha, I found my issue, I was missing brackets in some areas. Thanks for the hint about looking at my other functions, cause that was what caused my issues.
Reply all
Reply to author
Forward
0 new messages