EL2003
Computer Organization And
Assembly Language
LAB Assignment 1
Submitted by: Hassan Ali
Roll number: I22-7423
Date: October 10, 2024
Table of Contents
Page 1 of 17
∙ Introduction 3
∙ Steps 3
∙ Summary 3
∙ References 3
Page 2 of 17
● Question 1
A customer went for shopping and bought five different items. You need to
write an assembly program to take the prices (double digits) of the items from
user then add the prices of all the items and display the total bill of that
customer.
include Irvine32.inc
.data
subject1_msg byte "Subject 1 marks : ", 0
subject2_msg byte "Subject 2 marks : ", 0
subject3_msg byte "Subject 3 marks : ", 0
subject4_msg byte "Subject 4 marks : ", 0
subject5_msg byte "Subject 5 marks : ", 0
result_msg byte "Total marks : ", 0
total_marks dword ?
sub1 dword ?
sub2 dword ?
sub3 dword ?
sub4 dword ?
sub5 dword ?
.code
main proc
Page 3 of 17
; display message for subject 1 and read input and so on
mov edx, offset subject1_msg
call writestring
call readdec
mov sub1, eax
mov edx, offset subject2_msg
call writestring
call readdec
mov sub2, eax
mov edx, offset subject3_msg
call writestring
call readdec
mov sub3, eax
mov edx, offset subject4_msg
call writestring
call readdec
mov sub4, eax
mov edx, offset subject5_msg
call writestring
call readdec
mov sub5, eax
Page 4 of 17
; calculate total marks
mov eax, sub1
add eax, sub2
add eax, sub3
add eax, sub4
add eax, sub5
mov total_marks, eax
; display the total obtained marks
mov edx, offset result_msg
call writestring
mov eax, total_marks
call writedec
call crlf
; exit program
call waitmsg
exit
main endp
end main
Output
Page 5 of 17
● Question 2
Write an assembly program to take total marks (100) and obtained marks
(double digits) of a student for five subjects and display the total marks and
percentage (integral part only).
include Irvine32.inc
.data
subject1_msg byte "Subject 1 marks : ", 0
subject2_msg byte "Subject 2 marks : ", 0
subject3_msg byte "Subject 3 marks : ", 0
subject4_msg byte "Subject 4 marks : ", 0
subject5_msg byte "Subject 5 marks : ", 0
Page 6 of 17
result_msg byte "Total Marks : ", 0
percentage_msg byte "Percentage : ", 0
total_marks dword ?
sub1 dword ?
sub2 dword ?
sub3 dword ?
sub4 dword ?
sub5 dword ?
percentage dword ?
.code
main proc
; get marks for each subject
mov edx, offset subject1_msg
call writestring
call readdec
mov sub1, eax
mov edx, offset subject2_msg
call writestring
call readdec
mov sub2, eax
mov edx, offset subject3_msg
call writestring
Page 7 of 17
call readdec
mov sub3, eax
mov edx, offset subject4_msg
call writestring
call readdec
mov sub4, eax
mov edx, offset subject5_msg
call writestring
call readdec
mov sub5, eax
; Total marks
mov eax, sub1
add eax, sub2
add eax, sub3
add eax, sub4
add eax, sub5
mov total_marks, eax
; Percentage
mov eax, total_marks
mov ebx, 100
mul ebx
Page 8 of 17
mov ebx, 500
div ebx
mov percentage, eax
; display result
mov edx, offset result_msg
call writestring
mov eax, total_marks
call writedec
call crlf
; display percentage
mov edx, offset percentage_msg
call writestring
mov eax, percentage
call writedec
call crlf
; exit program
call waitmsg
exit
main endp
end main
Page 9 of 17
Output
● Question 3
.model small
include Irvine32.inc
.data
prompt_msg byte "Enter multi digit number : ", 0
result_msg byte "The sum of the first ", 0
sum_msg byte " natural numbers is: ", 0
num dword ?
total_sum dword ?
Page 10 of 17
.code
main proc
mov edx, offset prompt_msg
call writestring
call readint ; for reading
mov num, eax ; store the input
mov eax, num
inc eax
mov ebx, num
mul ebx
mov ebx, 2
div ebx
mov total_sum, eax
mov edx, offset result_msg
call writestring
mov eax, num
call writedec ; display num
mov edx, offset sum_msg
call writestring
mov eax, total_sum
call writedec ; display the sum
call crlf
Page 11 of 17
; exit program
call waitmsg
exit
main endp
end main
● Question 4
include Irvine32.inc
.data
msg1 byte "Enter 8 integers one by one : ", 0
msg2 byte "Addition result: ", 0
msg3 byte "Multiplication result: ", 0
msg4 byte "Subtraction result: ", 0
msg5 byte "Division result: ", 0
num1 dword ?
num2 dword ?
num3 dword ?
num4 dword ?
num5 dword ?
num6 dword ?
Page 12 of 17
num7 dword ?
num8 dword ?
add_result dword ?
mul_result dword ?
sub_result dword ?
div_result dword ?
.code
main proc
; Get input for the 8 integers
mov edx, offset msg1
call writestring
call readint
mov num1, eax
call readint
mov num2, eax
call readint
mov num3, eax
call readint
mov num4, eax
call readint
mov num5, eax
call readint
mov num6, eax
Page 13 of 17
call readint
mov num7, eax
call readint
mov num8, eax
; num1 + num2
mov eax, num1
add eax, num2
mov add_result, eax
; num3 * num4
mov eax, num3
mov ebx, num4
mul ebx
mov mul_result, eax
; num5 - num6
mov eax, num5
sub eax, num6
mov sub_result, eax
;num7 / num8
mov eax, num7
xor edx, edx
Page 14 of 17
mov ebx, num8
div ebx
mov div_result, eax
; Display results
; Display addition
mov edx, offset msg2
call writestring
mov eax, add_result
call writedec
call crlf
; Display multiplication
mov edx, offset msg3
call writestring
mov eax, mul_result
call writedec
call crlf
; Display subtraction
mov edx, offset msg4
call writestring
mov eax, sub_result
cmp eax, 0
Page 15 of 17
jge sub_display
call writedec
jmp end_sub
sub_display:
call writedec
end_sub:
call crlf
; Display division
mov edx, offset msg5
call writestring
mov eax, div_result
call writedec
call crlf
; Exit program
call waitmsg
exit
main endp
end main
Page 16 of 17
● Question 5
Output
● Question 6
inclu
Output
Page 17 of 17