0% found this document useful (0 votes)
24 views7 pages

1 Introduction

Uploaded by

kimdrew715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

1 Introduction

Uploaded by

kimdrew715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CSC216

Assembly language
programming
Requirements
 Assembler: Netwide assembler (NASM)
 An assembler for the Intel x86 architecture.
 It can be used in both Linux and Windows
 It can be download from the internet
 We will assume the IA-32 instruction set (Intel Architecture, 32-bit)
Parts of an assembly language program
 Data section/segment: For declaring variables/constants that are
initialised
 Specified using the instruction section .data
 BSS section/segment: used for declaring variables that are not
initialised and allocating memory to them
 It is specified using the instruction section .bss
 text section/segment: contains the actual code.
 Specified using the instruction section .text
 It must begin with the instruction global _start which tell the
kernel where the program execution begins
 The semicolon (;) is used to signal the start of a comment. Comments
can be on their own line or after an instruction
Assembly language statements
 Generally, there are three types of statements
 Instructions: An instruction is specified by an opcode. Each opcode
generates one machine instruction
 Assembler directives (pseudo-ops): These tell the assembler what to
do during the assembly process
 Macros: These are a text substitution mechanism. One macro can
result into one or several instructions.

Assembly language statements syntax
 Instructions are usually entered one per line
 The follow the format
[label] opcode [operands] [;comment]
 Examples
INC i ; increments the variable i by one
MOV [total], 48 ; transfer 48 to the variable total
Hello Kenya program
section .text
global _start ;must be declared for linker (ld)

_start: ;tells linker entry point


mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

mov eax,1 ;system call number (sys_exit)


int 0x80 ;call kernel

section .data
msg db 'Hello Kenya!', 0xa ;string to be printed
len equ $ - msg ;length of the string
Assembling
 To assemble the code, use the command below
> nasm -f elf hello.asm
 Elf stands for executable and linkable format
 The -f option is used to specify the output file format. Example
formats are elf32(elf), elf64, win32, win64,
 After assembling, link using the command below
> ld -m elf_i386 -s hello.o -o hello
 Then run the program by typing
 >./hello

You might also like