rendered paste body# pwd.S - simple assembler for Linux
#include <asm/unistd.h>
#include <linux/limits.h>
/* Some constants */
#define KERNEL 0x80
#define NEWLINE '\n'
#define STDOUT 1
#define OK_EXIT 0
.section .bss # Section declaration
.lcomm cwdstr, PATH_MAX # Space for working dir
.text # Section declaration
.global _start # Export entry point for linker
_start:
# Get current working directory ...
movl $cwdstr, %ebx # 1st arg : buffer
movl $PATH_MAX, %ecx # 2nd arg : max len
movl $__NR_getcwd, %eax # System call number
int $KERNEL # Call kernel
# Put in a newline ...
movl $cwdstr, %ebx # Get address into ebx
addl %eax, %ebx # Add string length
movb $NEWLINE, -1 (%ebx) # Move in a newline
# Print to stdout ...
movl $STDOUT, %ebx # 1st arg : fd
movl $cwdstr, %ecx # 2nd arg : pointer to message
movl %eax, %edx # 3rd arg : message length
movl $__NR_write, %eax # System call number
int $KERNEL # Call kernel
# Exit ...
movl $OK_EXIT, %ebx # 1st arg : exit code
movl $__NR_exit, %eax # System call number
int $KERNEL # Call kernel