Difference between revisions of "CSC231 Hello World!"
(Created page with '--~~~~ ---- =Hello World!= * Assemble, link and run as follows: nasm -f elf -F stabs helloworld.asm ld -melf_i386 -o helloworld helloworld.o ./helloworld <code><pre> ;;;…') |
|||
Line 1: | Line 1: | ||
--[[User:Thiebaut|D. Thiebaut]] 13:25, 20 September 2010 (UTC) | --[[User:Thiebaut|D. Thiebaut]] 13:25, 20 September 2010 (UTC) | ||
---- | ---- | ||
+ | __TOC__ | ||
+ | |||
=Hello World!= | =Hello World!= |
Latest revision as of 08:25, 20 September 2010
--D. Thiebaut 13:25, 20 September 2010 (UTC)
Contents
Hello World!
- Assemble, link and run as follows:
nasm -f elf -F stabs helloworld.asm ld -melf_i386 -o helloworld helloworld.o ./helloworld
;;; helloword.asm
;;; D. Thiebaut
;;; 9/13/10
;;; A simple "Hello world!" program. The program simply displays a string
;;; on the screen.
;;;
;;; to assemble and run:
;;; nasm -f elf -F stabs helloworld.asm
;;; ld -melf_i386 -o helloworld helloworld.o
;;; ./helloworld
;;; -------------------------------------------------------------------
EXIT equ 1
WRITE equ 4
STDOUT equ 1
;; ------------------------------------------------------------
;; data areas
;; ------------------------------------------------------------
section .data
hello db 10, "hello world!",10,10,10 ; the string we printing
MSGLEN equ $-hello
;; ------------------------------------------------------------
;; code area
;; ------------------------------------------------------------
section .text
global _start
;; print the string hello
_start: mov eax, WRITE
mov ebx, STDOUT
mov ecx, hello
mov edx, MSGLEN
int 0x80 ; system call to print to stdout
;; exit()
mov eax,EXIT
mov ebx,0
int 0x80 ; final system call
Listing File
- Generate the listing file as follows:
nasm -f elf -F stabs -l helloworld.S helloworld.asm
1 ;;; helloword.asm
2 ;;; D. Thiebaut
3 ;;; 9/13/10
4 ;;; A simple "Hello world!" program. The program simply displays a string
5 ;;; on the screen.
6 ;;;
7 ;;; to assemble and run:
8 ;;; nasm -f elf -F stabs helloworld.asm
9 ;;; ld -melf_i386 -o helloworld helloworld.o
10 ;;; ./helloworld
11 ;;; -------------------------------------------------------------------
12 EXIT equ 1
13 WRITE equ 4
14 STDOUT equ 1
15
16 ;; ------------------------------------------------------------
17 ;; data areas
18 ;; ------------------------------------------------------------
19
20 section .data
21 00000000 0A68656C6C6F20776F- hello db 10, "hello world!",10,10,10 ; the string we printing
22 00000009 726C64210A0A0A
23 MSGLEN equ $-hello
24
25 ;; ------------------------------------------------------------
26 ;; code area
27 ;; ------------------------------------------------------------
28
29 section .text
30 global _start
31
32 ;; print the string hello
33 00000000 B804000000 _start: mov eax, WRITE
34 00000005 BB01000000 mov ebx, STDOUT
35 0000000A B9[00000000] mov ecx, hello
36 0000000F BA10000000 mov edx, MSGLEN
37 00000014 CD80 int 0x80 ; system call to print to stdout
38
39 ;; exit()
40 00000016 B801000000 mov eax,EXIT
41 0000001B BB00000000 mov ebx,0
42 00000020 CD80 int 0x80 ; final system call