You are on page 1of 6

TASK 1

include irvine32.inc
.data
s1 byte "first five numbers are:",0,0ah
s2 byte " sum of first five numbers are:",0,0ah
n1 dd 5
sum dd ?
.code
main proc

mov edx , offset s1


call writestring ; print string
call crlf
mov eax , 1 ; store in eax 1
mov sum , 0 ; storing 0 for sum in sum
.while ( eax <= 5 ) ;while eax in not equal to 5
call writedec ; print the numbers
call crlf
add sum, eax ;first 5 numbers are being add and stor
tosum
inc eax ;increment eax for iteration
.endw ; end while loop
mov eax, sum ;mov sum to eax
mov edx , offset s2
call writestring
call crlf
call writedec ; printing sum
exit
main endp
end

TASK 2
include irvine32.inc
.data
s1 byte "first five numbers are:",0,0ah
s2 byte " = ",0,0ah
n1 dd 5

.code
main proc

mov edx , offset s1 ;printing string s1


call writestring
call crlf
mov eax , 1
mov ebx , 1
.while ( ebx <= 5 ) ; loop will run 5 times
mov eax , ebx
call writedec
mov edx , offset s2 ; printing ‘=’
call writestring
mul eax ; mul number with itself for square
call writedec ; printing square
call crlf ; mov output to nxt line
inc ebx ; increment cbx
.endw
exit
main endp
end

TASK 3
include irvine32.inc
.data
s1 byte "enter the number :", 0 , 0ah
s2 byte "factorial :", 0 , 0ah

.code
main proc
mov edx , offset s1 ; asking for number
call writestring
call readdec ; getting number
mov ebx , eax ; moving number to ebx
mov ecx , 1
mov eax , 1
.while (ecx <= ebx) ;loop until ecx is smaller then the number user input

mul ecx ; multiplying ecx with eax


inc ecx ; incrementing ecx
.endw
mov edx , offset s2 ; showing factorial
call writestring
call writedec
exit
main endp
end

TASK 4
include irvine32.inc
.data
s1 byte "enter the number greater than 10",0,0ah
s2 byte " number is less than 10",0,0ah
s3 byte " sum offset even numbers:",0,0ah
s4 byte " sum offset odd numbers:",0,0ah
s5 byte "odd:",0,0ah
s6 byte "even:",0,0ah
n1 dd ?
sum dd 0
sum2 dd 0
.code
main proc

mov edx ,offset s1 ; asking for a number greater 10


call writestring
call crlf
call reading ; getting numbe
mov ecx , eax ; storing it in ecx
mov ebx , 2
.if( ecx > 10 ) ; if the number is not greater then the following block of code will not
;run
mov edi , 1 ; move 1 in edi

.while ( ecx >= edi); ; loop until entered num is greater then edi
mov eax , edi
mov edx , 0
div ebx ; diviser eax has dividend performing division

.if ( edx == 0 ) ; if number is even


mov edx , offset s6 ; printing even
call writestring
mov eax , edi
call writedec ; printing even number
call crlf
add sum , eax ; summing even number
.endif ;condition end

mov eax , edi ;again moving edi in ecx


mov edx , 0
div ebx ; division
.if (edx != 0 ) ; checking odd numbers
mov edx , offset s5
call writestring ;printing odd
mov eax , edi
call writedec ; printing odd number
call crlf
add sum2 , eax ; summing odd number
.endif

inc edi ; increment edi for loop


.endw
mov edx , offset s3 ; printing sum of even numbers
mov eax , sum
call writestring
call writedec
call crlf
mov edx , offset s4 ; printing sum of odd numbers
mov eax , sum2
call writestring
call writedec

.else
mov edx ,offset s2 ; if number is not greater then 10 print this string
call writestring

.endif
exit
main endp
end

TASK 11
include irvine32.inc
.data
s1 byte "*",0
column dd 1
.code
main proc
mov ecx , 5 ; for outer loop

mov edx , offset s1 ; for printing *


outer: ; lable for outer loop
mov column , 1 ; to print column again

.while (column <= ecx ) ;loop until col is less or equal to ecx

call writestring ; printing ‘*’


inc column ; incrementing col

.endw
call crlf ; moving code flow to next line in output

loopnz outer ; if ecx is not equal to 0 continue loop

exit
main endp
end

TASK 12
; same as task 11 accept in while condition we replace ecx with 5

include irvine32.inc

.data

s1 byte "*",0

column dd 1

.code

main proc

mov ecx , 5

mov edx , offset s1

outer:

mov column , 1

.while (column <= 5 )

call writestring

inc column

.endw

call crlf

loopnz outer
exit

main endp

end

TASK 10

include irvine32.inc
.data
.code
main proc
mov ecx , 5
mov eax , 1
outer: ; lable for outer loop
mov eax, 1

.while (eax <= ecx) ; loop until eax is less then then or equal to ecx

call writedec ; printing number


inc eax ; increament for next number

.endw
call crlf
call crlf

loopnz outer; loop until ecx is not zero

exit
main endp
end

TASK 7
include irvine32.inc
.data
s1 byte "Enter number:",0
s2 byte "Enter power:",0
n1 dd ?
n2 dd ?
.code
main proc
mov edx , offset s1; asking for number
call writestring
call reading ; getiing number
mov n1 , eax ; mov to n1

mov edx , offset s2 ; asking for power


call writestring
call reading ; getting nnumber
mov n2 , eax ; moving to n2
mov eax , 1
.while n2 >= 1 ; loop until power is not equal to 1
mul n1 ; mull number with ecx
mov ebx, eax ; product is move to ebx

dec n2 ; decrementing power


.endw ; end while loop

mov eax , ebx ; the product is then mov to eax


call writedec ; this will print the result of number with given power
exit
main endp
end

You might also like