In: Computer Science
Question 1)
Given the byte value:
0xad
a) What is the equivalent decimal notation as an unsigned value?
b_ What is the equivalent decimal notation as a signed value?
Question 2)
Below are integer values and the location where each is stored,
which may be an address in memory or a register:
Value Location
0xc 0x130
0x82 0x134
0x5 %rdi
0x134 %rsi
What are the values of the following operands? You may answer in
decimal or hexadecimal, but if you answer in hexadecimal, you must
use the "0x" prefix:
Operand:
a) %rsi
b) (%rsi)
c) 20(%rsi,%rdi,4)
Question 3)
Assume that a variable "x" exists and its address is stored in
%rdx.
For each specification below, write an assembly instruction that
copies the value of variable "x" to the %rax/eax register.
a. Data type of "x": unsigned int
b. Data type of "x": unsigned long
Question 4)
Below are values that are stored in memory or registers, as
noted:
value address/register
0x11 0x130
0x13 0x138
0xab 0x140
0xff 0x148
0x138 %rsi
0x3 %rcx
0x1 %rdx
Compute the result, in hexadecimal, of each of the following
assembly instructions and note the location where each result will
be stored:
subq %rcx, 8(%rsi)
a) Result (answer below):
b) Location:
incq %rdx
a) Result (answer below):
b) Location:
1)
Hexadecimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
Use this table to convert from hexadecimal to binary
Converting AD to binary
A => 1010
D => 1101
So, in binary 0xAD is 10101101
a)
=> 10101101
=> 1x2^7+0x2^6+1x2^5+0x2^4+1x2^3+1x2^2+0x2^1+1x2^0
=> 1x128+0x64+1x32+0x16+1x8+1x4+0x2+1x1
=> 128+0+32+0+8+4+0+1
=> 173
Answer: 173
b)
since left most bit is 1, this number is negative number.
so, follow these steps below to convert this into a decimal value.
I. first flip all the bits. Flip all 0's to 1 and all 1's to 0.
10101101 is flipped to 01010010
II. Add 1 to above result
01010010 + 1 = 01010011
III. Now convert this result to decimal value
=> 1010011
=> 1x2^6+0x2^5+1x2^4+0x2^3+0x2^2+1x2^1+1x2^0
=> 1x64+0x32+1x16+0x8+0x4+1x2+1x1
=> 64+0+16+0+0+2+1
=> 83
Answer: -83
