What are the components of a von Neuman machine?
The grouping of the CPU, the cables connecting each item, temp storage, permanent storage, peripherals
Show how to manually convert 14.6 to IEEE hex form.
You should show enough steps to convince the grader that you know the conversion algorithm.
Solution:
14 = 1110
.6 x 2 = 1.2
.2 x 2 = 0.4
.4 x 2 = 0.8
.8 x 2 = 1.6
.6 x 2 = 1.2 <== The pattern has started to repeat.
Therefore 0.6 = .100110011001100110011001 .....
The complete number is 14.6 = 1110.100110011001100110011001 x 2^0
= 1.110100110011001100110011001 x 2^3
Since true exponent is 3 then the stored exponent is 3FF+3 = 402 = 100 0000 0010
First write the answer in binary
0 100 0000 0010 1101 0011 0011 0011 0011 0011 0011......0011
In hex that number is 0x0402 D333 3333 3333
long heat[52]
Use GDB to output the value stored at position 35 as an unsigned integer
p/u heat[35]
Think of a function that is part of a larger program. When that function executes it has its own activation record in memory. What is stored in the initial quadword of that activation record?
“push rbp”
Details: “push rbp” is the first instruction that executes in all asm programs. Why is it the first instruction? Because that statement is initiating a new activation record for the called function.
We say that rbp is the first qword in an AR.
Possible exception: the driver program is called by the loader module of the op system. The driver has its own AR. The first qword in that AR is all zeros.
True or False: since you cannot call strlen, you should count characters as you take them in. Since syscall related strings do not have to be null terminated then to count an already made string then loop through string until you find a newline or null and if neither then there is no reliable way to count the number of characters in that string
true
Counting Characters as You Take Them In:
Syscall-Related Strings:
Counting an Already Made String:
Conclusion:
The statement is true because:
Show how to obtain a random 64-bit value and then normalize that number so that it
becomes an IEEE number in the range 1.0<= number < 2.0.
stored exponent 3ff = 1.0 < = x < 2.0
rdrand r15 ;get random number
shl r15, 12 ;remove stored exponent and signed bit
shr r15, 12 ;set stored exponent and signed bit to 0
mov r8, 0x3FF0 0000 0000 0000 ;mask with what to replace 0s you added in previous instruction with 3ff
or r15, r8 ;original bit or 0 = original bit adds 3FF to beginning of r15 first 12 bits
Convert 123.9 to an IEEE754 number. Show sufficient steps to convince the grader that you know how the conversion algorithm works.
Answer: We start with 123 and divide by 2:
123/2 = 61R1
61/2 = 30R1
30/1 = 15R0
15/2 = 7R1
7/2 = 3R1
3/2 = 1R1
1/2= 0R1
When the quotient is zero we stop
Therefore, 123 = 1111011
Now multiply .9 by 2
.9 x 2 = 1.8
.8 x 2 = 1.6
.6 x 2 = 1.2
.2 x 2 = 0.4
.4 x 2 = 0.8
.8 x 2 = 1.6
.6 x 2 = 1.2
This sequence has begun to repeat.
Therefore, 123.9 = 1111011 . 111001100110011001100 …. x 2^0
Restructure that number to be a scientific binary number:
123.9 = 1 . 1110 1111 1001 1001 1001 1001 100 …. x 2^6
//Spaces added for easier readability
Next add 1023 + 6 to get 0x405
Now layout the complete number in binary groups of 4 bits per group. Begin with the sign bit.
0100 0000 0101 1110 1111 1001 1001 1001 1001 1001 1001 ….1001 1001 1
Bits in yellow are outside the register.
Round that answer to the nearest binary number and truncate the excess bits.
0100 0000 0101 1110 1111 1001 1001 1001 1001 1001 1001 ….1010
which equals 0x405E F999 9999 999A
The number in blue is the final correct answer.
city db “Garden Grove is friendly”,0
What is the GDB command that will change the ‘G’ of “Garden” to ‘W’.
set ((char*)&city)[0]=’W’
need call code(are you writing to or taking from or something else), file descriptor(where to write to or take from (source)), address for output or input(destination), number of characters for input or output
which registers hold these
rax->call code
rdi ->file descriptor (source)
rsi -> address of where want to input or output (destination)
rdi -> how many characters want to input or output
syscall
There are two computers that have processors with the same number of cores, cache, components, etc.; however, machine one frequency is reported in metric value and the other is in binary value. Which is faster?
Processor #1 = 2.00GHz (binary based on powers of 2)
Processor #2 = 2.12GHz (metric based on powers of 10)
Hints:
binary→1 KHz = 2^10HZ, 1 MHz = 2^10KHz, 1 GHz = 2^10 MHz
metric→ 1 KHz = 10^3HZ, 1 MHz = 10^3KHz, 1 GHz = 10^3 MHz
convert both to the same unit so Hz
Processor #1 = 2GHz = 2x2^10 MHz = 2x2^10x2^10 KHz =
= 2x2^10x2^10x2^10Hertz = 2^31Hertz
= 2147483648 Hertz (last step by calculator)
Processor #2 = 2.12 GHz = 2.12x10^3x10^3x10^3 Hertz
=2.12 x 10^9 = 2 120 000 000 Hertz
Processor #1 has a slightly higher frequency that processor #2.
Consider this number which is exceedingly close to zero: 13.0 x 2^(-1028) Find the IEEE754 numeric representation of this number.
Answer:
This number has the feeling of a subnormal number, and in a minute we will have evidence to back up that supposition.
Our number = 1101.0 x 2 ^ (-1028) = 0.001101 x 2^(-1022)
The number in green is in standard subnormal format. Therefore, the hidden bit is clearly seen to be zero and it is easy to write the number in IEEE754 format.
0000 0000 0000 0011 0100 0000 0000 0000 0000 ….etc…. 0000
which equals 0x0003 4000 0000 0000
The number in yellow is the one that counts.
Here is output created by gdb. What gdb command could have created this output?
0x7fffffffde70: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7fffffffde78: 0xb3 0x60 0xde 0xf7 0xff 0x7f 0x00 0x00
0x7fffffffde80: 0x20 0xc6 0xff 0xf7 0xff 0x7f 0x00 0x00
0x7fffffffde88: 0x68 0xdf 0xff 0xff 0xff 0x7f 0x00 0x00
0x7fffffffde90: 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x00
0x7fffffffde98: 0x96 0x11 0x40 0x00 0x00 0x00 0x00 0x00
0x7fffffffdea0: 0x10 0x16 0x40 0x00 0x00 0x00 0x00 0x00
0x7fffffffdea8: 0x7a 0x64 0x4e 0xd9 0x7e 0x0d 0x3a 0x84
0x7fffffffdeb0: 0xb0 0x10 0x40 0x00 0x00 0x00 0x00 0x00
0x7fffffffdeb8: 0x60 0xdf 0xff 0xff 0xff 0x7f 0x00 0x00
0x7fffffffdec0: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7fffffffdec8: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7fffffffded0: 0x7a 0x64 0x4e 0x64
hex output = /x
each hex value is 4 bits so 0xBB is 8 bits or 1 byte = /b
there are 100 of these 0xBBs = /100
starting address is 0x7fffffffde70 as it is the smallest address there
Answer: x/100xb 0x7fffffffde70
8. Here is a memory dump made during the run of a program. Separate the activation records
Offset Address Value
+480 00007fff9a5122e0 0000000000000000
+472 00007fff9a5122d8 00007fff9a512380
+464 00007fff9a5122d0 0000000000401070
+456 00007fff9a5122c8 107a4d83db79292f
+448 00007fff9a5122c0 0000000000401900
+440 00007fff9a5122b8 0000000000401156
+432 00007fff9a5122b0 0000000100011c00
+424 00007fff9a5122a8 00007fff9a512388
+416 00007fff9a5122a0 00007fb3c0345b80
+408 00007fff9a512298 00007fb3c017d083
+400 00007fff9a512290 0000000000000000
+392 00007fff9a512288 0000000000000000
+384 00007fff9a512280 000000000000000a
+376 00007fff9a512278 0000000000000010
+368 00007fff9a512270 0000000000000000
+360 00007fff9a512268 0000000100401900
+352 00007fff9a512260 00007fff9a512388
+344 00007fff9a512258 00000000004011ac
+336 00007fff9a512250 00007fff9a512290
+328 00007fff9a512248 4b5c0f18727e9800
+320 00007fff9a512240 fffffffffffffff7
+312 00007fff9a512238 ffffffffffffffff
+304 00007fff9a512230 0000000000000003
+296 00007fff9a512228 0000000000000020
+288 00007fff9a512220 0000000000000000
+280 00007fff9a512218 0000000000401252
+272 00007fff9a512210 00007fff9a512250
+264 00007fff9a512208 0000000000d6a2c0
+256 00007fff9a512200 fffffffffffffffe
+248 00007fff9a5121f8 00000000004012fb
+240 00007fff9a5121f0 00007fff9a512210
+232 00007fff9a5121e8 4b5c0f18727e9800
+224 00007fff9a5121e0 0079616468747269
+216 00007fff9a5121d8 4220797070614810
+208 00007fff9a5121d0 fffffffffffffffd
+200 00007fff9a5121c8 fffffffffffffffe
+192 00007fff9a5121c0 ffffffffffffffff
+184 00007fff9a5121b8 400c000000000000
+176 00007fff9a5121b0 00000000004013d3
+168 00007fff9a5121a8 0000000000000005
+160 00007fff9a5121a0 0000000000000002
+152 00007fff9a512198 fffffffffffffffd
+144 00007fff9a512190 00007fb3c0346788
+136 00007fff9a512188 00000000004013dc
+128 00007fff9a512180 00007fff9a5121f0
+120 00007fff9a512178 0000000000401900
+112 00007fff9a512170 0000000000401900
+104 00007fff9a512168 00007fb3c0267077
+96 00007fff9a512160 000000000000001a
+88 00007fff9a512158 0000000000000191
+80 00007fff9a512150 0000000000000002
+72 00007fff9a512148 000000000000002d
+64 00007fff9a512140 000000000000005a
+56 00007fff9a512138 00000000004021fb
+48 00007fff9a512130 0000000000000246
+40 00007fff9a512128 0000000000401070
+32 00007fff9a512120 00007fff9a512380
+24 00007fff9a512118 0000000000000000
+16 00007fff9a512110 0000000000000000
+8 00007fff9a512108 0000000000000246
+0 00007fff9a512100 ffffffffffffff9d
-8 00007fff9a5120f8 000000000040182b
-16 00007fff9a5120f0 00007fff9a512180
-24 00007fff9a5120e8 00000000000001f4
Offset Address Value
+480 00007fff9a5122e0 0000000000000000
+472 00007fff9a5122d8 00007fff9a512380
+464 00007fff9a5122d0 0000000000401070
+456 00007fff9a5122c8 107a4d83db79292f
+448 00007fff9a5122c0 0000000000401900
+440 00007fff9a5122b8 0000000000401156
+432 00007fff9a5122b0 0000000100011c00
+424 00007fff9a5122a8 00007fff9a512388
+416 00007fff9a5122a0 00007fb3c0345b80
+408 00007fff9a512298 00007fb3c017d083
+400 00007fff9a512290 0000000000000000
+392 00007fff9a512288 0000000000000000
+384 00007fff9a512280 000000000000000a
+376 00007fff9a512278 0000000000000010
+368 00007fff9a512270 0000000000000000
+360 00007fff9a512268 0000000100401900
+352 00007fff9a512260 00007fff9a512388
+344 00007fff9a512258 00000000004011ac
+336 00007fff9a512250 00007fff9a512290
+328 00007fff9a512248 4b5c0f18727e9800
+320 00007fff9a512240 fffffffffffffff7
+312 00007fff9a512238 ffffffffffffffff
+304 00007fff9a512230 0000000000000003
+296 00007fff9a512228 0000000000000020
+288 00007fff9a512220 0000000000000000
+280 00007fff9a512218 0000000000401252
+272 00007fff9a512210 00007fff9a512250
+264 00007fff9a512208 0000000000d6a2c0
+256 00007fff9a512200 fffffffffffffffe
+248 00007fff9a5121f8 00000000004012fb
+240 00007fff9a5121f0 00007fff9a512210
+232 00007fff9a5121e8 4b5c0f18727e9800
+224 00007fff9a5121e0 0079616468747269
+216 00007fff9a5121d8 4220797070614810
+208 00007fff9a5121d0 fffffffffffffffd
+200 00007fff9a5121c8 fffffffffffffffe
+192 00007fff9a5121c0 ffffffffffffffff
+184 00007fff9a5121b8 400c000000000000
+176 00007fff9a5121b0 00000000004013d3
+168 00007fff9a5121a8 0000000000000005
+160 00007fff9a5121a0 0000000000000002
+152 00007fff9a512198 fffffffffffffffd
+144 00007fff9a512190 00007fb3c0346788
+136 00007fff9a512188 00000000004013dc
+128 00007fff9a512180 00007fff9a5121f0 <==Points to backend of previous AR
+120 00007fff9a512178 0000000000401900
+112 00007fff9a512170 0000000000401900
+104 00007fff9a512168 00007fb3c0267077
+96 00007fff9a512160 000000000000001a
+88 00007fff9a512158 0000000000000191
+80 00007fff9a512150 0000000000000002
+72 00007fff9a512148 000000000000002d
+64 00007fff9a512140 000000000000005a
+56 00007fff9a512138 00000000004021fb
+48 00007fff9a512130 0000000000000246
+40 00007fff9a512128 0000000000401070
+32 00007fff9a512120 00007fff9a512380
+24 00007fff9a512118 0000000000000000
+16 00007fff9a512110 0000000000000000
+8 00007fff9a512108 0000000000000246
+0 00007fff9a512100 ffffffffffffff9d <==Top of stack
-8 00007fff9a5120f8 000000000040182b
-16 00007fff9a5120f0 00007fff9a512180
-24 00007fff9a5120e8 00000000000001f4
create a loop counts the number of 1 bits in r10.
xor r12,r12
xor rcx,rcx
mov r8,2
mov rax, r10
repeat:
cmp rcx, 63
jg finish
div r8
add r12,rdx
inc rcx
jmp repeat:
finish:
;End of block
In r12 there are 64 bits 64<-0 left to right. You want to change bits at positions 14, 13, and 12 to 010 while the other bits must stay the same. What bitwise operations do you do in order to accomplish your goal?
reminder:
original bit and 0 = 0
original bit and 1 = no change in original bit
original bit or 0 = no change in original bit
original bit or 1 = 1
original bit xor 0 = no change in original bit
original bit xor 1 = original bit flips
your goal is
60-63(same) ... 36-39(same), 32-35(same), 28-31(same)... 12-15(12,13,14 should be same010),8-11(same), 4-7(same), 0-3(same)
original bit and 1 = original bit
mask = 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1??? 1111 1111 1111
question mark is goal is 010 what should you put there so the and will work?
original bit and 0 = 0
so bits 12 and 14 can be 0s and we don't know how to get a 1 using and so we will make it a 0 because it doesn't matter
mask = 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1000 1111 1111 1111
and original and mask to get original bits in all positions and 000 in 12, 13, and 14
we need a 1 in 13, how do you get a 1? we know original bit or 1 = 1. great but the other bits need to stay the same so is there a way to keep all other bits the same with an or? original bit or 0 = no change in original bit. wonderful!! so we make a new mask to or with
mask2 = 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0010 0000 0000 0000
all in all
r12 and mask1
r12 or mask2
our solution : )
Convert the number 0x0000 0448 0000 0000 to decimal floating point.
Clearly this is a subnormal number. Therefore, the rules of subnormal apply. That tells us the hidden bit is zero, and the base number is the true exponent. Let’s write all of that information numerically:
The number is 0.0000 0000 0100 0100 1000 0000 0000 ….. 0000 x 2-1022.
Now shift the point to the right 17 places to get a new expression for the same number:
10001001 x 2-1039 = 137 x 2-1039.
This cannot be simplified further using only manual techniques. Therefore, the answer is 137 x 2-1039
How do you print all values in an activation record in hex formatted quadwords or 64 bits
figure out the size of activation record by subtracting rbp and rsp
($rbp-$rsp)
divide by your data size +1 so quadwords are 64 bits=8bytes so each output should be 8 bytes
($rbp-$rsp)/8
p automatically stores value to variable and need the base ten version of that number in order to use with x command = /d
p/d ($rbp-$rsp)/8
output $1=17
use x because we are printing multiple values format is x/<amount want to print><format you want to print in><data type size printing> we want
we want 17 values each in hex format(x) each being 64 bits(g) from $rsp as starting address
x/$1xg $rsp
Declare the string “Happy Birthday Chris Sawyer” in the data segment.
Output that string in the text segment using a syscall.
write to stdout file "Happy Birthday Chris Sawyer"
birthday db “Happy Birthday Chris Sawyer”
mov rax, 0 ;0 = write
mov rdi, 1 ;1 = stdout
mov rsi, birthday ;birthday = address of the first char of the string
mov rdx, 27 ;27 = string length
syscall
P2. Suppose a large integer such as 750 500 000 000 is stored in r14. You wish to compute 8209/7 of that large integer using only integer arithmetic instructions. Write a fragment of assembly code showing how to do it. Leave the final answer in r15.
mov rax, r14 ; Move the value of r14 (750 500 000 000) into rax. ; This is required because division (idiv) and multiplication (imul) ; use rax as the implicit accumulator register.
cqo ; Sign-extend the value in rax into rdx:rax. ; This is necessary before performing signed division (idiv), ; as idiv uses both rdx and rax as the dividend. ; Although not strictly necessary before imul in this case, ; cqo is used here to ensure that rdx is correctly set to match ; the sign of the value in rax. This avoids any unintended side effects ; if subsequent operations (like idiv) rely on a consistent rdx value.
mov rbx, 8209 ; Load the numerator multiplier (8209) into rbx. ; rbx will be used as the source operand for the multiplication.
imul rbx ; Multiply rax by rbx, placing the result in rax. ; This computes 750 500 000 000 × 8209 and stores the result in rax. ; The high-order bits of the result are stored in rdx,
mov rbx, 7 ; Load the divisor (7) into rbx. ;rbx will now be used as the divisor for the signed division.
idiv rbx ; Perform signed division of rdx:rax by rbx. ; This computes (750 500 000 000 × 8209) ÷ 7. ; The quotient is stored in rax (desired result), ; and the remainder is stored in rdx (not needed here).
mov r15, rax ; Move the result (quotient) from rax into r15. ; This stores the final answer in r15 as required.
How many floating point numbers are there between 18.0 and 19.0 in a 64-bit machine?
18.0 = 10010
19.0 in binary 10011
normal converting decimal to ieee
1.0010 * 2^4 = 18.0
1.0011 * 2^4 = 19.0
the rest of the mantissa can be anything how many of those anything 0 or 1s are there?
12 bits for signed bit with stored exponent
4 bits either 0010 or 0011 are set (if one was larger pick the larger one like 2^6 instead of 2^4 pick the larger 2^6 because then 6 bits are set but here both 2^4 is fine)
64 bit number - 12 - 4 = 48
2^48 different options so 2^48 possible numbers between 18.0 and 19.0
if signed value then there is a range positive numbers 2^(n-1)-1 and negative numbers -2^(n-1) where n is the number of bits you have for example 1 byte can hold numbers -2^(48-1) to +(2^(48-1))-1
all in all 2^48