COAL Lab 8 (22k-4136)

You might also like

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

LAB 8 (22k-4136)

Task 1:
INCLUDE Irvine32.inc

.data
prompt BYTE "Enter number: ",0
prompt2 BYTE "Numbers are not equal",0
prompt3 BYTE "Numbers are equal",0
arr DWORD 4 DUP (?)
.code
main PROC
mov ecx,4
mov esi,0
L1:
mov edx,OFFSET prompt
call Writestring
call ReadDec
mov arr[esi],eax
add esi,4
call CRLF
Loop L1

mov ecx,3
mov esi,0
mov eax,arr[esi]
L2:
add esi,4
cmp eax,arr[esi]
jne m1
Loop L2

mov edx,OFFSET prompt3


call writestring
call CRLF

exit

m1:
mov edx,OFFSET prompt2
call writestring
call CRLF
exit
main ENDP
END main
Task 2:
INCLUDE Irvine32.inc

.data
prompt BYTE "First non-zero value found at: "
intArr SWORD 0, 0, 0, 150, 120, 35, -12, 66, 4, 0
count WORD 1
.code
main PROC
mov esi,0
mov ecx, LENGTHOF intArr
mov eax,1
L1:

cmp intArr[esi],0
JNLE x1
add count,1
add esi,2
Loop L1

exit
x1:
mov ax,count
mov edx,OFFSET prompt
call WriteString
call WriteDec
call Crlf
exit
main ENDP
END main
Task 3:
INCLUDE Irvine32.inc

.data

val DWORD ?
var DWORD 5
.code
main PROC

add var,1
mov edx,var
mov ecx,10
L1:

cmp var,ecx
JB x1
jmp next

x1:
cmp ecx,edx
JAE x2
jmp next

x2:
mov val,0
jmp print

next:
mov val,1

print:
mov eax,val
call WriteDec
call crlf

Loop L1
exit
main ENDP
END main

Task 4:
INCLUDE Irvine32.inc

.data
var DWORD 0
hello BYTE "Hello",0
world BYTE "World",0

.code
main PROC

top:cmp var,10
ja x1
cmp var,5
jae x2
mov edx,OFFSET hello
call writestring
call crlf
jmp next
x2:
mov edx,OFFSET world
call writestring
call crlf
next:inc var
jmp top

x1:
exit
main ENDP
END main
Task 5:
INCLUDE Irvine32.inc

.data

arr WORD 10, 4, 7, 14, 299, 156, 3, 19, 29, 300, 20


found BYTE "Found",0
notFound BYTE "Not found",0
prompt BYTE "Enter the number u want to search: ",0

.code
main PROC

mov edx,OFFSET prompt


call writestring
call readDec
call Crlf
mov ecx,LENGTHOF arr
mov esi,0
L1:

cmp ax,arr[esi]
je x1
add esi,2
Loop L1

mov edx,OFFSET notFound


call writestring
call crlf
exit

x1:
mov edx,OFFSET found
call writestring
call crlf
exit
main ENDP
END main

Task 6:
INCLUDE Irvine32.inc

.data

arr WORD 10, 4, 7, 14, 299, 156, 3, 19, 29, 300, 20


sort BYTE "Bubble Sort: ",0
gap BYTE " ",0
count DWORD ?
var DWORD ?
.code
main PROC

mov edx,OFFSET sort


call writestring
mov ecx,LENGTHOF arr
mov var,1
mov eax,0
mov ebx,0
L1:
mov count,ecx
mov esi,0
mov ecx,LENGTHOF arr
sub ecx,var
cmp ecx,0
je bottom

L2:
mov bx,arr[esi]
cmp bx,arr[esi+2]
ja x1
jmp x2

x1:
mov ax,arr[esi+2]
mov arr[esi+2],bx
mov arr[esi],ax

x2:add esi,TYPE arr


Loop L2

inc var
mov ecx,count

Loop L1
bottom:

mov esi,0
mov eax,0
mov ecx,LENGTHOF arr
L3:

mov ax,arr[esi]
call writeDec
mov edx,OFFSET gap
call writestring
add esi ,TYPE arr
Loop L3

call crlf
exit
main ENDP
END main

Task 7:
INCLUDE Irvine32.inc

.data
prompt BYTE "Enter a number (1 to 7): ",0
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
default BYTE "Invalid number",0

.code
main PROC
mov eax,0
mov edx,OFFSET prompt
call writestring
call readDec

cmp eax,1
je w1

cmp eax,2
je w2

cmp eax,3
je w3

cmp eax,4
je w4

cmp eax,5
je w5

cmp eax,6
je w6

cmp eax,7
je w7

mov edx,OFFSET default


jmp bottom

w1:
mov edx,OFFSET monday
jmp bottom

w2:
mov edx,OFFSET tuesday
jmp bottom

w3:
mov edx,OFFSET wednesday
jmp bottom

jmp bottom
w4:
mov edx,OFFSET thursday
jmp bottom

w5:
mov edx,OFFSET friday
jmp bottom

w6:
mov edx,OFFSET saturday
jmp bottom

w7:
mov edx,OFFSET sunday
jmp bottom
bottom:
call writestring
call crlf
exit
main ENDP
END main

Task 8:
INCLUDE Irvine32.inc

.data
prompt BYTE "Enter a charachter: ",0
found BYTE "It is a character",0
notFound BYTE "It is not a character",0

.code
main PROC
mov eax,0
mov edx,OFFSET prompt
call writestring
call readchar
call writechar
call crlf

cmp al,65
jae x1
jmp next

x1:
cmp al,90
jbe x2
jmp next

x2:
mov edx,OFFSET found
call writestring
call crlf
exit

next:
cmp al,97
jae x3
jmp bottom

x3:
cmp al,122
jbe x2

bottom:
mov edx,OFFSET notFound
call writestring
call crlf
exit
main ENDP
END main

You might also like