<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: assambler code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 11 Oct 2008 03:07:53 GMT</pubDate>
    <description>DZone Snippets: assambler code</description>
    <item>
      <title>Hello assambler</title>
      <link>http://snippets.dzone.com/posts/show/3949</link>
      <description>The canonical Hello World program in assambler.&lt;br /&gt;&lt;br /&gt;Compile it with:&lt;br /&gt;nasm -f elf hello.s&lt;br /&gt;ld -s -o hello hello.o&lt;br /&gt;&lt;br /&gt;Helloworld is a function. It uses the write system call to print to stdout (file descriptor 1).&lt;br /&gt;&lt;br /&gt;This is written in NASM (Intel) syntax, hence it will not work with gas, tasm or masm. It was written for Linux. The details may vary on other platforms.&lt;br /&gt;&lt;br /&gt;Download NASM for free at http://nasm.sourceforge.net/&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;section .data&lt;br /&gt;  hello: db "Hello world!",10&lt;br /&gt;  hellolen: equ $ - hello&lt;br /&gt;&lt;br /&gt;section .text&lt;br /&gt;  global _start&lt;br /&gt;&lt;br /&gt;_start:&lt;br /&gt;  call helloworld&lt;br /&gt;&lt;br /&gt;  mov eax,1 ; start exit procedure&lt;br /&gt;  mov ebx,0&lt;br /&gt;&lt;br /&gt;  int 80h&lt;br /&gt;&lt;br /&gt;helloworld:&lt;br /&gt;  mov eax,4 ; 4 is the code for the write system call&lt;br /&gt;  mov ebx,1 ; 1 is the fd for stdout&lt;br /&gt;  mov ecx,hello ; the address of the string&lt;br /&gt;  mov edx,hellolen ; the length of the string&lt;br /&gt;&lt;br /&gt;  int 80h ; trigger an interrupt; this should be 21h for DOS&lt;br /&gt;&lt;br /&gt;  ret&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 02 May 2007 18:40:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3949</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
    <item>
      <title>Automated GNU Makefile</title>
      <link>http://snippets.dzone.com/posts/show/3948</link>
      <description>A simple automated GNU Makefile to build and link c/c++/asm projects. All the variables that need to be tweaked are located at the begining:&lt;br /&gt;    PROGNAME: the name of the executable to be built&lt;br /&gt;    CC: the C compiler&lt;br /&gt;    CPP: the C++ compiler&lt;br /&gt;    ASM: the assambler&lt;br /&gt;    LD: the linker&lt;br /&gt;&lt;br /&gt;This searches for all *.c, *.cpp and *.s files and compiles them into objects. It then links all the files into a single executable.&lt;br /&gt;&lt;br /&gt;The strip rule is used to strip all unwanted symbols from the resulting executable. This usually results in a significant (think 40%) size optimisation.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$(VERBOSE).SILENT:&lt;br /&gt;&lt;br /&gt;PROGNAME = prog&lt;br /&gt;&lt;br /&gt;CC = gcc&lt;br /&gt;CC += -c&lt;br /&gt;CPP = g++&lt;br /&gt;CPP += -c&lt;br /&gt;ASM = nasm&lt;br /&gt;ASM += -f elf -d ELF_TYPE&lt;br /&gt;LD = g++&lt;br /&gt;&lt;br /&gt;OBJFILES = $(patsubst %.c,%.o,$(wildcard *.c))&lt;br /&gt;OBJFILES += $(patsubst %.s,%.o,$(wildcard *.s))&lt;br /&gt;OBJFILES += $(patsubst %.cpp,%.o,$(wildcard *.cpp))&lt;br /&gt;&lt;br /&gt;all: $(PROGNAME)&lt;br /&gt;&lt;br /&gt;clean:&lt;br /&gt;	@echo "Cleaning object files"&lt;br /&gt;	@echo "    rm -f     *.o"&lt;br /&gt;	rm -f *.o&lt;br /&gt;	@echo "Cleaning backups"&lt;br /&gt;	@echo "    rm -f     *~"&lt;br /&gt;	rm -f *~&lt;br /&gt;	@echo "Removing programme"&lt;br /&gt;	@echo "    rm -f     "$(PROGNAME)&lt;br /&gt;	rm -f $(PROGNAME)&lt;br /&gt;&lt;br /&gt;%.o: %.s&lt;br /&gt;	@echo "Assambling "$@&lt;br /&gt;	@echo "    ASM       "$&lt;&lt;br /&gt;	$(ASM) $&lt;&lt;br /&gt;&lt;br /&gt;%.o: %.c&lt;br /&gt;	@echo "Compiling "$@&lt;br /&gt;	@echo "    CC        "$&lt;&lt;br /&gt;	$(CC) $&lt;&lt;br /&gt;&lt;br /&gt;%.o: %.cpp&lt;br /&gt;	@echo "Compiling "$@&lt;br /&gt;	@echo "    CPP       "$&lt;&lt;br /&gt;	$(CPP) $&lt;&lt;br /&gt;&lt;br /&gt;$(PROGNAME): $(OBJFILES)&lt;br /&gt;	@echo "Linking "$@&lt;br /&gt;	@echo "    LD        -o "$(PROGNAME)"        "$(OBJFILES)&lt;br /&gt;	$(LD) -o $(PROGNAME) $(OBJFILES)&lt;br /&gt;&lt;br /&gt;strip: $(PROGNAME)&lt;br /&gt;	@echo "Stripping "$(PROGNAME)&lt;br /&gt;	echo -n "Size of "$(PROGNAME)" before strip is "&lt;br /&gt;	ls -sh $(PROGNAME) | cut -d' ' -f1&lt;br /&gt;	@echo "    strip     "$(PROGNAME)&lt;br /&gt;	strip $(PROGNAME)&lt;br /&gt;	echo -n "Size of "$(PROGNAME)" after strip is "&lt;br /&gt;	ls -sh $(PROGNAME) | cut -d' ' -f1&lt;br /&gt;&lt;br /&gt;nothing:&lt;br /&gt;	@echo "Nothing to do; quitting  :("&lt;br /&gt;	@echo "HINT: Try make all"&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 02 May 2007 17:43:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3948</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
  </channel>
</rss>
