Advertisement
_takumi

idz2_for4

Nov 3rd, 2022 (edited)
1,333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     .intel_syntax noprefix
  2.     .text
  3.     .section    .rodata
  4. .LC0:
  5.     .string "%lld"
  6. .LC1:
  7.     .string "%c"
  8.     .text
  9.     .globl  main
  10.     .type   main, @function
  11. main:
  12.     push    rbp
  13.     mov rbp, rsp
  14.     sub rsp, 64
  15.     mov QWORD PTR -40[rbp], 0 # rbp-40 is n
  16.     lea rsi, -40[rbp]
  17.     lea rdi, .LC0[rip]
  18.     mov eax, 0
  19.     call    __isoc99_scanf@PLT
  20.     mov rax, QWORD PTR -40[rbp] # rax = n
  21.     add rax, 1 # rax = n+1
  22.     mov rdi, rax # malloc argument is n+1 - the size of the string s in bytes
  23.     call    malloc@PLT
  24.     mov QWORD PTR -16[rbp], rax # rbp-16 = s
  25.     mov QWORD PTR -32[rbp], 0 # p1(?)
  26.         cmp     QWORD PTR -40[rbp], 1
  27.         jne     .L16
  28.         mov     QWORD PTR -32[rbp], rax
  29. .L16:
  30.     add rax, QWORD PTR -40[rbp] # rax = s + n #-40
  31.     mov QWORD PTR -24[rbp], rax # rbp-24 = p2 = s + n
  32.     call    getchar@PLT
  33.     mov DWORD PTR -52[rbp], 0 # rbp-52 = i = 0
  34.     jmp .L2
  35. .L3:
  36.     movsx   rdx, DWORD PTR -52[rbp]
  37.     mov rsi, QWORD PTR -16[rbp]
  38.     add rsi, rdx # s + i
  39.     lea rdi, .LC1[rip] # format string
  40.     mov eax, 0
  41.     call    __isoc99_scanf@PLT
  42.     inc DWORD PTR -52[rbp]
  43. .L2:
  44.     movsx   rdx, DWORD PTR -52[rbp]
  45.     cmp rdx, QWORD PTR -40[rbp]
  46.     jl  .L3
  47.     mov rax, QWORD PTR -40[rbp]
  48.     dec eax
  49.     mov DWORD PTR -48[rbp], eax # rbp-48 = i = n-1
  50.     jmp .L4
  51. .L9:
  52.     mov eax, DWORD PTR -48[rbp]
  53.     lea rdx, -1[rax]
  54.     mov rax, QWORD PTR -16[rbp] # rax = s
  55.     add rax, rdx
  56.     movzx   edx, BYTE PTR [rax]# edx = s[i-1]
  57.     mov eax, DWORD PTR -48[rbp]
  58.     movsx   rcx, eax
  59.     mov rax, QWORD PTR -16[rbp]
  60.     add rax, rcx
  61.     movzx   eax, BYTE PTR [rax] # rax = s[i]
  62.     cmp dl, al # if (s[i - 1] < s[i])
  63.     jge .L5
  64.     mov eax, DWORD PTR -48[rbp]
  65.     cdqe
  66.     lea rdx, -1[rax]
  67.     mov rax, QWORD PTR -16[rbp]
  68.     add rax, rdx
  69.     mov QWORD PTR -32[rbp], rax # p1 = s + i - 1
  70.     jmp .L6
  71. .L5: # else
  72.     cmp QWORD PTR -32[rbp], 0 # if (p1 != NULL)
  73.     jne .L8 # break
  74.     mov eax, DWORD PTR -48[rbp]
  75.     movsx   rdx, eax
  76.     mov rax, QWORD PTR -16[rbp]
  77.     add rax, rdx
  78.     mov QWORD PTR -24[rbp], rax # p2 = s + i
  79. .L6:
  80.     sub DWORD PTR -48[rbp], 1 # --i
  81. .L4:
  82.     cmp DWORD PTR -48[rbp], 0
  83.     jg  .L9
  84. .L8:
  85.         cmp      QWORD PTR -32[rbp], 0
  86.         je      .L15
  87.     mov DWORD PTR -44[rbp], 0 # i = 0
  88.     jmp .L10
  89. .L11:
  90.     mov eax, DWORD PTR -44[rbp]
  91.     movsx   rdx, eax
  92.     mov rax, QWORD PTR -32[rbp]
  93.     add rax, rdx
  94.     movzx   eax, BYTE PTR [rax]
  95.     movsx   eax, al
  96.     mov edi, eax # arg=p1[i]
  97.     call    putchar@PLT # putchar=printf("%c",...)
  98.     add DWORD PTR -44[rbp], 1
  99. .L10:
  100.     mov eax, DWORD PTR -44[rbp]
  101.     movsx   rdx, eax
  102.     mov rax, QWORD PTR -32[rbp]
  103.     add rax, rdx
  104.     cmp QWORD PTR -24[rbp], rax
  105.     jne .L11
  106. .L15:
  107.     mov eax, 0
  108.     leave
  109.     ret
  110.     .size   main, .-main
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement