Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Lab Task #6

Computer Organization and Assembly Language

COAL-255

Submitted To
Mr. Muhammad Jabbar
Submitted By
Muhammad Uzair Zafar

Roll Number

21011519-051

Section
A

Department of Computer Science


University of Gujrat, Hafiz Hayat Campus
Lab Tasks
Computer organization and assembly Language

Task 1:
Get the two numbers from user and perform comparison between them and show
greatest number.
Hint: Use CMP and JMP and JG commands.

Code:
include irvine32.inc

.data

s1 byte "Enter first Number: ",0

s2 byte "Enter Second Number: ",0

s3 byte "Greater Number is: ",0

num1 dd ?

.code

main proc

mov edx,offset s1

call writestring

call readint

mov num1,eax

;moving 1st number to num1

mov edx,offset s2

call writestring

call readint
cmp eax,num1

;comparing 1st num with 2nd num

jg l1

mov edx,offset s3

call writestring

mov eax,num1

call writedec

jmp next

l1:

mov edx,offset s3

call writestring

call writedec

call crlf

next:

call crlf

exit

main endp

end

Output Snip:
Task 2:
Get the two numbers from user and perform comparison between them and show
smallest number.
Hint: Use CMP and JMP and JL commands.

Code:

include irvine32.inc

.data

s1 byte "Enter first Number: ",0

s2 byte "Enter Second Number: ",0

s3 byte "Lesser Number is: ",0

num1 dd ?

.code

main proc

mov edx,offset s1

call writestring

call readint

mov num1,eax

mov edx,offset s2

call writestring

call readint

cmp eax,num1

jl l1

mov edx,offset s3

call writestring

mov eax,num1

call writedec

jmp next
l1:

mov edx,offset s3

call writestring

call writedec

call crlf

next:

call crlf

exit

main endp

end

Output Snip:
Task 3:
Get the marks from user in percentage, perform comparison and show grade
80 or above show A grade
70 or above show B grade
60 or above show C grade
50 or above show D grade
Less than 50 show F grade

Code:
include irvine32.inc

.data

s1 byte "Enter marks in Percentage: ",0

s2 byte "Your Grade is A",0

s3 byte "Your Grade is B",0

s4 byte "YOur Grade is C",0

s5 byte "Your Grade is D",0

s6 byte "Sorry you are Fail",0

s7 byte "Enter valid Marks",0

.code

main proc

continue:

mov edx,offset s1

call writestring

call readint

cmp eax,100 ;Checking marks greater then 100 or less then 0


jg error

cmp eax,0

jl error

cmp eax,80 ;comparing marks between 80-100

jge L1

cmp eax,70 ;comparing marks between 70-79

jge L2

cmp eax,60 ;comparing marks between 60-69

jge L3

cmp eax,50 ;comparing marks between 50-59

jge L5

cmp eax,49 ;comparing for Fail grade if marks are less then 49

jle L6

; Lables

L1: ; L1 display Grade A if marks are between 80-100

mov edx,offset s2

call writestring

call crlf

jmp next
L2: ; L2 display Grade B if marks are between 70-79

mov edx,offset s3

call writestring

call crlf

jmp next

L3: ; L3 display Grade C if marks are between 60-69

mov edx,offset s4

call writestring

call crlf

jmp next

L5: ; L5 display Grade D if marks are between 50-59

mov edx,offset s5

call writestring

call crlf

jmp next

L6: ; L6 display Grade Fail if marks are less then 49

mov edx,offset s6

call writestring

call crlf

jmp next
error: ;error displayed if Marks are Greater then 100 or less then 0

mov edx,offset s7

call writestring

call crlf

jmp continue

next:

exit

main endp

end

Error if Input is Greater then 100 or less then 0 how program behaves:
Grade A:

Grade B:
Grade C:

Grade D:
Grade Fail:

You might also like