Why do you shift the Segment Register ( MEM[GPR + disp32 + SegR<<16] ) ?
We always use 32-bit addressing, never 16-bit addressing.
We also simplify x86 memory addressing by avoiding the GDT. Any time
an instruction accesses memory, you have to build the address based on
base+displacement as specified in the Mod R/M byte of the instruction,
and add the Segment Register shifted 16 bits. The Segment Register is
always DS unless the stack is being accessed (e.g., push and pop
instructions or any other instruction using EBP or ESP as the base
register) in which case SS is the default. Note that the default
Segment Register can also be overridden with a specific instruction
prefix (not used in this problem set).
What is register transfer notation? So are you looking for something like:
ADD (opcode 81 /0 id): ADD r/m32, imm32
r/m32 <- r/m32 + imm32
Use GPR
or MEM
instead of r/m32
. Thus, in this example:
MEM[GPR + SegR<<16] <- MEM[GPR + SegR<<16] + imm32
GPR <- GPR + imm32
MEM[GPR + disp32 + SegR<<16] <- MEM[GPR + disp32 + SegR<<16] + imm32
MEM[GPR + SEXT(disp8) + SegR<<16] <- MEM[GPR + SEXT(disp8) + SegR<<16] + imm32
MEM[disp32 + SegR<<16] <- MEM[disp32 + SegR<<16] + imm32
GPR
stands for General Purpose Register, SegR
stands for Segment Register
and MEM
stands for Memory.
Do we need to consider prefixes for Homework 2?
No. You do not need to worry about any instruction that has a prefix in its x86 representation.
Do we need to build a decoder or cache for Homework 2?
Not required for Homework 2. Please start from a basic data path. You can add your modules step by step.
Do we need to account for instructions with 8-bit displacements (mode 01)?
Yes, because the operand size is 32 bits (the 8-bit displacement is used for address generation).
Do we need to do JMP rel8
(EB cb
) and ADD AL,imm8
(04 ib
)?
JMP rel8
uses a 32-bit register, but ADD AL, imm8
uses an 8-bit register, so you need to
implement JMP rel8
but not ADD AL, imm8
.
Do we need to do JMP rel16
(E9 cw
)?
JMP rel16
requires an operand size override prefix; thus you
do not need to implement it.
Do we have to do the move to and move from segment register
instructions, such as MOV r/m16, Sreg
and MOV Sreg, r/m16
?
No.
Do we need to do the far jump instructions?
You are required to implement only JMP ptr16:32
for Homework 2. Since
JMP ptr16:16
needs an operand size override prefix, you will implement it
later. You do not need to implement JMP m16:16
and JMP m16:32
.
Do we need to do the moves which take moffs?
You do not need to implement those move variations.
Do we need to implement flags ?
Yes.
If the instruction is OP r32, r32, how do we know which of the registers is represented by the mod r/m bits and which is represented by the middle 3 reg bits?
Chapter two of the second manual discusses this.
A far jump requires us to change the value in CS register. Does this have to be handled for this assignment?
Yes.