Joseph Haugh
University of New Mexico
C Data Type | Typical 32-bit | Typical 64-bit | x86-64 |
---|---|---|---|
char | 1 | 1 | 1 |
short | 2 | 2 | 2 |
int | 4 | 4 | 4 |
long | 4 | 8 | 8 |
float | 4 | 4 | 4 |
double | 8 | 8 | 8 |
long double | — | — | 10/16 |
pointer | 4 | 8 | 8 |
Decimal: 15213
Binary: 0011 1011 0110 1101
Hex: 3 B 6 D
int b = -15213;
int *p = &b;
typedef unsigned char *pointer;
void show_bytes(pointer start, size_t len) {
size_t i;
for (i = 0; i < len; i++)
printf("%p\t0x%.2x\n", start+i, start[i]);
printf("\n");
}
int a = 15213;
printf("int a = 15213;\n");
show_bytes((pointer) &a, sizeof(int));
int a = 15213;
0x7ffee15d7e8c 0x6d
0x7ffee15d7e8d 0x3b
0x7ffee15d7e8e 0x00
0x7ffee15d7e8f 0x00
int fib(int n)
{
int r = 1;
for (; n > 0; n--) {
r = r * n;
/* Loop decr. */
/* Loop end chk. */
}
return r;
}
Disassembly of section .text:
Address Insn Bytes Assembly Code
40057d: 55 push %rbp
40057e: 48 89 e5 mov %rsp,%rbp
400581: 89 7d ec mov %edi,-0x14(%rbp)
400584: c7 45 fc 01 00 00 00 movl $0x1,-0x4(%rbp)
40058b: eb 0e jmp 40059b <fib+0x1e>
40058d: 8b 45 fc mov -0x4(%rbp),%eax
400590: 0f af 45 ec imul -0x14(%rbp),%eax
400594: 89 45 fc mov %eax,-0x4(%rbp)
400597: 83 6d ec 01 subl $0x1,-0x14(%rbp)
40059b: 83 7d ec 00 cmpl $0x0,-0x14(%rbp)
40059f: 7f ec jg 40058d <fib+0x10>
4005a1: 8b 45 fc mov -0x4(%rbp),%eax
4005a4: 5d pop %rbp
4005a5: c3 retq
p1.c p2.c
gcc -Og p1.c p2.c -o p
long plus(long x, long y);
void sumstore(long x, long y,
long *dest)
{
long t = plus(x, y);
*dest = t;
}
sumstore:
pushq %rbx
movq %rdx, %rbx
call plus
movq %rax, (%rbx)
popq %rbx
ret
gcc -Og -S sum.c
(S means only preprocess and compile)sum.s
sumstore bytes:
0x0400595:
0x53
0x48
0x89
0xd3
0xe8
0xf2
0xff
0xff
0xff
0x48
0x89
0x03
0x5b
0xc3
*dest = t;
movq %rax, (%rbx)
0x40059e: 48 89 03
0000000000400595 <sumstore>:
400595: 53 push %rbx
400596: 48 89 d3 mov %rdx,%rbx
400599: e8 f2 ff ff ff callq 400590 <plus>
40059e: 48 89 03 mov %rax,(%rbx)
4005a1: 5b pop %rbx
4005a2: c3 retq
objdump –d sum
Object:
0x0400595:
0x53
0x48
0x89
0xd3
0xe8
0xf2
0xff
0xff
0xff
0x48
0x89
0x03
0x5b
0xc3
Disassembled:
Dump of assembler code for function sumstore:
0x0000000000400595 <+0>: push %rbx
0x0000000000400596 <+1>: mov %rdx,%rbx
0x0000000000400599 <+4>: callq 0x400590 <plus>
0x000000000040059e <+9>: mov %rax,(%rbx)
0x00000000004005a1 <+12>:pop %rbx
0x00000000004005a2 <+13>:retq
gdb sum
disassemble sumstore
x/14xb sumstore
% objdump -d WINWORD.EXE
WINWORD.EXE: file format pei-i386
No symbols in "WINWORD.EXE".
Disassembly of section .text:
30001000 <.text>:
30001000: FORBIDDEN!
30001001: FORBIDDEN!
30001003: FORBIDDEN!
30001005: FORBIDDEN!
3000100a: FORBIDDEN!
%rsp
indicates end position in the run-time stackDesc. | Letter | Bytes | Bits |
---|---|---|---|
byte | b | 1 | 8 |
word | w | 2 | 16 |
double word | l | 4 | 32 |
quad word | q | 8 | 64 |
Desc. | Letter | Bytes | Bits |
---|---|---|---|
Single Precision | s | 4 | 32 |
Double Precision | l | 8 | 64 |
'$'
prefixM[Addr]
, starting at address addrM
$
indicates immediateOperation | Result |
---|---|
0x100(%rax) | 0x100 + content of %rax |
0x100(%rax, %rbx) | 0x100 + content of %rax + content of %rbx |
(%rax, %rbx, 2) | content of %rax + content of %rbx * 2 |
Address | Value | Register | Value |
---|---|---|---|
0x100 |
0xFF |
%rax |
0x100 |
0x104 |
0xAB |
%rcx |
0x1 |
0x108 |
0x13 |
%rdx |
0x3 |
0x10C |
0x11 |
Operand | Value |
---|---|
%rax |
________ |
0x104 |
________ |
$0x108 |
________ |
(%rax) |
________ |
4(%rax) |
________ |
9(%rax, %rdx) |
________ |
260(%rcx, %rdx) |
________ |
0xFC(, %rcx, 4) |
________ |
(%rax, %rdx, 4) |
________ |
Operand | Value | Comment |
---|---|---|
%rax |
0x100 |
Register |
0x104 |
0xAB |
Absolute address |
$0x108 |
0x108 |
Immediate |
(%rax) |
0xFF |
Address 0x100 |
4(%rax) |
0xAB |
Address 0x104 |
9(%rax, %rdx) |
0x11 |
Address 0x10C |
260(%rcx, %rdx) |
0x13 |
Address 0x108 |
0xFC(, %rcx, 4) |
0xFF |
Address 0x100 |
(%rax, %rdx, 4) |
0x11 |
Address 0x10C |
Operation | Desc. |
---|---|
movb | move byte |
movw | move word |
movl | move double word (long word) |
movq | move quad word |
movabsq | move absolute quad word |
movl
, also sets the high-order 4 bytes of the register to 0.movq
when given an immediate value, treats it as 32
bit two’s complement value which it sign extends to 64
bitmovabsq
when given an immediate value, treats it as 64
bitmovq Source, Dest
$0x400
, $-533
'$'
%rax
, %r13
%rsp
reserved for special use(%rax)