Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Napisati asemblerski program koji proverava da li je uneti string palindrom.
  2. Program vraća operativnom sistemu 0 ako string nije palindrom, a 1 ako jeste.
  3. Interakcija sa korisnikom treba da izgleda:
  4.  
  5. Unesite string: aca
  6. Uneti string je palindrom.
  7.  
  8. Unesite string: milan
  9. Uneti string nije palindrom.
  10.  
  11. Promenljive za ispis se nalaze u palindrom.S fajlu.
  12.  
  13.  
  14.  
  15.  
  16. .section .data
  17. poruka: .ascii "Unesite string:\0"
  18. str_lenght1 = . - poruka
  19.  
  20. nijep:  .ascii "String nije palindrom.\n\0"
  21. str_lenght2 = . - nijep
  22.  
  23. jestep: .ascii "String je palindrom.\n\0"
  24. str_lenght3 = . - jestep
  25.  
  26. unos:   .fill 50,1,42
  27.  
  28. brojac: .long 0
  29.  
  30. konst: .long 2
  31. .section .text
  32. .globl main
  33. main:
  34.     movl $unos, %esi
  35.  
  36. ulaz:
  37.     movl $4, %eax
  38.     movl $1, %ebx
  39.     leal poruka, %ecx
  40.     movl $str_lenght1, %edx
  41.     int $0x80  
  42.    
  43.     movl $3, %eax
  44.     movl $0, %ebx
  45.     leal unos, %ecx
  46.     movl $50, %edx
  47.     int $0x80
  48.  
  49.     movl $unos, %edi
  50.  
  51.  
  52. duzina:
  53.     cmpb $10, (%edi)
  54.     je gotovo
  55.     incl %edi
  56.     incl brojac
  57.     jmp duzina
  58.  
  59. gotovo:
  60.     movl $0, %edx
  61.     movl brojac, %eax
  62.     divl konst
  63.     movl %eax, brojac
  64.  
  65. nastavi:
  66.     movb (%esi), %cl
  67.     cmpb %cl, -1(%edi)
  68.     je proveri
  69.     jne nije
  70.     jmp nastavi
  71.  
  72. jeste:
  73.     movl $4, %eax
  74.     movl $0, %ebx
  75.     leal jestep, %ecx
  76.     movl $str_lenght3, %edx
  77.     int $0x80
  78.     jmp kraj
  79.  
  80. nije:
  81.     movl $4, %eax
  82.     movl $1, %ebx
  83.     leal nijep, %ecx
  84.     movl $str_lenght2, %edx
  85.     int $0x80
  86.     jmp kraj
  87.  
  88. kraj:
  89.     movl $1, %eax
  90.     int $0x80
  91.  
  92. proveri:
  93.     decl brojac
  94.     cmpl $0, brojac
  95.     je jeste
  96.     incl %esi
  97.     decl %edi
  98.     jmp nastavi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement