Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <asm/unistd_32.h>
- .intel_syntax noprefix
- .text
- .global _start
- _start:
- //make system call brk which returs a pointer of a new end of memory
- mov esi, 0 //stack capacity
- mov eax, __NR_brk
- mov ebx, 0
- int 0x80
- mov edi, eax //edi is the poiter of heap sbrk
- push edi //saving edi
- loop_read:
- //if buffer is not empty
- cmp esi, 0
- jg read
- //else realloc
- mov esi, 2048
- add edi, esi //edi is adding as well
- //again make systerm call brk
- mov eax, __NR_brk
- mov ebx, edi //because now edi is N*2048 bytes
- int 0x80
- //get edi old value which is 0
- sub edi, esi
- read:
- //reading while capacity is not 0
- //make system call read
- mov eax, __NR_read
- mov ebx, 0
- mov ecx, edi // *buffer
- mov edx, esi //size_t n_bytes
- int 0x80
- //if there was nothing to read go to write
- test eax, eax
- jz get_endl
- //else saving to edi and change esi(capacity)
- add edi, eax
- sub esi, eax
- jmp loop_read
- get_endl:
- //need endl '\n'
- mov al, '\n' //al is the 8-bit register of 32-bit eax register(lower 8-bit)
- mov [edi], al //load to the end of text '\n' symbol
- loop_write:
- mov esi, edi
- write:
- //if edi is the end go to end
- cmp edi, [esp]
- je end
- //write each char
- sub edi, 1
- mov al, '\n'
- cmp [edi], al //comparing new char with endl
- je write_line
- jmp write
- write_line:
- //wring line
- //make system call
- mov eax, __NR_write
- mov ebx, 1
- mov ecx, edi // *buffer
- //ecx += 1
- add ecx, 1
- mov edx, esi //size_t n_bytes
- sub edx, edi
- int 0x80
- jmp loop_write
- end:
- //wring the last line
- //making system call
- mov eax, __NR_write
- mov ebx, 1
- mov ecx, edi
- mov edx, esi
- sub edx, edi
- inc edx
- int 0x80
- //exit
- pop edi
- mov eax, __NR_exit
- mov ebx, 0
- int 0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement