In: Electrical Engineering
In assembly
1.What is the effect of the following instructions executing on a modern x86 64-bit system (describe what happens and the final contents of the registers involved)? Can you obtain the same end result using only two instructions, and no other registers?
PUSH RAX
PUSH RBX
PUSH RCX
XOR RAX,RAX
XOR RBX,RBX
XOR RCX,RCX
POP RAX
POP RAX
POP RBX
2. What is the purpose of a segment register in protected mode memory addressing?
3. For a 32-bit Pentium4 descriptor that contains a base address of 01000000H, a limit of 0FFFFH, and G=0, what starting and ending locations are addressed by it? (also see Segmentation and Pagination Diagrams in BlackBoard, Other Reference Materials).
4. If DS=0105H in protected mode, which descriptor entry, table, and RPL are selected? (also see Segmentation and Pagination Diagrams in BlackBoard, Other Reference Materials).
5. What is the purpose of the TLB located within the Pentium class microprocessor?
Sol 1.
Lets analyze the instructions step by step
"PUSH RAX" => it will push or copy the 64 bit contents of AX
register to top of stack memory
"PUSH RBX" => it will push the contents of BX register to the new stack top
"PUSH RCX" => it will push the contents of CX register to the new stack top
Now, the stack has the 64 bit values of CX, BX and AX in order from top to bottom.
The XOR function is used here to clear the contents of the registers used. When we XOR a binary number with itself, the result is always 0.
So, the next three instructions will set registers AX, BX and CX to 0.
The "POP" instruction will extract the 64 bit value from top of the stack memory and move it to the following register. After POP instruction, the Stack Pointer will move to the next 64 bit value.
"POP RAX" this instruction will take the contents of top of stack memory (CX) and move it to AX register.
"POP RAX" this will now take the next value from stack (BX) and move it to AX register.
"POP RBX" this will move the next value in stack (AX) and move it to BX register.
Now, the contents of AX register are stored in BX and
the contents of BX register in AX.
Essentially, the program swaps the values of AX and BX registers and clears the value of CX register
This program in assembly can be reduced to two instrcutions :
XCHG RAX,RBX ; exchange 64 bit values of AX and BX registers
XOR RCX,RCX ; clear CX register to 0