COAL
COAL
COAL
Lab 08
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
addition DWORD 0
.code
main PROC
call WriteString
call sum
call crlf
call WriteString
call WriteDec
call CrLf
call waitmsg
exit
main ENDP
sum PROC
mov ecx, 5
mov esi, 0
l1:
Page 2 of 15
call ReadInt
loop l1
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
smallest DWORD ?
largest DWORD ?
total DWORD ?
average DWORD ?
Page 3 of 15
.code
main PROC
call getSmallest
call getLargest
call getTotal
call getAverage
call WriteString
call WriteInt
call CrLf
call WriteString
call WriteInt
call CrLf
call WriteString
call WriteInt
call CrLf
call WriteString
call WriteInt
call CrLf
Page 4 of 15
call waitmsg
exit
main ENDP
getSmallest PROC
findSmallest:
add esi, 4
jge skipSmallest
skipSmallest:
loop findSmallest
ret
getSmallest ENDP
getLargest PROC
findLargest:
add esi, 4
jle skipLargest
Page 5 of 15
mov eax, ebx
skipLargest:
loop findLargest
ret
getLargest ENDP
getTotal PROC
mov eax, 0
findTotal:
add esi, 4
loop findTotal
ret
getTotal ENDP
getAverage PROC
cdq
div ecx
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 ?
grade BYTE 0
.code
main PROC
Page 7 of 15
call WriteString
call ReadInt
call grades
call WriteString
call WriteString
call CrLf
call waitmsg
exit
main ENDP
grades PROC
cmp eax, 5
jl gradeD
cmp eax, 7
jge gradeB
jl gradeC
cmp eax, 9
je gradeA
jmp gradeEnd
gradeD:
jmp gradeEnd
Page 8 of 15
gradeC:
jmp gradeEnd
gradeB:
jmp gradeEnd
gradeA:
jmp gradeEnd
gradeEnd:
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
number DWORD ?
guess DWORD ?
.code
main PROC
call WriteString
call ReadInt
shr eax, 1
Page 10 of 15
mov guess, eax
sqrt_loop:
div guess
shr eax, 1
mul ebx
jl sqrt_loop
call WriteString
call WriteDec
call CrLf
call waitmsg
exit
main ENDP
END main
Page 11 of 15
Question 5
INCLUDE Irvine32.inc
.data
var1 dword ?
var2 dword ?
.code
main PROC
call WriteString
call CrLf
call WriteString
call CrLf
call ReadInt
cmp eax, 1
je capitalize
cmp eax, 2
je multiply
jmp main
Page 12 of 15
capitalize PROC
call caps
call WriteString
call CrLf
call waitmsg
ret
capitalize ENDP
multiply PROC
call WriteString
call Readint
call Readint
mul var2
call WriteDec
call WriteString
call waitmsg
ret
multiply ENDP
caps PROC
Page 13 of 15
cmp al, 0
je endcaps
jb nextChar
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