flat assembler
Message board for the users of flat assembler.
Index
> Linux > Attempt at implementing cat in fasm. |
Author |
|
revolution 25 Apr 2015, 14:55
The code you posted also has ETX at the end. Perhaps your editor/viewer software is faulty?
|
|||
25 Apr 2015, 14:55 |
|
alkap 25 Apr 2015, 16:21
Sorry. That was intentional. Just wanted to post the output generated verbatim.
|
|||
25 Apr 2015, 16:21 |
|
revolution 26 Apr 2015, 00:22
It occurs to me that ETX is the same as CTRL-C. Does the Linux stdin send a CTRL-C code to indicate the end of a text stream?
|
|||
26 Apr 2015, 00:22 |
|
alkap 27 Apr 2015, 14:29
Mystery solved.
Turns out, I used the wrong base pointer offset when accessing the number-of-bytes parameter in my implementation of the 'read' and 'write' functions: Code: read: push ebp mov ebp, esp mov eax, READ mov ebx, [ebp+08h] mov ecx, [ebp+0Ch] mov edx, [ebp+0Eh] ; wrong offset; should read '[ebp+10h] int 80h mov esp, ebp pop ebp ret Code: write: push ebp mov ebp, esp mov eax, WRITE mov ebx, [ebp+08h] mov ecx, [ebp+0Ch] mov edx, [ebp+0Eh] ; wrong offset; should read '[ebp+10h]' int 80h mov esp, ebp pop ebp ret Thanks for trying to help. |
|||
27 Apr 2015, 14:29 |
|
alkap 04 May 2015, 10:46
Here is a version of 'cat' that uses 'cdecl' calling convention.
I also intend to implement a version of the program that passes parameters to functions using registers. Constructive criticism would be appreciated. Code: flib_stack.inc Code: ; int open(const char *pathname, int flags) align 16 open: push ebp mov ebp, esp mov eax, OPEN mov ebx, [ebp+08h] mov ecx, [ebp+0Ch] int 80h mov esp, ebp pop ebp ret ; int close(int fd) align 16 close: push ebp mov ebp, esp mov eax, CLOSE mov ebx, [ebp+08h] int 80h mov esp, ebp pop ebp ret ; ssize_t read(int fd, void *buf, size_t count) align 16 read: push ebp mov ebp, esp mov eax, READ mov ebx, [ebp+08h] mov ecx, [ebp+0Ch] mov edx, [ebp+10h] int 80h mov esp, ebp pop ebp ret ; ssize_t write(int fd, const void *buf, size_t count) align 16 write: push ebp mov ebp, esp mov eax, WRITE mov ebx, [ebp+08h] mov ecx, [ebp+0Ch] mov edx, [ebp+10h] int 80h mov esp, ebp pop ebp ret ; void _exit(int status) align 16 exit: push ebp mov ebp, esp mov eax, EXIT mov ebx, [ebp+08h] int 80h mov esp, ebp pop ebp ret ; syscalls EXIT = 1 READ = 3 WRITE = 4 OPEN = 5 CLOSE = 6 |
|||
04 May 2015, 10:46 |
|
alkap 12 May 2015, 18:45
Here's a version of 'cat' that passes function parameters via registers.
Constructive criticism, and/or suggestions on a better/simpler implementation would be much appreciated. Code: flib_regs.inc Code: ; int open(const char *pathname, int flags) ; eax - syscall ; ebx - pathname ; ecx - flags ; eax - file descriptor align 16 open: mov eax, OPEN int 80h ret ; int close(int fd) ; eax - syscall ; ebx - file descriptor align 16 close: mov eax, CLOSE int 80h ret ; ssize_t read(int fd, void *buf, size_t count) ; eax - syscall ; ebx - file descriptor ; ecx - buffer ; edx - size of buffer ; eax - nbytes read into buffer align 16 read: mov eax, READ int 80h ret ; ssize_t write(int fd, const void *buf, size_t count) ; eax - syscall ; ebx - file desciptor ; ecx - buffer ; edx - bytes to be written align 16 write: mov eax, WRITE int 80h ret ; void _exit(int status) ; eax - syscall ; ebx - status align 16 exit: mov eax, EXIT int 80h ; syscalls EXIT = 1 READ = 3 WRITE = 4 OPEN = 5 CLOSE = 6 |
|||
12 May 2015, 18:45 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.