6.3 x64

和原来一样,只是传递参数时不使用栈而使用寄存器。

6.3.1 MSVC

  1. _DATA SEGMENT
  2. $SG1289 DB Enter X:’, 0aH, 00H
  3. $SG1291 DB ’%d’, 00H
  4. $SG1292 DB You entered %d...’, 0aH, 00H
  5. _DATA ENDS
  6. _TEXT SEGMENT
  7. x$ = 32
  8. main PROC
  9. $LN3:
  10. sub rsp, 56
  11. lea rcx, OFFSET FLAT:$SG1289 ; Enter X:’
  12. call printf
  13. lea rdx, QWORD PTR x$[rsp]
  14. lea rcx, OFFSET FLAT:$SG1291 ; ’%d
  15. call scanf
  16. mov edx, DWORD PTR x$[rsp]
  17. lea rcx, OFFSET FLAT:$SG1292 ; You entered %d...’
  18. call printf
  19. ; return 0
  20. xor eax, eax
  21. add rsp, 56
  22. ret 0
  23. main ENDP
  24. _TEXT ENDS

6.3.2 GCC

  1. .LC0:
  2. .string "Enter X:"
  3. .LC1:
  4. .string "%d"
  5. .LC2:
  6. .string "You entered %d...
  7. "
  8. main:
  9. sub rsp, 24
  10. mov edi, OFFSET FLAT:.LC0 ; "Enter X:"
  11. call puts
  12. lea rsi, [rsp+12]
  13. mov edi, OFFSET FLAT:.LC1 ; "%d"
  14. xor eax, eax
  15. call __isoc99_scanf
  16. mov esi, DWORD PTR [rsp+12]
  17. mov edi, OFFSET FLAT:.LC2 ; "You entered %d...
  18. "
  19. xor eax, eax
  20. call printf
  21. ; return 0
  22. xor eax, eax
  23. add rsp, 24
  24. ret