background preloader

Assembly

Facebook Twitter

A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux. (or, "Size Is Everything") She studied it carefully for about 15 minutes. Finally, she spoke. "There's something written on here," she said, frowning, "but it's really teensy. " [Dave Barry, "The Columnist's Caper"] If you're a programmer who's become fed up with software bloat, then may you find herein the perfect antidote. This document explores methods for squeezing excess bytes out of simple programs. Please note that the information and examples given here are, for the most part, specific to ELF executables on a Linux platform running under an Intel-386 architecture.

Please also note that if you aren't a little bit familiar with assembly code, you may find parts of this document sort of hard to follow. In order to start, we need a program. Let's take an incredibly simple program, one that does nothing but return a number back to the operating system. So, here is our first version: /* tiny.c */ int main(void) { return 42; } which we can compile and test like so: $ gcc -Wall tiny.c $ . So. Rmiyagi-inline-asm. Inline Assembly with DJGPP. Back to Eric's Home page by Brennan "Bas" Underwood This document has disappeared from it's previous resting place. Apparently Brennan has changed ISPs. If you know where it is, please let me know. Document version 1.1.2.2 Ok. This is meant to be an introduction to inline assembly under DJGPP.

Hopefully if you already know Intel syntax, the examples will be helpful to you. The Syntax So, DJGPP uses the AT&T assembly syntax. Basic inline assembly The format for basic inline assembly is very simple, and much like Borland's method. asm ("statements"); Pretty simple, no? Asm ("nop"); will do nothing of course, and asm ("cli"); will stop interrupts, with asm ("sti"); of course enabling them. When it comes to simple stuff like this, basic inline assembly is fine. Asm ("pushl %eax\n\t" "movl $0, %eax\n\t" "popl %eax"); (The \n's and \t's are there so the .s file that GCC generates and hands to GAS comes out right when you've got multiple statements per asm .) Extended inline assembly asm ("cld\n\t" as well.

Using Assembly Language in Linux. By Phillip phillip@ussrback.com Last updated: Monday 8th January 2001 Contents: Introduction. This article will describe assembly language programming under Linux. Contained within the bounds of the article is a comparison between Intel and AT&T syntax asm, a guide to using syscalls and a introductory guide to using inline asm in gcc.

This article was written due to the lack of (good) info on this field of programming (inline asm section in particular), in which case i should remind thee that this is not a shellcode writing tutorial because there is no lack of info in this field. Various parts of this text I have learnt about through experimentation and hence may be prone to error. There is only one prerequisite for reading this article, and thats obviously a basic knowledge of x86 assembly language and C. Intel and AT&T Syntax. Prefixes. In Intel syntax there are no register prefixes or immed prefixes. Example: Direction of Operands. Memory Operands. Example: As you can see, AT&T is very obscure. Linux Assembly. Introduction to Linux Intel Assembly Language. Norman Matloff February 5, 2002 ©2001, 2002, N.S. Matloff 1 Overview2 Different Assemblers3 Assembler Command-Line Syntax4 Sample Program5 16-Bit, 8-Bit and String Operations6 Linking into an Executable File7 What If You Compile a C Program?

8 How to Execute Those Sample Programs 8.1 ``Normal'' Execution Won't Work 8.2 Running Our Programs Using gdb/ddd 8.2.1 Use a Debugging Tool for ALL of Your Programming, in EVERY Class 8.2.2 Using ddd for Executing Our Assembly Programs 8.2.3 Using gdb for Executing Our Assembly Programs 8.3 An Assembly-Language Specific Debugger: ald9 Useful Web Links 1 Overview This document introduces the use of assembly language on Linux systems. 2 Different Assemblers Our emphasis will be on as (also written sometimes as gas, for ``GNU assembler''), the assembler which is part of the gcc package. However, we will also be using another commonly-used assembler, NASM. It is very important to note, though, that the two assemblers will produce the same machine code.