In: Computer Science
The following problems deal with sign extension and overflow. Registers X0 and X1 hold the values as shown in the table below. You will be asked to perform LEGv8 operations on these registers and show the result for the contents of A and B in the table 2 following.
A. |
X0 = 0x7000000016 |
X1 = 0x0FFFFFFF16 |
B. |
X0 = 0x4000000016 |
X1 = 0x4000000016 |
Table 2.
ADD X4, X0, X1
SUB X4, X0, X1
ADD X4, X0, X1
ADD X4, X0, X0
Answer is as follows :
We have following 32 bit data stored in registers with capacity of 32 bits. if the result include more than 32 bits it will lead to overflow
A :
X0 = 0x7000000016 i.e. 0111 0000 0000 0000 0000 0000 0000 0000 in binary
X1 = 0x0FFFFFFF16 i.e. 0000 1111 1111 1111 1111 1111 1111 1111 in binary
B :
X0 = 0x4000000016 i.e. 0100 0000 0000 0000 0000 0000 0000 0000 in binary
X1 = 0x4000000016 i.e. 0100 0000 0000 0000 0000 0000 0000 0000 in binary
So Solution for given queries are :
Part I : ADD X4, X0, X1
This instruction Add the contents of register X0 and X1 and store the result to register X4
A) We get 0110 1111 1111 1111 1111 1111 1111 1111 after additon i.e. 0x7FFFFFFF
B) We get 1000 0000 0000 0000 0000 0000 0000 0000 after addition i.e. 0x80000000
In both cases we get the desired result i.e. stored in register X4. So there is not any kind of overflow in A and B.
Part II : SUB X4, X0, X1
This instruction subtract the contents of register X0 from X1 and store the result to register X4
A) We get 0110 0000 0000 0000 0000 0000 0000 0001 after subtraction i.e. 0x60000001
B) We get 0000 0000 0000 0000 0000 0000 0000 0000 after subtraction i.e. 0x00000000
In both cases we get the desired result i.e. stored in register X4. So there is not any kind of overflow in A and B.
Part III:
Instruction 1 : ADD X4, X0, X1
This instruction Add the contents of register X0 and X1 and store the result to register X4
A) We get 0110 1111 1111 1111 1111 1111 1111 1111 after additon i.e. 0x7FFFFFFF
B) We get 1000 0000 0000 0000 0000 0000 0000 0000 after addition i.e. 0x80000000
Instruction 2 : ADD X4, X0, X0
This instruction Add the contents of register X0 and X0 and store the result to register X4
A) We get 1110 1111 1111 1111 1111 1111 1111 1111 after additon i.e. 0xE0000000
B) We get 1000 0000 0000 0000 0000 0000 0000 0000 after addition i.e. 0x80000000
So in this final values of X4 are :
A : 0xE0000000 and B : 0x80000000
In both cases we get the desired result i.e. stored in register X4. So there is not any kind of overflow in A and B.
if there is any query please ask in the comments...