Assembly x64 Intro - More Types for Printf




  extern printf
  section .data
fmt2: db "printf flt2 = %e", 10, 0
fmt3: db "char1 = %c str1 = %s len = %d", 10, 0
fmt4: db "char1 = %c str1 = %s len = %d inta1 = %d inta2 = %ld", 10, 0
fmt5: db "hex1 = %lX flt1 = %e flt2 = %e", 10, 0

char1: db 'a'
str1:  db "my test string", 0
len:   equ $-str1
inta1: dd 12345678
inta2: dq 12345678900
hex1:  dq 0x123456789ABCD
flt1:  dd 5.327e-30
flt2:  dq -123.456789e300
  section .bss
flttmp: resq 1
  section .text
  global main
main:
  push rbp
  fld  dword [flt1]  
  fstp qword [flttmp]
  mov  rdi, fmt2
  movq xmm0, qword [flt2]
  mov  rax, 1               ; 1 xmm register used
  call printf

  mov rdi, fmt3
  mov rsi, [char1]
  mov rdx, str1
  mov rcx, len
  mov rax, 0                ; no xmm register used
  call printf

  mov rdi, fmt4
  mov rsi, [char1]
  mov rdx, str1
  mov rcx, len
  mov r8,  [inta1]
  mov r9,  [inta2]
  mov rax, 0
  call printf

  mov rdi, fmt5
  mov rsi, [hex1]
  movq xmm0, qword [flttmp]  ; here flttmp used rather than flt1
  movq xmm1, qword [flt2]
  mov  rax, 2                ; 2 xmm registers used
  call printf

  pop rbp
  mov  rax, 0
  ret



你可能感兴趣的:(Assembly x64 Intro - More Types for Printf)