Assembly x64 Intro - Arith Operate



  extern printf

%macro prtabc 1
  section .data
.str db %1, 0
  section .text
  mov rdi, fmt4
  mov rsi, .str
  mov rdx, [a]
  mov rcx, [b]
  mov r8,  [c]
  mov rax, 0              ; no any xmm register used
  call printf
%endmacro

  section .data
a: dq 3
b: dq 4
fmt4: db "%s, a=%ld, b=%ld, c=%ld",10,0
  section .bss
c: resq  1

  section .text
  global main
main:
  push rbp
lit5:
  mov rax, 5
  mov [c], rax
  prtabc "c = c "
a_add_b:
  mov rax, [a]
  add rax, [b]
  mov [c], rax
  prtabc "c = a + b "
a_sub_b:
  mov rax, [a]
  sub rax, [b]
  mov [c], rax
  prtabc "c = a - b "
a_mul_b:
  mov rax, [a]
  imul qword [b]
  mov [c], rax
  prtabc "c = a * b "
a_div_b:
  mov rax, [c]
  mov rdx, 0
  idiv qword [a]
  mov [c], rax
  prtabc "c = c / a "

  pop rbp
  mov rax, 0
  ret



你可能感兴趣的:(Assembly x64 Intro - Arith Operate)