Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

AFTER MID TO FINAL TERM WEEK 10

Gamma Computer organization and assembly language

TOPIC: Constants directive


Constants are just like variables, but they exist only until your program is compiled
(assembled). After definition of a constant its value cannot be changed. To define
constants EQU directive is used:

Constants: Numeric and string


%assign %define
Syntax

name EQU < any expression >

For example:

Program 1

k EQU 5

MOV AX, k

The above example is functionally identical to code:

MOV AX, 5
Program 2

SYS_EXIT equ1
SYS_WRITE equ4
STDIN equ0
STDOUT equ1
section .text
global _start ;must be declared for using gcc

_start: ;tell linker entry point


mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg1
mov edx, len1
int 0x80

mov eax, SYS_WRITE


mov ebx, STDOUT
mov ecx, msg2
mov edx, len2
int 0x80

mov eax, SYS_WRITE


mov ebx, STDOUT
mov ecx, msg3
mov edx, len3
int 0x80

mov eax,SYS_EXIT ;system call number (sys_exit)


int 0x80 ;call kernel

section .data
msg1 db 'Hello, programmers!',0xA,0xD
len1 equ $ - msg1

msg2 db 'Welcome to the world of,', 0xA,0xD


len2 equ $ - msg2

msg3 db 'Linux assembly programming! '


len3 equ $- msg3

output
Lab task

Write simple program/code in assembly language that illustrate the use of EQU , %ASSIGN AND %
DEFINE directive.

Helping link

https://www.tutorialspoint.com/assembly_programming/assembly_constants.htm

https://www.tutorialspoint.com/compile_asm_online.php

You might also like