Chapter 3 - Machine-Level Representation of Programs Flashcards
What register is used to store where a computer is in its program sequence?
The program counter register, %rip.
Which register is associated with the program counter?
%rip.
How many locations are there in a typical modern integer register file?
16 registers.
How many bits of information can each register in the register file hold?
64 bits.
What program can be used on a Linux system to view the assembly code of a given object file?
objdump.
What term is given to the class of programs used to inspect the contents of machine-code files?
Disassemblers.
What command can be used to generate a file containing the assembly-level version of the source file prog.cc?
g++ -Og -S prog.cc
Using g++, a source file is translated into both assembly code (with the -S flag) and an executable (with the -o flag). What is likely to be the most noticeable difference after dumping the contents of the generated files? (Either using ‘objdump’ or ‘cat’.)
The offset in the address.
How does the Intel format differ from the ATT format?
- Intel code omits size designation suffixes (i.e. push not pushq).
- Intel code omits the ‘%’ character in front of register names.
- Intel code describes memory locations differently (e.g. QWORD PTR [rbx] rather than (%rbx)).
- Intel code lists operands in reverse order to ATT code.
State the number of bytes taken to represent the following data types: char short int long char* float double
char -- 1 short -- 2 int -- 4 long -- 8 char* -- 8 float -- 4 double -- 8
How many registers did the original 8086 processor have and what size data could they contain?
There were eight 16-bit registers.
How many registers did the IA32 processor have and what size data could they contain?
There were eight 32-bit registers.
How many registers does the x86-64 processor have and what size data can it contain?
There are 16 64-bit registers.
What labels did the registers in the original 8086 processor have?
There were eight registers labelled %ax through to %sp.
What labels did the registers in the IA32 processor have?
There were eight registers labelled %eax through to %esp.
What labels do the registers of the x86-64 processor have?
There are 16 registers; the first eight registers are labelled %rax through to %rsp, and the other eight are labelled %r8 through %r15.
When instructions have registers for destinations, what happens to the remaining bytes when the instructions generate size 1, 2 or 4-byte values?
When 1 and 2-byte values are generated, the remaining bytes in the register are left untouched.
When 4-byte values are generated, the high-order 4 bytes are set to zero.
Which register is associated with the stack pointer?
%rsp.
What suffixes are used in integer instructions to indicate the size of the operand?
1-byte = 'b' 2-byte = 'w' 4-byte = 'dw' 8-byte = 'qw'
What is the syntax for providing an immediate value as an operand to an assembly instruction?
The given value is preceded by the $ character.
What is the general syntax for providing a memory location as an operand to an assembly instruction?
The syntax has the form Imm(rb,ri,s).
An assembly instruction is given “Imm(rb,ri,s)” as an operand. Describe what this operand represents.
Imm(rb,ri,s) corresponds to the byte at the memory location:
M[ Imm + R[rb] + R[ri] * s ]
The individual terms are: Imm = Immediate offset R[rb] = Base register R[ri] = Index register s = scaling index
What are the three main types of operands supplied to assembly instructions?
Immediate, register and memory.
Assume the following values are stored at the indicated memory addresses and registers:
Address Value 0x100 0xFF 0x104 0xAB 0x108 0x13 0x10C 0x11
Register Value
%rax 0x100
%rcx 0x1
%rdx 0x3
What are the values of the following operands?
260(%rcx,%rdx)
0xFC(,%rcx,4)
(%rax,%rdx,4)
260(%rcx,%rdx) = M[0x108] = 0x13.
0xFC(,%rcx,4) = M[0x104] = 0xFF.
(%rax,%rdx,4) = M[0x10C] = 0x11.