Courses/Computer Science/CPSC 601.29.ISSA/20110128CodeSession

From wiki.ucalgary.ca
< Courses‎ | Computer Science‎ | CPSC 601.29.ISSA
Revision as of 22:30, 7 February 2011 by Locasto (talk | contribs) (Created page with "Makefile: [michael@xorenduex lectures]$ cat Makefile all: mywrite mywrite: mywrite.asm nasm -f elf mywrite.asm gcc -Wall -s -nostdlib mywrite.o clea...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Makefile:

  [michael@xorenduex lectures]$ cat Makefile 
  all: mywrite
  
  mywrite: mywrite.asm
  	nasm -f elf mywrite.asm
  	gcc -Wall -s -nostdlib mywrite.o
  
  clean:
  	@/bin/echo "nothing to do"
  [michael@xorenduex lectures]$ 


Assembly Source:

[michael@xorenduex lectures]$ cat mywrite.asm 
	;; mywrite.asm 
	;; goal is to invoke write system call
	;; write( fd,    buf,          size)
	;; eax/4  ebx/1  ecx/greeting  edx/5
BITS 32
GLOBAL _start
SECTION .data
greeting	db	'hello'
SECTION .text
_start:	
	mov	eax, 4		;sys_write is 4 
	mov	ebx, 1		;stdout (default file desc. supplied by OS)
	mov	ecx, greeting	;move address of label in .data to ecx
	mov	edx, 5		;5 byte
	int	0x80		;invoke write(2)
	mov	ebx, eax	;save ret val (eax) to ebx (arg to exit)
	mov	eax, 1		;sys_exit is 1
	int	0x80		;invoke exit(2)
[michael@xorenduex lectures]$