This assignment has a written part and a programming part, both relating to x86-64 assembly programming.
New: detailed notes to help with problem 2 (and 1d).
Please type your answers to the written problems and save them in PDF format in a file hw4_written.pdf. Hint: Read BO chapter 3. Some of the problems below are similar to the practice problems you'll find there.
Address Value Register Value 0x200 0xAB %rax 0x200 0x208 0xCD %rcx 0x1 0x20C 0x15 %rdx 0x13 0x214 0x42Fill in the following table showing the values for the indicated operands in hex.
Operand Value %rax _________ 0x208 _________ $0x20c _________ (%rax) _________ 12(%rax) _________ 7(%rax, %rcx) _________ 512(%rcx, %rdx) _________ 0x1FC(, %rcx, 4) _________ (%rax, %rcx, 8) _________
Suppose register %rax holds value x and %rcx holds value y. Fill in the table below with formulas indicating the value that will be stored in register %rdx for each of the given assemby code instructions.
Instruction Result leaq 3(%rax), %rdx __________ leaq (%rax, %rcx), %rdx __________ leaq (%rax, %rcx, 8), %rdx __________ leaq 7(%rax, %rax, 4), %rdx __________ leaq 0xF(, %rcx, 2), %rdx __________ leaq 1(%rcx, %rax, 4), %rdx __________
Address Value Register Value 0x200 0xAB %rax 0x200 0x208 0xCD %rcx 0x1 0x210 0x15 %rdx 0x3 0x218 0x42Fill in the following table showing the effects of the following instructions, in terms of both the register or memory location that will be updated and the resulting value (in hex).
Instruction Destination Value addq %rcx, 8(%rax) _________ _________ subq %rdx, (%rax) _________ _________ imulq $16, (%rax, %rdx, 8) _________ _________ decq 16(%rax) _________ _________ incq %rcx _________ _________ shrq $2, %rax _________ _________
movq SrcReg, DstRegwhere SrcReg and DstReg each are one of the first eight 64-bit registers (%rax, %rbx, %rcx, %rdx, %rsi, %rdi, %rbp, or %rsp).
To do this, create an assembly file, say movqtest.s, containing many instructions like
movq %rax, %rbxthen assemble the program into object code (gcc -c movqtest.s), then disassemble it to see the hexadecimal encoding (objdump -d movqtest.o).
(1) Identify the bit patterns used to encode each of the 8 registers:
%rax = _____ %rbx = _____ %rcx = _____ %rdx = _____ %rsi = _____ %rdi = _____ %rbp = _____ %rsp = _____(2) Write down the complete opcode for "movq SrcReg, DstReg" in binary, using "S" and "D" as placeholders for the bits encoding the two registers. Group binary digits in groups of 4 for readability. For instance, if the opcode was two bytes long and each register was represented using 4 bits (hint: not true), your answer might look like this:
11SS SS00 0DDD D101Answer: ______________________________________________
Write x86-64 assembly functions that take two long int arguments a and b and return
I'm providing a skeleton hw4asm.s. In it, complete the assembly functions "avg", "max", "maxabs", "sumseq", and "countbits". I'm also providing a driver program named hw4main.c to call your functions and print their results. You can find both files in my directory ~schar/cs202/hw4/.
Upload your files hw4_written.pdf and hw4asm.s using the HW 4 submission page by the beginning of your class section on the due date. As always, make sure your files contain your name and section, and that all your code is properly documented.