Monday, October 10, 2016

calculate students grade and display using assembly language

Problem

Calculate grade of the students by adding subject marks input by the user. Display the grade to the user.

Code

include irvine32.inc

.data
array1 sdword  10 dup(?)
array2 sdword  10 dup(?)
array3 sdword 10 dup(?)

array4 sdword +100,+100,+100,+100,+100
array5 sdword +100,+100,+2,+2,+100

mul_array sdword 32 dup(0)

mine dword ?
temp dword 0
temp1 dword 0
temp2 dword 0

two dword 2

student1_msg byte "                -*-*-*-*-*-     Student # 01     -*-*-*-*-*-*-",0
student2_msg byte "                -*-*-*-*-*-     Student # 02     -*-*-*-*-*-*-",0

la_marks_msg  byte " LA  = ",0
ms_marks_msg  byte " MS  = ",0
ds_marks_msg   byte " DS   = ",0
algo_marks_msg   byte " ALGO   = ",0
coal_marks_msg byte " COAL = ",0



grade_msg   byte "Grade = ",0
grade_f_msg  byte "F",0
grade_c_msg  byte "C",0
grade_b_msg  byte "B",0
grade_a_msg  byte "A",0

num1_msg byte "Enter 1st value: ",0
num2_msg byte "Enter 2nd value: ",0

equation_msg byte "Solving the equation: ",0ah,0dh,0
result byte " Result = ",0

even1_msg byte " 1st number is even.",0ah,0dh,0
even2_msg byte " 2nd number is even.",0ah,0dh,0ah,0dh,0

pos_msg byte "1st number is positive.",0ah,0dh,0
pos1_msg byte "2nd number is positive.",0ah,0dh,0

odd_msg byte " one number is odd.",0ah,0dh,0ah,0dh,0

neg_msg byte "number is negative.",0ah,0dh,0

ans_msg byte "Answer = ",0


.code
main proc
comment !
mov esi, offset array1
mov edi, offset array2
mov ebp, offset array3

mov ecx, 10

main_loop:

mov edx, offset num1_msg
call writestring
call readint
mov [esi], eax

mov edx, offset num1_msg
call writestring
call readint
mov [edi], eax

mov eax, [esi]
cmp eax, 0
jge positive_value1
jmp negative_value1
positive_value1:
mov edx, offset pos_msg
call writestring

mov eax, [edi]
cmp eax, 0

jge positive_value2
jmp negative_value1
positive_value2:
call positive
jmp jmp_to_loop
negative_value1:
call negative

jmp_to_loop:
add esi, 4
add edi, 4
add ebp, 4
loop main_loop

mov esi, offset array4
mov edi, offset array5

mov ecx, 5
mov ebp, offset array3

l1:
call crlf
mov eax, [ebp]
;call writeint
mov [esi], eax
add ebp, 4
add esi,4

loop l1

mov ecx, 5

l2:
call crlf
mov eax, [ebp]
;call writeint
mov [edi], eax
add ebp, 4
add edi, 4
loop l2

mov esi, offset array4
mov ecx, 5

l3:
call crlf
mov eax, [esi]

cmp eax, 0
jl negative_to_positive
mov eax, [esi]
cmp eax, 100
ja make_it_100
jmp normal_execution

negative_to_positive:
mov ebx, -1
imul ebx
cmp eax, 100
ja make_it_100
jmp normal_execution
make_it_100:
mov eax, 100
mov [esi], eax
normal_execution:
call writeint
add esi, 4
loop l3

call crlf
call crlf
mov edi, offset array5
mov ecx, 5

l4:
call crlf
mov eax, [edi]

cmp eax, 0
jl negative_to_positive_1
mov eax, [edi]
cmp eax, 100
ja make_it_100_1
jmp normal_execution_1

negative_to_positive_1:
mov ebx, -1
imul ebx
cmp eax, 100
ja make_it_100
jmp normal_execution_1
make_it_100_1:
mov eax, 100
mov [edi], eax
normal_execution_1:

call writeint
add edi, 4
loop l4
!


mov edx, offset student1_msg
call writestring
call crlf

call crlf
mov edx, offset coal_marks_msg
call writestring
mov eax, array4
call writeint

call crlf
mov edx, offset ms_marks_msg
call writestring
mov eax, [array4+4]
call writeint

call crlf
mov edx, offset ds_marks_msg
call writestring
mov eax, [array4+8]
call writeint

call crlf
mov edx, offset algo_marks_msg
call writestring
mov eax, [array4+12]
call writeint

call crlf
mov edx, offset la_marks_msg
call writestring
mov eax, [array4+16]
call writeint

call crlf
mov edx, offset grade_msg
call writestring



mov esi, offset array4
mov ecx, 5
mov eax, 0
l5:
mov ebx, [esi]
add eax, ebx
;call writeint
add esi, 4
loop l5

cmp eax, 399
ja grade_A

cmp eax, 299
ja grade_B

cmp eax, 199
ja grade_C

