asmgarden: Question 001

Introduction to x86 Assembly: Hello World

Objective

Write a basic x86 assembly program that prints "Hello, World!" to the console.

Background

The "Hello, World!" program is a classic introductory program in programming. It's often used to introduce the basic syntax of a programming language.

Task

Your task is to write an x86 assembly program that uses system calls to print "Hello, World!" to the standard output (console).

Requirements

Solution


section .data
    hello db 'Hello, World!',0xA   ; 'Hello, World!' plus a linefeed character
    helloLen equ $ - hello         ; Length of the 'Hello, World!' string

section .text
    global _start                  ; Make '_start' the entry point of the program

_start:
    mov eax, 4                     ; 'sys_write' system call
    mov ebx, 1                     ; File descriptor 1 - STDOUT
    mov ecx, hello                 ; Pointer to the string to print
    mov edx, helloLen              ; Length of the string to print
    int 0x80                       ; Call the kernel

    mov eax, 1                     ; 'sys_exit' system call
    xor ebx, ebx                   ; Return 0 status on exit
    int 0x80                       ; Call the kernel

Assembly and Execution

  1. Write and save your solution in student_solutions directory.
  2. Name the file hello.asm.
  3. From the parent directory, test it with docker run --rm -v $(pwd)/student_solutions:/asmcode abhinavmir/asmgarden 001 hello.asm