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

Coal Lab 8 22k-4161 M.

Asim

Task 1:
Code:
INCLUDE irvine32.inc
.data
array DWORD 4 dup (?)
prompt1 byte "Enter Four numbers: ",0
promptEqual byte "The numbers are equal.",0
promptNotEqual byte "The numbers are not equal.",0

.code
main proc

mov edx,offset prompt1


call writestring

mov ecx,4
mov esi,0
L1:
call readint
mov array[esi],eax
add esi,4
Loop L1

mov edi,4
mov eax,array[0]
mov ecx,3

L2:
cmp eax,array[edi]
JNE noteq
add esi,4
Loop L2

mov edx,offset promptequal


call WriteString
exit

noteq:
mov edx,offset promptnotequal
call writestring
exit

main endp
end main
OUTPUT Ss:
Task 2:
CODE:
INCLUDE irvine32.inc
.data

array SDWORD 0,0,0,150,120,35-12,66,4,0

prompt1 byte "First non zero number was ",0

.code
main proc

mov eax,0
mov ecx,10
mov esi,0

L1:
cmp eax,array[esi]
jne notequal
add esi,4
Loop L1

notequal:
mov edx,offset prompt1
call writestring
mov eax,array[esi]
call writeint
exit

main endp
end main

OUTPUT SS:
Task 3:
CODE:
INCLUDE irvine32.inc
.data
var DWORD 5
x DWORD ?
prompt byte "x= ",0

.code
main PROC

mov ecx,10 ;VALUE FROM Q2


l1:
mov edx,var
inc edx

mov eax,var
cmp eax,ecx
jb secondcomp
jmp falsestatements

secondcomp:
cmp ecx,edx
jae truestatements
jmp falsestatements

truestatements:
mov x,0
jmp loopend
falsestatements:
mov x,1
loopend:
mov eax,x
mov edx,offset prompt
call writestring
call writeint
call crlf
loop l1
exit
main ENDP
END main
OUTPUT SS:
Task 4:
CODE:
INCLUDE irvine32.inc
.data
var DWORD 0
hello byte "hello",0
World byte "World",0

.code
main PROC

top:
mov eax,var
cmp eax,10
ja loopbreak
cmp eax,5
jae falsestatements
mov edx,offset hello
call WriteString
call crlf
jmp next

falsestatements:
mov edx,offset World
call WriteString
call crlf

next:
inc var
jmp top

loopbreak:

exit
main ENDP
END main
OUTPUT SS:
Task 5:
CODE:

INCLUDE irvine32.inc
.data
arr WORD 10, 4, 7, 14, 299, 156, 3, 19, 29, 300, 20
prompt byte "Enter number you want to search: ",0
key word ?
numfound byte "The number was found at index position ",0
notfound byte "The number was not found.",0
index dword 0

.code
main PROC
mov edx,offset prompt
call writestring
call readint
mov key,ax

mov ecx,11
mov esi,0
L1:
cmp ax,arr[esi]
je found
add esi,2
inc index
Loop L1

mov edx,offset notfound


call writestring
exit

found:
mov edx,offset numfound
call writestring
mov eax,index
call writedec

exit
main ENDP
END main
OUTPUT SS:

Task 6:
CODE:
INCLUDE Irvine32.inc
.data
arr DWORD 10, 4, 7, 14, 299, 156, 3, 19, 29, 300, 20
count dword 0
outercount dword 0

.code
main PROC
mov eax,lengthof arr
mov count,eax
Sub count, 1

mov edx,0
mov ecx,count

L1:
mov outercount,ecx
mov edx,0
mov ecx,count

L2:
mov esi, arr[edx]
cmp esi,arr[edx+4]
jbe continue

mov esi,arr[edx]
xchg esi,arr[edx+4]
mov arr[edx],esi

continue:
add edx,4
loop l2

mov ecx,outercount
loop L1

mov ecx,lengthof arr


mov esi,0

l3:
mov eax, arr[esi*4]
call writedec
call crlf
inc esi
loop l3

exit
main ENDP
END main
OUTPUT SS:
Task 7:
CODE:
INCLUDE irvine32.inc
.data
num dword ?
monday byte "MONDAY",0
tuesday byte "TUESDAY",0
wednesday byte "WEDNESDAY",0
thursday byte "THURSDAY",0
friday byte "FRIDAY",0
saturday byte "SATURDAY",0
sunday byte "SUNDAY",0
prompt1 byte "Enter a number between 1-7: ",0
prompt2 byte "The day based on the given number is ",0

.code
main PROC
mov edx,offset prompt1
call writestring
call readdec

cmp eax,1
je mon
cmp eax,2
je tue
cmp eax,3
je wed
cmp eax,4
je thurs
cmp eax,5
je fri
cmp eax,6
je sat
cmp eax,7
je sun

mon:
mov edx,offset prompt2
call writestring
mov edx,offset monday

call writestring
jmp next

tue:
mov edx,offset prompt2
call writestring
mov edx,offset tuesday
call writestring
jmp next

wed:
mov edx,offset prompt2
call writestring
mov edx,offset wednesday
call writestring
jmp next

thurs:
mov edx,offset prompt2
call writestring
mov edx,offset thursday
call writestring
jmp next

fri:
mov edx,offset prompt2
call writestring
mov edx,offset friday
call writestring
jmp next

sat:
mov edx,offset prompt2
call writestring
mov edx,offset saturday
call writestring
jmp next

sun:
mov edx,offset prompt2
call writestring
mov edx,offset sunday
call writestring

next:

exit
main ENDP
END main

OUTPUT SS:
Task 8:
CODE:
INCLUDE irvine32.inc
.data
num dword ?
prompt1 byte "Enter the character you want to check for: ",0
prompt2 byte "The input is an alphabet.",0
prompt3 byte "The input is not an alphabet.",0

.code
main PROC
mov edx,offset prompt1
call writestring
call readchar
call crlf
call writechar

cmp al,97
jae seccomp
jmp no

seccomp:
cmp al,122
ja no
mov edx,offset prompt2
call crlf
call writestring
jmp next

no:
call crlf
mov edx,offset prompt3
call writestring

next:

exit
main ENDP
END main

OUTPUT SS:

You might also like