0% found this document useful (0 votes)
12 views12 pages

Coal Assign 2 016

Uploaded by

mubasharayesha95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views12 pages

Coal Assign 2 016

Uploaded by

mubasharayesha95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

computer organization and assembly language

Assignment No. 2

Name: AYESHA MUBASHAR


Roll No.: 016
Program: BSCS
Section: BLUE
Submitted To: MAM WARDA

TABLE OF CONTENTS
Sr. Page
Question Description
No. No.
Print numbers from 1 to 9 using conditional and
1 2
unconditional jumps
2 Print numbers from 1 to 9 using loop instruction 2
Check if a number is even or odd and display result in
3 3
assembly language
Count the number of characters in an input line and
4 4
display the result
Calculate sum of first 50 terms of arithmetic sequence
5 5
1,5,9,13,... in assembly
Read a six-character password, overwrite it with a
6 6
carriage return and display asterisks

QUESTION NO 01
Print numbers from 1 to 9 using conditional and unconditional jumps.
SOLVE:
.model small

1|Page
.stack 100h
.data
.code
main proc
mov ax, @data
mov ds, ax
mov cl, 1
top:
mov ah, 02h
add cl, 30h
mov dl, cl
int 21h
sub cl, 30h
cmp cl, 9
je Exit
inc cl
jmp top
Exit:
mov ah, 4ch
int 21h
main endp
end main

QUESTION NO 02
Print numbers from 1 to 9 using loop instruction.
SOLVE:
.model small

2|Page
.stack 100h
.data
.code
main proc
mov ax, @data
mov ds, ax
mov cx, 9
mov dl, '1'
print:
mov ah, 02h
int 21h
inc dl
loop print
mov ah, 4ch
int 21h
main endp
end main

QUESTION NO 03
Write an assembly language code for the following.
Enter a number=
If it is even

3|Page
Display ""Even"
Else
Display "Odd"
SOLVE:
.model small
.stack 100h
.data
msg1 db 'Enter a number=$'
msg2 db 0Dh,0Ah,'Even$'
msg3 db 0Dh,0Ah,'Odd$'
.code
main proc
mov ax, @data
mov ds, ax
mov ah, 09h
lea dx, msg1
int 21h
mov ah, 01h
int 21h
sub al, 30h
test al, 1
jz even
odd:
mov ah, 09h
lea dx, msg3
int 21h
jmp Exit

4|Page
even:
mov ah, 09h
lea dx, msg2
int 21h
Exit:
mov ah, 4ch
int 21h
main endp
end main

QUESTION NO 04
Write an assembly language code to count the number of characters in an input
line and display the result.

5|Page
SOLVE:
.model small
.stack 100h
.data
msg1 db 'Enter characters= $'
msg2 db 0Dh,0Ah,'Total characters = $'
count db 0
.code
main proc
mov ax, @data
mov ds, ax
mov ah, 09h
lea dx, msg1
int 21h
read_char:
mov ah, 01h
int 21h
cmp al, 13
je show_count
inc count
jmp read_char
show_count:
mov ah, 09h
lea dx, msg2
int 21h
mov al, count
add al, 30h

6|Page
mov dl, al
mov ah, 02h
int 21h
mov ah, 4ch
int 21h
main endp
end main

QUESTION NO 05
Write an assembly language code to put the sum of 1 50 terms of arithmetic
sequence 1,5,9,13,... in DX.

7|Page
SOLVE:
.model small
.stack 100h
.data
msg_result db 0Dh,0Ah, 'Sum of sequence = $'
.code
main proc
mov ax, @data
mov ds, ax
mov ah, 09h
lea dx, msg_result
int 21h
; Sn = n/2 * (2a + (n-1)d)
mov ax, 49
mov bx, 4
mul bx
add ax, 2
mov bx, 25
mul bx
mov dx, ax
mov ax, dx
call print_number
mov ah, 4Ch
int 21h
main endp
print_number proc
mov cx, 0

8|Page
next_digit:
mov dx, 0
mov bx, 10
div bx
push dx
inc cx
cmp ax, 0
jne next_digit
print_digits:
pop dx
add dl, 30h
mov ah, 02h
int 21h
loop print_digits
ret
print_number endp
end main

QUESTION NO 06
Read a six characters password and overwrite it by executing carriage return and
display six *. You need not to save the input characters.

9|Page
SOLVE:
.model small
.stack 100h
.data
Msg1 db 'Enter 6 character password: $'
.code
main proc
mov ax, @data
mov ds, ax
mov ah, 09h
lea dx, Msg1
int 21h
mov cx, 6
read_loop:
mov ah, 01h
int 21h
mov ah, 02h
mov dl, '*'
int 21h
loop read_loop
mov ah, 02h
mov dl, 0Dh
int 21h
mov dl, 0Ah
int 21h
mov ah, 4Ch
mov al, 0

10 | P a g e
int 21h
main endp
end main

11 | P a g e

You might also like