The first training assembly, is this talking word size of 8 bytes?

When I break the core, it seems that the bold line is where I create and initialize. I think I'm wrong, I'm trying to learn the x86_64 assembly from a book explaining x86. This seems strange, and I'm sure I just don’t understand how in this book he says that he will refer to the word and the word as 4 bytes. If I could get an explanation to help my ignorance, that would be very grateful.

  (gdb) list
     1 #include <stdio.h>
     2   
     3 int main ()
     4 {
     5 int i;
     6 for (i = 0; i <10; i ++)
     7 {
     8 printf ("Hello, world! \ N");
     nine }
     10 return 0;
     (gdb) disassemble main
     Dump of assembler code for function main:
        0x0000000100000f10 <+0>: push rbp
        0x0000000100000f11 <+1>: mov rbp, rsp
        0x0000000100000f14 <+4>: sub rsp, 0x10
        0x0000000100000f18 <+8>: mov DWORD PTR [rbp-0x4], 0x0
        0x0000000100000f1f <+15>: mov DWORD PTR [rbp-0x8], 0x0
        0x0000000100000f26 <+22>: cmp DWORD PTR [rbp-0x8], 0xa
        0x0000000100000f2d <+29>: jge 0x100000f54 <main + 68>
        0x0000000100000f33 <+35>: lea rdi, [rip + 0x48] # 0x100000f82
        0x0000000100000f3a <+42>: mov al, 0x0
        0x0000000100000f3c <+44>: call 0x100000f60
        0x0000000100000f41 <+49>: mov DWORD PTR [rbp-0xc], eax
        0x0000000100000f44 <+52>: mov eax, DWORD PTR [rbp-0x8]
        0x0000000100000f47 <+55>: add eax, 0x1
        0x0000000100000f4c <+60>: mov DWORD PTR [rbp-0x8], eax
        0x0000000100000f4f <+63>: jmp 0x100000f26 <main + 22>
        0x0000000100000f54 <+68>: mov eax, 0x0
        0x0000000100000f59 <+73>: add rsp, 0x10
        0x0000000100000f5d <+77>: pop rbp
        0x0000000100000f5e <+78>: ret    
     End of assembler dump.  </code>
+6
source share
1 answer

The terms used to describe dimensions in x86 architecture are as follows:

  • byte : 8 bits
  • word : 2 bytes
  • dword : 4 bytes (means "double word")
  • qword : 8 bytes (means "four-digit word")

This is somewhat at odds with the usual meaning of the word: the 16-bit nature of word is the result of the evolution of x86 machines from their 16-bit sources, and not because of the natural size of the word machine. For compatibility reasons, the size of the word operand should always remain the same even on a 64-bit machine.

Note that the variable i in your program is 32 bits: you can see dword size dword in the corresponding glass calls. It may be instructive to recompile your program with type i changed to long int .

+7
source

Source: https://habr.com/ru/post/959001/


All Articles