Advertisement
TimSenin

Untitled

Dec 3rd, 2022
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     .global main
  2. main:
  3.     movl $1, %edx
  4.     movl $4, %esi  // отступ для получения индекса
  5.     movl $-1, versions(, %edx, 4)
  6. read:
  7.     jc fin
  8.     call readi32
  9.     jc fin
  10.     or %eax, %eax
  11.     jz push
  12.     jmp pop
  13.  
  14. push:
  15.     call readi32
  16.     movl %eax, %ebx  // в %ebx лежит i
  17.     call readi32
  18.     mov %eax, %ecx  // в %ecx лежит x
  19.     movl %ecx, versions(, %edx, 8)  // число
  20.     movl %ebx, versions(%esi, %edx, 8)  // индекс элемента-предка
  21.     inc %edx
  22.  
  23.     jmp read
  24.  
  25. pop:
  26.     call readi32
  27.     movl %eax, %ebx  // в %ebx индекс состояния
  28.    
  29.     movl versions(, %ebx, 8), %eax  // печатаем вершину стека
  30.     movl versions(%esi, %ebx, 8), %ecx
  31.     cmp $-1, %ecx
  32.     jz empty_stack
  33.     call writei32
  34.     movl versions(%esi, %ebx, 8), %ecx  // в %ecx индекс новой головы
  35.     movl versions(, %ecx, 8), %edi
  36.     movl %edi, versions(, %edx, 8)
  37.     movl versions(%esi, %ecx, 8), %edi
  38.     movl %edi, versions(%esi, %edx, 8)
  39.  
  40.     inc %edx
  41.     jmp read
  42.  
  43. empty_stack:
  44.     mov $-1, %eax
  45.     call writei32
  46.     jmp read
  47.  
  48. fin:
  49.     call finish
  50.  
  51.     .data
  52. versions:  // в version лежат пары {число, индекс элемента-предка}
  53.     .skip 4 * 2 * 1001
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement