Islam CSC342342 TakeHomeTest 1
Islam CSC342342 TakeHomeTest 1
CS342/343
Fall 2023
Instructor: Professor Izidor Gertner
TA: Albi Arapi
Submitted By
Md Wasiul Islam
Date: 11/07/2023
Take Home Test CSC342
(1) We know, Program length (in bytes) = Ending Address – Starting Address
= 0x000000000040158e - 0x0000000000401550
= 0x3E
Converting hex to decimal: 3x16^1 + 15x16^0 = 63 bytes
Therefore, the program length is 63 bytes
(3)
In my architecture, “info register rip” is the gdb command to print the content of the instruction
pointer register. The rip register contains the current value of the instruction pointer, which points
to the address of the currently executing instruction, 0x40155d.
(4)
In my architecture, “info register rbp” is the gdb command to print the content of the base pointer
register. The rbp register contains the current value of the base pointer, which points to the
address, 0x61fe20.
(5)
In my architecture, “info register rsp” is the gdb command to print the content of the stack pointer
register. The rsp register contains the current value of the stack pointer, which points to the
address, 0x61fde0.
(6)
In my architecture, “x/1wx $rbp-4” is the gdb command I used to print the content and the address
of 4-byte word on stack at a offset -4 from base pointer. Here, x is the examine command, /1
specifies that you want to print 1 unit of data, w specifies that the data is in word (4 bytes) format
and $rbp-4 is the memory address calculated as an offset from the base pointer (RBP) minus 4
bytes, which is the typical size of a word.
(7)
In my architecture, “info program” provides information about the program's execution state,
including the current instruction address. Here it shows that the program stopped at 0x40155d,
so this will be next address of instruction that will be executed.
(7.1)
In my architecture, “x/i {address}” is the gdb command to find the machine instruction. Here, “x/i”
allows to examine the machine instruction at the given address, in this case, movl $0xffffffff,-
0x4(%rbp), which is the instruction at the breakpoint.
(9)
In my architecture, “info register” in GDB is used to display the current values of all the general-
purpose and floating-point registers. Here we can see that rbp is pointing to 0x61fe20, which is the
value stored in the base pointer register.
(10) Using the same picture as (9), “info register” in GDB is used to display the current values of all the
general-purpose and floating-point registers. Here, we can see that rsp is pointing to 0x61fde0, which
is the value stored in the stack pointer register.
(11) In order to print out machine instructions at each address, we need to do “x/i <address>”. In the
address space we put in the corresponding address that is listed in our dump assembler code. Here,
In order to print out all the machine instructions at once without repeating the command over and
over again, I have done the following gdb commands,
Here I have set the address to the first address and the loop will stop once it reaches the end
address. Here are my screenshots for the machine instructions of all addresses.
(12) In order to print out the stack starting from the base pointer in gdb, we can use the following
command, “x/gx rbp-0x(some number)” Here in some number, we can put any value and it should
give us the address of a value on the stack based on the base pointer. For example:
I didn’t list everything because we just use similar commands for them.
(12.1) The local variable a is -0x4 in hexadecimal and in decimal it is 4. The offset from base pointer
to the local variable "a" is -0x4, which is the same in hexadecimal representation. So, the hex offset is
also -0x4. Therefore in decimal representation, the offset is -4.