UW-Madison
Computer Sciences Dept.

CS/ECE 552 Introduction to Computer Architecture


Spring 2012 Section 1
Instructor David A. Wood and T. A. Ramkumar Ravikumar
URL: http://www.cs.wisc.edu/~david/courses/cs552/S12/

Project Miscellanea



How should I interpret immediate and displacement field for branch instructions? Should I shift left by 1?

Clarification on the immediate field for branch instructions (beqz, bnez, j, jr, jal, jalr)

You MUST NOT shift the immediate field by 1. I know this is slightly counter-intuitive, but the simulator already implements this semantics and these are semantics in the ISA spec. so we will stick with it.

For example, see beqz_0.asm:

lbi r0, 0

beqz r0, 4

lbi r0, 1

lbi r1, 1

lbi r2, 1

lbi r3, 1

Its .lst file:

0000 c000 lbi r0, 0

0002 6004 beqz r0, 4

0004 c001 lbi r0, 1

0006 c101 lbi r1, 1

0008 c201 lbi r2, 1

000a c301 lbi r3, 1

The conditional branch is taken and PC will be set to:

0x0002 + 2 + 4 == 0x0008

NOT 0x0002 + 2 + (4 << 1) == 0x000C

Similar semantics applies for all conditional and unconditional branches.

If your immediate or displacement field in the assembly program ends up being an odd number, then you will get an unaligned access error from the simulator and from the memory module.





 
Computer Sciences | UW Home