Advertisement
Guest User

Untitled

a guest
May 21st, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .text
  2. global main
  3.  
  4. main:
  5.         push    prompt1             ; push prompt1
  6.         push    prompt1Len          ; push length
  7.         call    print               ; call print
  8.  
  9.         call    read                ; call read
  10.  
  11.         mov     esi, str
  12.         sub     byte [esi], 0x30
  13.  
  14.         push    prompt2             ; push prompt1
  15.         push    prompt2Len          ; push length
  16.         call    print               ; call print
  17.  
  18.         call    read
  19.         mov     edi, str
  20.         sub     byte [edi], 0x30
  21.  
  22.         push    esi                 ; push int val of input
  23.         push    eax                 ; push num of read bytes
  24.  
  25.         call    print               ; print
  26.  
  27.         ; close
  28.         mov     eax, 1
  29.         mov     ebx, 0
  30.         int     0x80
  31.  
  32. print:
  33.         push    ebp
  34.         mov     ebp, esp
  35.  
  36.         mov     edx, [ebp+8]
  37.         mov     ecx, [ebp+12]
  38.         mov     eax, 4
  39.         mov     ebx, 1
  40.         int     0x80
  41.         mov     esp, ebp
  42.         pop     ebp
  43.         ret
  44.  
  45. read:
  46.         push    ebp
  47.         mov     ebp, esp
  48.  
  49.         mov     eax, 3
  50.         mov     ebx, 0
  51.         mov     ecx, str
  52.         mov     edx, 100
  53.         int     0x80
  54.        
  55.         mov     esp, ebp
  56.         pop     ebp
  57.         ret
  58.  
  59. stringlen:
  60.         push    ebp
  61.         mov     ebp, esp                ;pre amble
  62.  
  63.         mov     ecx, [ebp + 8]
  64.  
  65.         xor     eax, eax                ; length
  66.  
  67. startLoop:
  68.         xor     edx, edx
  69.         mov     dl, byte[ecx]
  70.         inc     eax
  71.  
  72.         cmp     dl, 0x0                 ; check for \0
  73.         je      end                     ; restart loop if not \0
  74.         cmp     dl, 'a'
  75.         jb      next
  76.         cmp     dl, 'z'
  77.         ja      next
  78.         sub     dl, 0x20
  79.         mov     [ecx], dl
  80.  
  81. next:
  82.         inc     ecx
  83.         jmp     startLoop
  84.  
  85. end:
  86.         inc ecx
  87.         mov     byte[ecx], 0xa
  88.         inc eax
  89.         pop     ebp
  90.         ret      
  91.  
  92. section .data
  93.         str:    times   100     db  0             ; allocate 100 byte buffer
  94.         lf:     db      10                   ; new line for full buffer
  95.         prompt1 db      'Enter first Number: '
  96.         prompt1Len equ $-prompt1
  97.         prompt2 db      'Enter second Number: '
  98.         prompt2Len equ $-prompt2
  99.  
  100.  
  101.  
  102. all = numberequ
  103.  
  104. numberequ: numberequ.o
  105.     gcc -m32 -o numberequ numberequ.o
  106.  
  107. numberequ.o: numberequ.asm
  108.     nasm -f elf32 -g numberequ.asm
  109.  
  110. clean:
  111.     rm -rf *.o numberequ
  112.  
  113.  
  114.  
  115. section .text
  116. global main
  117.  
  118. main:
  119.         mov     eax, [esp + 0x08]       ; get argv ptr
  120.         mov     esi, [eax + 0x04]       ; get argv[1]
  121.  
  122.         push    esi                     ; push string for strlen
  123.         call    stringlen               ; call string length
  124.  
  125.         push    eax                     ; push string length for print
  126.  
  127.         call    print
  128.  
  129.         ; sys_exit
  130.         mov    eax, 1
  131.         int    0x80
  132.  
  133. print:
  134.         push    ebp
  135.         mov     ebp, esp
  136.  
  137.         mov     edx, [ebp+8]
  138.         mov     ecx, [ebp+12]
  139.         mov     eax, 4
  140.         mov     ebx, 1
  141.         int     0x80
  142.         pop     ebp
  143.         ret
  144.  
  145. stringlen:
  146.         push    ebp
  147.         mov     ebp, esp                ;pre amble
  148.  
  149.         mov     ecx, [ebp + 8]
  150.  
  151.         xor     eax, eax                ; length
  152.  
  153. startLoop:
  154.         xor     edx, edx
  155.         mov     dl, byte[ecx]
  156.         inc     eax
  157.  
  158.         cmp     dl, 0x0                 ; check for \0
  159.         je      end                     ; restart loop if not \0
  160.         cmp     dl, 'a'
  161.         jb      next
  162.         cmp     dl, 'z'
  163.         ja      next
  164.         sub     dl, 0x20
  165.         mov     [ecx], dl
  166.  
  167. next:
  168.         inc     ecx
  169.         jmp     startLoop
  170.  
  171. end:
  172.         inc ecx
  173.         mov     byte[ecx], 0xa
  174.         inc eax
  175.         pop     ebp
  176.         ret      
  177.  
  178.  
  179.  
  180. all = lowertoupper
  181.  
  182. lowertoupper: lowertoupper.o
  183.     gcc -m32 -o lowertoupper lowertoupper.o
  184.  
  185. lowertoupper.o: lowertoupper.asm
  186.     nasm -f elf32 -g lowertoupper.asm
  187.  
  188. clean:
  189.     rm -rf *.o lowertoupper
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement