Advertisement
Guest User

Untitled

a guest
Oct 29th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.97 KB | None | 0 0
  1. #include <asm/unistd_32.h>
  2. .intel_syntax noprefix
  3.  
  4. .text
  5. .global _start
  6.  
  7. _start:
  8.     //make system call brk which returs a pointer of a new end of memory
  9.     mov esi, 0  //stack capacity
  10.     mov eax, __NR_brk
  11.     mov ebx, 0
  12.     int 0x80
  13.     mov edi, eax    //edi is the poiter of heap sbrk
  14.     push edi    //saving edi
  15. loop_read:
  16.     //if buffer is not empty
  17.     cmp esi, 0
  18.     jg read
  19.     //else realloc
  20.     mov esi, 2048
  21.     add edi, esi    //edi is adding as well
  22.     //again make systerm call brk
  23.     mov eax, __NR_brk
  24.     mov ebx, edi    //because now edi is N*2048 bytes
  25.     int 0x80
  26.     //get edi old value which is 0
  27.     sub edi, esi
  28. read:
  29.     //reading while capacity is not 0
  30.     //make system call read
  31.     mov eax, __NR_read
  32.     mov ebx, 0
  33.     mov ecx, edi    // *buffer
  34.     mov edx, esi    //size_t n_bytes
  35.     int 0x80
  36.     //if there was nothing to read go to write
  37.     test eax, eax
  38.     jz get_endl
  39.     //else saving to edi and change esi(capacity)
  40.     add edi, eax
  41.     sub esi, eax
  42.     jmp loop_read
  43. get_endl:
  44.     //need endl '\n'
  45.     mov al, '\n'   //al is the 8-bit register of 32-bit eax register(lower 8-bit)
  46.     mov [edi], al   //load to the end of text '\n' symbol
  47. loop_write:
  48.     mov esi, edi
  49. write:
  50.     //if edi is the end go to end
  51.     cmp edi, [esp]
  52.     je end
  53.     //write each char
  54.     sub edi, 1
  55.     mov al, '\n'
  56.     cmp [edi], al   //comparing new char with endl
  57.     je write_line
  58.  
  59.     jmp write
  60. write_line:
  61.     //wring line
  62.     //make system call
  63.     mov eax, __NR_write
  64.     mov ebx, 1
  65.     mov ecx, edi   // *buffer
  66.     //ecx += 1
  67.     add ecx, 1
  68.     mov edx, esi   //size_t n_bytes
  69.     sub edx, edi
  70.     int 0x80
  71.     jmp loop_write
  72. end:
  73.     //wring the last line
  74.     //making system call
  75.     mov eax, __NR_write
  76.     mov ebx, 1
  77.     mov ecx, edi
  78.     mov edx, esi
  79.     sub edx, edi
  80.     inc edx
  81.     int 0x80
  82.     //exit
  83.     pop edi
  84.     mov eax, __NR_exit
  85.     mov ebx, 0
  86.     int 0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement