当前位置:网站首页>[CSAPP] Application of bit vectors | encoding and byte ordering

[CSAPP] Application of bit vectors | encoding and byte ordering

2022-07-27 05:19:00 Lemon leaf C

One w-bit The vector can be expressed as   \left \{ {0, . . . , w-1} \right \} . use 8-bit The binary code represents each given two unsigned integers , That's one 8-bit Vector , Then calculate the intersection of these two sets 、 Union and symmetric difference . The elements of this set are  \left \{ {0, . . , 7} \right \} . Each element corresponds in ascending order starting from the position on the left .

a)   Let DEC 28 = BIN 00011110 is A

      Let DEC 64 = BIN 01000000 is B

      Then, translated by bit vector, we can get  A = \left \{ 2,3,4 \right \}    B = \left \{ 6 \right \} ,so that

      A\cup B=\left \{ 2,3,4,6 \right \}      (intersection)

      A\cap B=\O       (union)

      A\oplus B=\left \{ 2,3,4,6 \right \}        (symmetric difference)

b)  Same Way,  Let DEC 63 = BIN 00111111 is A

      Let DEC 112 = BIN 01110000 is B

      Then,  A = \left \{ 0,1,2,3,4,5,6 \right \}    B = \left \{ 6 \right \} ,so that

      A\cup B=\left \{ 0,1,2,3,4,5,6 \right \}     (intersection)

      A\cap B=\left \{ 4,5 \right \}      (union)

      A\oplus B=\left \{ 0,1,2,3,6 \right \}     (symmetric difference)

 

Hypothetical variables x and y The types of are int and short.x The address for 0x100,y The address for 0x200.x Four bytes of will be stored in memory location 0x100、0x101、0x102 and 0x103 It's about .y Two bytes of will be stored in memory location 0x200 and 0x201 It's about .x The value of is 27066166,y The value of is 41797. If we were to x and y Stored in the small end and the large end respectively , So what values are stored in a given memory range ?( In hexadecimal notation ).

x_{DEC} = 27066166,x_{HEX} = 19C FF 36

y_{DEC} = 41797,y_{HEX} = A3 45

Little endian:36 FF 9C 01  ...  45 A3

Big endian  : 01 9C FF 36  ...  A3 45

a)

1. The preprocessor modifies the original C program according to directives that begin with the # character, and deletes the comments. The result is another C program with the .i suffix.

2. The compiler translates the text file hello.i into the text file hello.s, which contains an assembly-language program. Each statement in an assembly-language program exactly describes one low-level machine-language instruction.

3. The assembler translates hello.s into machine-language instructions, packages them in a form known as a relocatable object program. The result is stored as object file hello.o.

4. A program can call a function resides in a separate precompiled object file. The linker handles this merging, and the executable object file hello is the final output.
 

b) 

High-level programming languages and compilers provide an abstraction for application developers without the need to know internally complex machine-level code

a) Registers are a type of computer memory used to quickly accept, store, and transfer data and instructions that are being used immediately by the CPU.

b) The main memory is a temporary storage device that holds both a program and the data it manipulates while the processor is executing the program.

c) The L1 and L2 caches serve as temporary staging areas for information that the processor is likely to need in the near future. So, the processor can read data faster.

Convert the following decimal numbers into 8-bit Unsigned binary number and corresponding hexadecimal number , If unable to convert , Write it down as X.

a) 0        b) 255        c) 256        d) 100

a)  00000000, 00

b)  255 = 2^7+2^6+...+2^0 , 11111111 , FF

c)  256 = 2^8 ,  X

d)  100 = 2^6 + 2^5+2^2 ,  01100100 , 64

A given 32 Bit binary code represents string or integer ( Use binary complement ). If the hexadecimal representation of each byte is in the following conversion table , The given code is a string ; Otherwise, it is an integer . Write down the string or integer of each binary code .( From left to right ) Example .

a) 45 53 4E 47, ESNG

b) 74 21 33 2e, t!3.

c) FF FF FF D4, -44

d) 00 01 57 A6, 87974

a)   211 + 240 = 451,384 + 247 = 631

451<2^x-1<631,x=9

b)for unsigned integer representation,0\leq 3x\leq 2^4-1,0\leq x\leq 5

two's complement encoding integer representation,-2^3 \leq 3x\leq 2^3-1,-2\leq x\leq 2


原网站

版权声明
本文为[Lemon leaf C]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/200/202207180333227510.html