Kingdom of Saudi Arabia
Ministry of Education
University of Bisha
College of Computer
Science and Information
Technology
Computer Science
Project for Assembly language
Calculates linear equation from the first degree
Supervisor Dr :- Omnia Babkr
Names IDs
Afnan Misfer Al-Aklabi 444801547
Remas Amer 442802817
Deema Jalwi Lazher 442802967
Tgreed saleh 442800317
Content Page
a. Input
The program requires two inputs from the user:
1. A: The coefficient of X in the equation AX + B = 0. It is a signed integer.
2. B: The constant term in the equation AX + B = 0. It is also a signed integer.
• First, the program asks the user to input the value of A.
• Next, it asks the user to input the value of B.
b. Description
This assembly program is designed to solve the linear equation AX + B = 0 for X,
using integer arithmetic.
1. Solvable Equation:
o If A ≠ 0, the equation can be solved as X = -B / A. The program will
compute the value of X and print it.
2. No Solution:
o If A = 0 and B ≠ 0, the program will display a message indicating that
there is no solution (as the equation 0X + B = 0 is invalid for B ≠ 0).
3. Infinite Solutions:
o If both A = 0 and B = 0, the equation 0X + 0 = 0 is true for all
values of X, meaning there are infinite solutions.
• Overflow Handling: It checks for integer overflow during input.
• Input Validation: Ensures that only numeric input is accepted.
• Precision: Outputs floating-point results with up to 10 decimal places.
c.Code
.model small
.stack 100h
precision = 10
.data
cr equ 0Dh
lf equ 0Ah
new_line equ 0Dh,0Ah, '$'
mess0 db 'calculation of AX + B = 0',
new_line
mess1 db 'Enter A ', '$'
2
mess2 db lf, cr, 'Enter B ', '$'
mess6 db cr, lf, 'result: ', cr, lf, '
x = ', '$'
mess7 db cr, lf, cr, lf, 'no
solution!', new_line
mess8 db cr, lf, cr, lf, 'infinite
number of solutions!', new_line
error db cr, lf, 'the number is out of
range!', new_line
twice_nl db new_line, new_line
make_minus db 0
a dw ?
b dw ?
ten dw 10
.code
main proc
mov ax, @data
mov ds, ax
mov es, ax
lea dx, mess0
call puts
lea dx, mess1
call puts
call scan_num
mov a, cx
lea dx, mess2
call puts
call scan_num
mov b, cx
cmp a, 0
jne soluble
cmp b, 0
jne no_solution
jmp infinite
soluble:
mov ax, b
neg ax
mov b, ax ; Store -b back into b for
consistency if needed later
3
mov ax, b ; AX = -b
xor dx, dx
cmp ax, 0
jns not_singned
not dx
not_singned:
mov bx, a
idiv bx
push dx
lea dx, mess6
call puts
pop dx
call print_float
jmp end_prog
no_solution:
lea dx, mess7
call puts
jmp end_prog
infinite:
lea dx, mess8
call puts
end_prog:
lea dx, twice_nl
call puts
mov ah, 4Ch
int 21h
main endp
print_float proc
push cx
push dx
cmp bx, 0
jns div_not_signed
neg dx
div_not_signed:
cmp ax, 0
jne checked
cmp dx, 0
jns checked
4
push dx
mov dl, '-'
call write_char
pop dx
checked:
call print_num
cmp dx, 0
je done
push dx
mov dl, '.'
call write_char
pop dx
mov cx, precision
call print_fraction
done:
pop dx
pop cx
ret
print_float endp
print_fraction proc
push ax
push dx
next_fraction:
cmp cx, 0
jz end_rem
dec cx
cmp dx, 0
je end_rem
mov ax, dx
xor dx, dx
cmp ax, 0
jns not_sig1
not dx
not_sig1:
imul ten
idiv bx
push dx
5
mov dx, ax
cmp dx, 0
jns not_sig2
neg dx
not_sig2:
add dl, 30h
call write_char
pop dx
jmp next_fraction
end_rem:
pop dx
pop ax
ret
print_fraction endp
print_num proc
push dx
push ax
cmp ax, 0
jnz not_zero
mov dl, '0'
call write_char
jmp printed
not_zero:
cmp ax, 0
jns positive
neg ax
mov dl, '-'
call write_char
positive:
call print_numx
printed:
pop ax
pop dx
ret
print_num endp
print_numx proc
push bx
push cx
push dx
6
mov cx, 1
mov bx, 10000
cmp ax, 0
jz end_show
begin_print:
cmp bx,0
jz end_show
cmp cx, 0
je calc
cmp ax, bx
jb skip
calc:
xor cx, cx
xor dx, dx
div bx
push dx
mov dl, al
add dl, 30h
call write_char
pop dx
mov ax, dx
skip:
push ax
xor dx, dx
mov ax, bx
div ten
mov bx, ax
pop ax
jmp begin_print
end_show:
pop dx
pop cx
pop bx
ret
print_numx endp
puts proc
push ax
7
mov ah, 09h
int 21h
pop ax
ret
puts endp
read_char proc
mov ah, 01h
int 21h
ret
read_char endp
scan_num proc
push dx
push ax
xor cx, cx
mov make_minus, 0
next_digit:
call read_char
cmp al, '-'
je set_minus
cmp al, cr
je stop_input
cmp al, '0'
jb next_digit
cmp al, '9'
ja next_digit
push ax
mov ax, cx
mul ten
mov cx, ax
pop ax
cmp dx, 0
jne out_of_range
sub al, 30h
xor ah, ah
add cx, ax
jc out_of_range
8
jmp next_digit
set_minus:
mov make_minus, 1
jmp next_digit
out_of_range:
lea dx, error
call puts
stop_input:
cmp make_minus, 0
je not_minus
neg cx
not_minus:
pop ax
pop dx
ret
scan_num endp
write_char proc
push ax
mov ah, 02h
int 21h
pop ax
ret
write_char endp
end main
9
d) Output (Print screen)
10
11