|
CS 456 - Systems Programming
Spring 2024
|
Displaying ./code/asm/write.asm
; Write
; Compile with: nasm -f elf write.asm
; Link with (64 bit systems require elf_i386 option): ld -m elf_i386 write.o -o write
; Run with: ./write
%include 'functions.asm'
SECTION .data
filename db 'readme.txt', 0h ; the filename to create
contents db 'Hello world!', 0h ; the contents to write
SECTION .text
global _start
_start:
mov ecx, 0777o ; code continues from lesson 22
mov ebx, filename
mov eax, 8
int 80h
mov edx, 12 ; number of bytes to write - one for each letter of our contents string
mov ecx, contents ; move the memory address of our contents string into ecx
mov ebx, eax ; move the file descriptor of the file we created into ebx
mov eax, 4 ; invoke SYS_WRITE (kernel opcode 4)
int 80h ; call the kernel
call quit ; call our quit function
|