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

1]Print Hello World

section.data

hello db 'Hello world!',12


hellolen equ $-hello

section.txt
global _start

_start:

mov eax,4
mov ebx,1
mov ecx,hello
mov edx, hellolen
int 80h

mov eax,1
mov ebx,0
int 80h

o/p
Hello world!

2]Print 9 stars
section.data
star times 9 db '*'

section.text
global _start

_start:

mov eax,4
mov ebx,1
mov ecx,star
mov edx,9
int 80h

mov eax,1
mov ebx,0
int 80h

3]read num from user


section .data
read1 db 'Enter the number:',5
read1len equ $-read1

read2 db 'Number is:',5


read2len equ $-read2

section .bss
num resb 5

section .text
global _start

_start:
mov eax,4
mov ebx,1
mov ecx,read1
mov edx,read1len
int 80h

mov eax,3
mov ebx,2
mov ecx,num
mov edx,5
int 80h

mov eax,4
mov ebx,1
mov ecx,read2
mov edx,read2len
int 80h

mov eax,4
mov ebx,1
mov ecx,num
mov edx,5
int 80h

mov eax,1
mov ebx,0
int 80h

5]read name from user


section .data
string1 db 'Enter name:',5
string1len equ $-string1
string2 db 'Name: ',5
string2len equ $-string2

section .bss
name resb 5

section .text
global _start

_start:

mov eax,4
mov ebx,1
mov ecx,string1
mov edx,string1len
int 80h

mov eax,3
mov ebx,2
mov ecx,name
mov edx,5
int 80h

mov eax,4
mov ebx,1
mov ecx,string2
mov edx,string2len
int 80h

mov eax,4
mov ebx,1
mov ecx,name
mov edx,5
int 80h

mov eax,1
mov ebx,0
int 80h

5.e]
%macro write 2
mov eax,4
mov ebx,1
mov ecx, %1
mov edx,%2
int 80h
%endmacro

%macro read 1
mov eax,3
mov ebx,2
mov ecx,%1
mov edx,5
int 80h
%endmacro

section .data
str1 db 'Enter the number: ',5
str1len equ $-str1
str2 db 'The number is: ',5
str2len equ $-str2

section .bss
num1 resb 5

section .text
global _start

_start:

write str1,str1len
read num1
write str2,str2len
write num1,5

mov eax,1
mov ebx,0
int 80h

5.3]%macro write 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro read 1
mov eax,3
mov ebx,2
mov ecx,%1
mov edx,5
int 80h
%endmacro

%macro newline 0
mov eax,4
mov ebx,1
mov ecx,n1
mov edx,n1len
int 80h
%endmacro

%macro addition 3
mov eax,[%1]
sub eax,'0'
mov ebx,[%2]
sub ebx,'0'
add eax,ebx
add eax,'0'
mov [%3],eax
int 80h
%endmacro

%macro subtraction 3
mov eax,[%1]
sub eax,'0'
mov ebx,[%2]
sub ebx,'0'
sub eax,ebx
add eax,'0'
mov [%3],eax
int 80h
%endmacro

%macro mult 3
mov al,[%1]
sub al,'0'
mov bl,[%2]
sub bl,'0'
mul bl
add al,'0'
mov [%3],eax
int 80h
%endmacro

%macro division 4
mov al,[%1]
sub al,'0'
mov bl,[%2]
sub bl,'0'
div bl
add al,'0'
add ah,'0'
mov [%3],al
mov [%4],ah
int 80h
%endmacro

section .data

str1 db 'Enter the number: ',5


str1len equ $-str1
str2 db 'The sum is: ',5
str2len equ $-str2
str3 db 'The diff is: ',5
str3len equ $-str3
str4 db 'The product is: ',5
str4len equ $-str4
str5 db 'The quotient is: ',5
str5len equ $-str5
str6 db 'The remainder is: ',5
str6len equ $-str6
n1 db '',10
n1len equ $-n1

section .bss
num1 resb 5
num2 resb 5
sum resb 5
diff resb 5
prod resb 5
quo resb 5
rem resb 5

section .text
global _start

_start:

write str1,str1len
read num1
write str1,str1len
read num2
addition num1,num2,sum
write str2,str2len
write sum,5
newline
subtraction num1,num2,diff
write str3,str3len
write diff,5
newline
mult num1,num2,prod
write str4,str4len
write prod,5
newline
division num1,num2,quo,rem
write str5,str5len
write quo,5
newline
write str6,str6len
write rem,6

mov eax,1
mov ebx,0
int 80h

5.f] %macro read 1


mov eax,3
mov ebx,2
mov ecx,%1
mov edx,4
int 80h
%endmacro

%macro write 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro newline 0
mov eax,4
mov ebx,1
mov ecx,n1
mov edx,n1len
int 80h
%endmacro

%macro fib 3
mov eax,[%1]
sub eax,'0'
mov ebx,[%2]
sub ebx,'0'
add eax,ebx
add eax,'0'
mov [%3],eax
int 80h
%endmacro

