Thursday, March 14, 2013

Simple echo in ASM code

This is very very simple and stupid code that reads from the standard input a string and writes on the standard output the same string.

The system calls are called by ASM code

#define BUF_SIZE 1024
#define READ 3
#define WRITE 4
#define FD 0

void main(){

 int __res;

 char __str[BUF_SIZE];

 //__res = read(0,__str,BUF_SIZE)
 __asm__ volatile ("int $0x80" : \
  "=a" (__res) : \
  "a" (READ), \
  "b" (FD), \
  "c" (__str), \
  "d" (BUF_SIZE));

 //write(0,__str,__res)
 __asm__ volatile ("int $0x80" : : \
  "a" (WRITE), \
  "b" (FD), \
  "c" (__str), \
  "d" (__res));

}

No comments:

Post a Comment