0% found this document useful (0 votes)
20 views15 pages

COAL

Manual COAL

Uploaded by

i227423
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views15 pages

COAL

Manual COAL

Uploaded by

i227423
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

El2003

COAL
Lab 08

Submitted by: Hassan Ali


Roll number: 22I-7423
Date: Oct 28, 2024

Table of Contents

Report 3
Introduction 3
Summary 7

Question 1

Write a Procedure that takes 5 numbers as an argument. Calculate the sum of numbers and
return the sum. Stores the sum in a variable in the main procedure.
Code
INCLUDE Irvine32.inc

.data

msg BYTE "Enter the numbers: ", 0

msg2 byte "Sum : ", 0

addition DWORD 0

.code

main PROC

mov edx, OFFSET msg

call WriteString

call sum

call crlf

mov edx, OFFSET msg2

call WriteString

mov eax, addition

call WriteDec

call CrLf

call waitmsg

exit

main ENDP

sum PROC

mov ecx, 5

mov esi, 0

l1:

Page 2 of 15
call ReadInt

add esi, eax

loop l1

mov addition, esi

ret

sum ENDP

END main

Question 2

Write a program that takes marks of the students in an array and stores
average, highest, lowest, and sum of all marks.

Code
INCLUDE Irvine32.inc

.data

array DWORD 10, 3, 55, 8, 10, 5, 2, 0, 9, 1

msgSmall BYTE "The smallest element is: ", 0

msgLarge BYTE "The largest element is: ", 0

msgSum BYTE "The total sum is: ", 0

msgAvg BYTE "The average is: ", 0

newline BYTE 13, 10, 0

smallest DWORD ?

largest DWORD ?

total DWORD ?

average DWORD ?

Page 3 of 15
.code

main PROC

call getSmallest

call getLargest

call getTotal

call getAverage

mov edx, OFFSET msgSmall

call WriteString

mov eax, smallest

call WriteInt

call CrLf

mov edx, OFFSET msgLarge

call WriteString

mov eax, largest

call WriteInt

call CrLf

mov edx, OFFSET msgSum

call WriteString

mov eax, total

call WriteInt

call CrLf

mov edx, OFFSET msgAvg

call WriteString

mov eax, average

call WriteInt

call CrLf

Page 4 of 15
call waitmsg

exit

main ENDP

getSmallest PROC

mov esi, OFFSET array

mov eax, [esi]

mov ecx, LENGTHOF array - 1

findSmallest:

add esi, 4

mov ebx, [esi]

cmp ebx, eax

jge skipSmallest

mov eax, ebx

skipSmallest:

loop findSmallest

mov smallest, eax

ret

getSmallest ENDP

getLargest PROC

mov esi, OFFSET array

mov eax, [esi]

mov ecx, LENGTHOF array - 1

findLargest:

add esi, 4

mov ebx, [esi]

cmp ebx, eax

jle skipLargest

Page 5 of 15
mov eax, ebx

skipLargest:

loop findLargest

mov largest, eax

ret

getLargest ENDP

getTotal PROC

mov esi, OFFSET array

mov eax, 0

mov ecx, LENGTHOF array

findTotal:

add eax, [esi]

add esi, 4

loop findTotal

mov total, eax

ret

getTotal ENDP

getAverage PROC

mov eax, total

mov ecx, LENGTHOF array

cdq

div ecx

mov average, eax

ret

getAverage ENDP

END main

Page 6 of 15
Output

Question 3

Take the marks from user and display the letter grade.
Code

INCLUDE Irvine32.inc

.data

input DWORD ?

msg BYTE "Enter marks (0-9): ", 0

gradeMsg BYTE "Your grade is: ", 0

newline BYTE 13, 10, 0

grade BYTE 0

.code

main PROC

mov edx, OFFSET msg

Page 7 of 15
call WriteString

call ReadInt

mov input, eax

call grades

mov edx, OFFSET gradeMsg

call WriteString

mov edx, OFFSET grade

call WriteString

call CrLf

call waitmsg

exit

main ENDP

grades PROC

mov eax, input

cmp eax, 5

jl gradeD

cmp eax, 7

jge gradeB

jl gradeC

cmp eax, 9

je gradeA

jmp gradeEnd

gradeD:

mov edx, OFFSET grade

mov byte ptr [edx], 'D'

jmp gradeEnd

Page 8 of 15
gradeC:

mov edx, OFFSET grade

mov byte ptr [edx], 'C'

jmp gradeEnd

gradeB:

mov edx, OFFSET grade

mov byte ptr [edx], 'B'

jmp gradeEnd

gradeA:

mov edx, OFFSET grade

mov byte ptr [edx], 'A'

jmp gradeEnd

gradeEnd:

xor eax, eax

ret

grades ENDP

END main

Output

Page 9 of 15
Question 4
Program to Find the Square Root of a Number using procedures

Code
INCLUDE Irvine32.inc

.data

msg BYTE "Enter a number to find its square root: ", 0

resultMsg BYTE "The square root is: ", 0

number DWORD ?

guess DWORD ?

.code

main PROC

mov edx, OFFSET msg

call WriteString

call ReadInt

mov number, eax

mov eax, number

shr eax, 1

Page 10 of 15
mov guess, eax

sqrt_loop:

mov eax, number

xor edx, edx

div guess

add eax, guess

shr eax, 1

mov guess, eax

mov ebx, guess

mul ebx

mov eax, number

cmp eax, ebx

jl sqrt_loop

mov edx, OFFSET resultMsg

call WriteString

mov eax, guess

call WriteDec

call CrLf

call waitmsg

exit

main ENDP

END main

Page 11 of 15
Question 5

Display a menu to user to choose from any of the option

INCLUDE Irvine32.inc

.data

menuMsg BYTE "1. Capitalize a string", 0

menuMsg2 BYTE "2. Multiply two single digit numbers", 0

message BYTE "capitalize check", 0

resultMsg BYTE "Enter numbers to multiply: ", 0

newline BYTE 13, 10, 0

var1 dword ?

var2 dword ?

.code

main PROC

mov edx, OFFSET menuMsg

call WriteString

call CrLf

mov edx, OFFSET menuMsg2

call WriteString

call CrLf

call ReadInt

cmp eax, 1

je capitalize

cmp eax, 2

je multiply

jmp main

Page 12 of 15
capitalize PROC

mov esi, OFFSET message

call caps

mov edx, OFFSET message

call WriteString

call CrLf

call waitmsg

ret

capitalize ENDP

multiply PROC

mov edx, OFFSET resultMsg

call WriteString

call Readint

mov var1, eax

call Readint

mov var2, eax

mov eax, var1

mul var2

call WriteDec

mov edx, OFFSET newline

call WriteString

call waitmsg

ret

multiply ENDP

caps PROC

mov al, [esi]

Page 13 of 15
cmp al, 0

je endcaps

cmp al, 'a'

jb nextChar

cmp al, 'z'

ja nextChar

sub al, 32

mov [esi], al

nextChar:

inc esi

jmp caps

endcaps:

ret

caps ENDP

main ENDP

END main

Output

For Input 1

Page 14 of 15
For Input 2

Page 15 of 15

You might also like