section .data

str1 db 'Enter the number of terms: ',5


str1len equ $-str1
str2 db 'Fibonacci series is: ',5
str2len equ $-str2
n1 db '',10
n1len equ $-n1

section .bss

n resb 4
a resb 4
b resb 4
c resb 4
i resb 4

section .text
global _start:
_start:

write str1,str1len
read n
write str2,str2len

mov byte[i],'0'
mov byte[a],'0'
mov byte[b],'1'

cmp byte[n],'0'
JE L4
JMP L1

L1:
write a,4
inc byte[i]
mov al,[i]
cmp al,byte[n]
JE L4
JMP L2

L2:
write b,4
inc byte[i]
mov al,[i]
cmp al,byte[n]
JE L4
JMP L3

L3:
fib a,b,c
write c,4

mov al,[b]
mov [a],al

mov al,[c]
mov [b],al

inc byte[i]
mov al,[i]
cmp al,byte[n]
JE L4
JMP L3

L4:
newline
mov eax,1
mov ebx,0
int 80h
5.f]%macro read 1
mov eax,3
mov ebx,2
mov ecx,%1
mov edx,4
int 80h
%endmacro

%macro write 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro newline 0
mov eax,4
mov ebx,1
mov ecx,n1
mov edx,n1len
int 80h
%endmacro

section .data

str1 db 'Enter the number of terms: ',5


str1len equ $-str1
str2 db 'Printing n times: ',5
str2len equ $-str2
n1 db '',10
n1len equ $-n1
str3 db 'Nidhi',5
str3len equ $-str3

section .bss

n resb 4
i resb 4

section .text
global _start:
_start:

write str1,str1len
read n
newline
write str2,str2len
newline

mov byte[i],'0'

L1:
write str3,str3len
newline
inc byte[i]
mov al,[i]
cmp al,byte[n]
JE L2
JMP L1

L2:
newline
mov eax,1
mov ebx,0
int 80h

8.1]%macro read 1
mov eax,3
mov ebx,2
mov ecx,%1
mov edx,4
int 80h
%endmacro

%macro write 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro newline 0
mov eax,4
mov ebx,1
mov ecx,n1
mov edx,n1len
int 80h
%endmacro

section .data

str1 db 'Enter the size: ',5


str1len equ $-str1
str2 db 'Enter the elements: ',5
str2len equ $-str2
str3 db 'The array is: ',5
str3len equ $-str3
n1 db '',10
n1len equ $-n1
array times 10 dw 0
len equ 10

section .bss

n resb 9
i resb 9
ele resb 10

section .text
global _start:
_start:
write str1,str1len
read n
write str2,str2len
newline

mov byte[i],'0'
mov esi, array

input:
read ele
mov ebx,[ele]
mov [esi],ebx

inc esi
inc byte[i]

mov al,[i]
mov bl,[n]
sub bl,'0'
cmp al,bl
;JE L2
JL input

L2:
write str3,str3len
newline
mov byte[i],'0'
mov esi,array

output:
mov ebx,[esi]
mov [ele],ebx
write ele,5

inc esi
inc byte[i]

mov al,[i]
mov bl,[n]
sub bl,'0'
cmp al,bl
;JE exit
JL output

mov eax,1
mov ebx,0
int 80h

8.2]%macro read 2
mov eax, 3
mov ebx, 2
mov ecx, %1
mov edx, %2
int 80h
%endmacro

%macro write 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro newline 0
mov eax,4
mov ebx,1
mov ecx,n1
mov edx,n1len
int 80h
%endmacro

section .data

str1 db 'Enter the size: '


str1len equ $-str1
str2 db 'Enter the elements: '
str2len equ $-str2
str3 db 'Count of Odd: '
str3len equ $-str3
str4 db 'Count of Even: '
str4len equ $-str4
n1 db '',10
n1len equ $-n1
array times 10 dw 0
len equ 10

section .bss

n resb 10
i resb 10
ele resb 10
rem resb 5
nodd resb 5
neven resb 5

section .text
global _start
_start:

write str1,str1len
read n,5
write str2,str2len

mov byte[i], 0
mov byte[nodd], 0
mov byte[neven], 0
mov esi, array

input:
read ele,2
mov ebx, [ele]
mov [esi], ebx

inc esi
inc byte[i]

mov al, [i]


mov bl, [n]
sub bl, '0'
cmp al, bl
jl input

mov byte[i], 0
mov esi, array

check:

mov al, [esi]


mov bl,'2'
sub bl,'0'
div bl
cmp ah,0
JE even
JMP odd

even:
inc byte[neven]
jmp looper

odd:
inc byte[nodd]
jmp looper

looper:
inc esi
inc byte[i]
mov al,[i]
mov bl,[n]
sub bl,'0'
cmp al,bl
JL check
JE output

output:
add [neven],byte '0'
add [nodd],byte '0'

write str3,str3len
write nodd,5

newline

write str4,str4len
write neven,5

mov eax,1
mov ebx,0
int 80h

You might also like