cmp eax, 0
ja grade_F

jmp grading_L3

grade_A:
mov edx, offset grade_a_msg
call writestring
jmp grading_L3

grade_B:
mov edx, offset grade_b_msg
call writestring
jmp grading_L3

grade_C:
mov edx, offset grade_c_msg
call writestring
jmp grading_L3

grade_F:
mov edx, offset grade_f_msg
call writestring
grading_L3:
call crlf
mov edx, offset student2_msg
call writestring
call crlf


call crlf
mov edx, offset coal_marks_msg
call writestring
mov eax, array5
call writeint

call crlf
mov edx, offset ms_marks_msg
call writestring
mov eax, [array5+4]
call writeint

call crlf
mov edx, offset ds_marks_msg
call writestring
mov eax, [array5+8]
call writeint

call crlf
mov edx, offset algo_marks_msg
call writestring
mov eax, [array5+12]
call writeint

call crlf
mov edx, offset la_marks_msg
call writestring
mov eax, [array5+16]
call writeint



call crlf
mov edx, offset grade_msg
call writestring

mov edi, offset array5
mov ecx, 5
mov eax, 0
l6:
mov ebx, [edi]
add eax, ebx
add edi,4
;call writeint
loop l6


cmp eax, 399
ja grade_A_1

cmp eax, 299
ja grade_B_1

cmp eax, 199
ja grade_C_1

cmp eax, 0
ja grade_F_1

jmp grading_L4

grade_A_1:
mov edx, offset grade_a_msg
call writestring
jmp grading_L4

grade_B_1:
mov edx, offset grade_b_msg
call writestring
jmp grading_L4

grade_C_1:
mov edx, offset grade_c_msg
call writestring
jmp grading_L4

grade_F_1:
mov edx, offset grade_f_msg
call writestring
grading_L4:
call crlf

;call equation

call crlf
call crlf
call crlf
exit
main endp

positive proc
mov edx, offset pos1_msg
call writestring
mov edx, 0
mov eax, [esi]
cdq
idiv two
cmp edx, 0
je even_value1
jmp odd_value1
even_value1:
call crlf
mov edx, offset even1_msg
call writestring

mov edx, 0
mov eax, [edi]
cdq
idiv two
cmp edx, 0
je even_value2
jmp odd_value1
even_value2:
mov edx, offset even2_msg
call writestring
call multiply
call display
jmp jmp_from_even
odd_value1:
mov edx, offset odd_msg
call writestring
call divide
call display

jmp_from_even:

ret
positive endp

negative proc
call crlf
mov edx, offset neg_msg
call writestring
mov edx, 0
mov eax, [esi]
cdq
idiv two
cmp edx, 0
je even_value3
pop edx
jmp odd_value3
even_value3:
mov edx, offset even1_msg
call writestring
mov edx, 0
mov eax, [edi]
cdq
idiv two

cmp edx, 0
je even_value4
jmp odd_value3

even_value4:
mov edx, offset even2_msg
call writestring
call multiply
call display
jmp jmp_from_even

odd_value3:
mov edx, offset odd_msg
call writestring
call divide
call display
jmp_from_even:
ret
negative endp

multiply proc
push ecx
mov edx, offset mul_array

mov ebx, [esi]

mov mine, 0
mov temp, 0
mov ecx, 32

l:
shr ebx,1
jc one_jump
jmp else_jump
one_jump:
mov eax, mine
mov temp, eax
mov eax, [edi]

l1:
cmp temp, 0
je outside_loop
sub temp, 1
shl eax, 1
jmp l1
outside_loop:
mov [edx], eax
add edx, 4
else_jump:
add mine, 1
loop l
mov ecx, lengthof mul_array
mov edx, offset mul_array
mov eax, 0

add_array:
add eax,[edx]
add edx, 4
loop add_array
mov ecx, 32
mov ebx, 0
mov edx, offset mul_array
empty_mul_array:
mov [edx],ebx
add edx, 4

loop empty_mul_array
pop ecx

ret
multiply endp 

divide proc
push ecx

mov edx, 0
mov eax, [esi]
cdq
mov ecx, [edi]
idiv ecx
pop ecx
ret
divide endp

display proc

call crlf
mov edx, offset ans_msg
call writestring
call writeint
call crlf
call crlf
mov [ebp], eax

ret
display endp


equation proc
mov edx, 0
mov eax, [array3+24]
cdq
idiv [array3+12]
mov temp2, eax
mov esi, offset temp2
mov edx, 0
mov eax, array3
cdq
idiv [array3+4]
mov temp1, eax

mov edi, offset temp1

call multiply

mov edx, [array3+16]
add edx, [array3+20]
add eax, edx
mov temp1, eax

mov esi, offset temp1
mov edi, offset [array3+8]
call multiply
add eax, array3[28]
call crlf
call crlf
mov edx, offset equation_msg
call writestring
call crlf

mov edx, offset result
call writestring
call writeint
ret
equation endp

end main

Output


No comments :

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact