0% found this document useful (0 votes)
3 views23 pages

Assembly_Assignment_Solutions

This document contains a series of assembly language programming assignments for a course in Computer Organization & Assembly Language (COAL). Each problem outlines a specific task, such as printing numbers, letters, or specific characters, along with the expected output and the corresponding assembly code. The assignments are structured to help students practice and understand assembly programming concepts.

Uploaded by

mahaz70ali
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)
3 views23 pages

Assembly_Assignment_Solutions

This document contains a series of assembly language programming assignments for a course in Computer Organization & Assembly Language (COAL). Each problem outlines a specific task, such as printing numbers, letters, or specific characters, along with the expected output and the corresponding assembly code. The assignments are structured to help students practice and understand assembly programming concepts.

Uploaded by

mahaz70ali
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

LAB ASSIGNMENT

COAL

Student Name: Mahaz Ali


Roll Number: F23-0343
Section: Section D
Subject: Computer Organization & Assembly
Language (COAL)
Submitted To: Ms. Javeria Niaz
Submission Date: June 1, 2026
Problem 1: Write a program in assembly to print numbers from 0 to 9.
Expected Output: 0 1 2 3 4 5 6 7 8 9

org 100h

section .text
start:
mov cx, 10 ; Loop counter (10 iterations)
mov dl, '0' ; Start character '0' (ASCII 48)

print_loop:
push dx ; Save current character
mov ah, 02h ; DOS print character function
int 21h ; Print character in DL

mov dl, ' ' ; Print a space separator


mov ah, 02h
int 21h

pop dx ; Restore character


inc dl ; Move to next number
loop print_loop ; Decrement CX, jump if CX != 0

mov ah, 4Ch ; Exit program


int 21h

Problem 2: Write a program in assembly to print even numbers from 2 to


10.
Expected Output: 2 4 6 8 10

org 100h

section .text
start:
mov bl, 2 ; Start value

print_loop:
; Check if we need to print 10 (two digits)
cmp bl, 10
je print_ten

; Print single digit (2, 4, 6, 8)


mov dl, bl
add dl, '0' ; Convert to ASCII
mov ah, 02h
int 21h
jmp print_space

print_ten:
mov dl, '1'
mov ah, 02h
int 21h
mov dl, '0'
int 21h

print_space:
mov dl, ' '
mov ah, 02h
int 21h

add bl, 2 ; Next even number


cmp bl, 12 ; Loop until we pass 10
jne print_loop

mov ah, 4Ch


int 21h

Problem 3: Write a program in assembly to print odd numbers from 1 to 9.


Expected Output: 1 3 5 7 9

org 100h

section .text
start:
mov cx, 5 ; 5 odd numbers (1, 3, 5, 7, 9)
mov dl, '1' ; Start with '1'

print_loop:
push dx
mov ah, 02h
int 21h

mov dl, ' '


int 21h

pop dx
add dl, 2 ; Skip to next odd number
loop print_loop

mov ah, 4Ch


int 21h
Problem 4: Write a program in assembly to print uppercase letters from A
to Z.
Expected Output: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

org 100h

section .text
start:
mov cx, 26 ; 26 letters
mov dl, 'A' ; Start with 'A'

print_loop:
push dx
mov ah, 02h
int 21h

mov dl, ' '


int 21h

pop dx
inc dl ; Next uppercase letter
loop print_loop

mov ah, 4Ch


int 21h

Problem 5: Write a program in assembly to print lowercase letters from a to


z.
Expected Output: a b c d e f g h i j k l m n o p q r s t u v w x y z

org 100h

section .text
start:
mov cx, 26 ; 26 letters
mov dl, 'a' ; Start with 'a'

print_loop:
push dx
mov ah, 02h
int 21h

mov dl, ' '


int 21h

pop dx
inc dl ; Next lowercase letter
loop print_loop

mov ah, 4Ch


int 21h

Problem 6: Write a program in assembly to print * character 10 times.


Expected Output: * * * * * * * * * *

org 100h

section .text
start:
mov cx, 10 ; Loop 10 times

print_loop:
mov dl, '*'
mov ah, 02h
int 21h

mov dl, ' ' ; Space separator


int 21h
loop print_loop

mov ah, 4Ch


int 21h

Problem 7: Write a program in assembly to print countdown from 5 to 1.


Expected Output: 5 4 3 2 1

org 100h

section .text
start:
mov cx, 5 ; 5 iterations
mov dl, '5' ; Start at '5'

print_loop:
push dx
mov ah, 02h
int 21h

mov dl, ' '


int 21h

pop dx
dec dl ; Countdown
loop print_loop

mov ah, 4Ch


int 21h

Problem 8: Write a program in assembly to print numbers from 9 to 0.


Expected Output: 9 8 7 6 5 4 3 2 1 0

org 100h

section .text
start:
mov cx, 10 ; 10 digits
mov dl, '9' ; Start at '9'

print_loop:
push dx
mov ah, 02h
int 21h

mov dl, ' '


int 21h

pop dx
dec dl ; Countdown
loop print_loop

mov ah, 4Ch


int 21h

Problem 9: Write a program in assembly to print uppercase letters from Z


to A.
Expected Output: Z Y X W V U T S R Q P O N M L K J I H G F E D C B A

org 100h

section .text
start:
mov cx, 26
mov dl, 'Z' ; Start backwards

print_loop:
push dx
mov ah, 02h
int 21h

mov dl, ' '


int 21h

pop dx
dec dl ; Step backward
loop print_loop

mov ah, 4Ch


int 21h

Problem 10: Write a program in assembly to print lowercase letters from z


to a.
Expected Output: z y x w v u t s r q p o n m l k j i h g f e d c b a

org 100h

section .text
start:
mov cx, 26
mov dl, 'z' ; Start backwards

print_loop:
push dx
mov ah, 02h
int 21h

mov dl, ' '


int 21h

pop dx
dec dl ; Step backward
loop print_loop

mov ah, 4Ch


int 21h

Problem 11: Write a program in assembly to print numbers from 1 to 20.


Expected Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

org 100h
section .text
start:
mov bl, 1 ; Counter starts at 1

print_loop:
mov al, bl
mov ah, 0
mov bh, 10
div bh ; AL = quotient (tens), AH = remainder (ones)

mov cl, ah ; Save remainder


mov dl, al
cmp dl, 0 ; If tens digit is 0, skip printing it
je print_ones

add dl, '0' ; Print tens digit


push cx
mov ah, 02h
int 21h
pop cx

print_ones:
mov dl, cl
add dl, '0' ; Print ones digit
mov ah, 02h
int 21h

mov dl, ' ' ; Space separator


int 21h

inc bl ; Increment count


cmp bl, 21
jne print_loop

mov ah, 4Ch


int 21h

Problem 12: Write a program in assembly to print numbers from 20 to 1.


Expected Output: 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

org 100h

section .text
start:
mov bl, 20 ; Counter starts at 20

print_loop:
mov al, bl
mov ah, 0
mov bh, 10
div bh ; AL = tens, AH = ones

mov cl, ah ; Save ones


mov dl, al
cmp dl, 0 ; Check if tens digit is 0
je print_ones

add dl, '0'


push cx
mov ah, 02h
int 21h
pop cx

print_ones:
mov dl, cl
add dl, '0'
mov ah, 02h
int 21h

mov dl, ' '


int 21h

dec bl ; Decrement count


cmp bl, 0
jne print_loop

mov ah, 4Ch


int 21h

Problem 13: Write a program in assembly to print multiples of 2 up to 20.


Expected Output: 2 4 6 8 10 12 14 16 18 20

org 100h

section .text
start:
mov bl, 2 ; Start value

print_loop:
mov al, bl
mov ah, 0
mov bh, 10
div bh ; AL = tens, AH = ones

mov cl, ah ; Save ones


mov dl, al
cmp dl, 0
je print_ones

add dl, '0'


push cx
mov ah, 02h
int 21h
pop cx

print_ones:
mov dl, cl
add dl, '0'
mov ah, 02h
int 21h

mov dl, ' '


int 21h

add bl, 2 ; Next multiple of 2


cmp bl, 22 ; Loop until 20 is printed
jne print_loop

mov ah, 4Ch


int 21h

Problem 14: Write a program in assembly to print multiples of 5 up to 50.


Expected Output: 5 10 15 20 25 30 35 40 45 50

org 100h

section .text
start:
mov bl, 5 ; Start value

print_loop:
mov al, bl
mov ah, 0
mov bh, 10
div bh ; AL = tens, AH = ones

mov cl, ah ; Save ones


mov dl, al
cmp dl, 0
je print_ones

add dl, '0'


push cx
mov ah, 02h
int 21h
pop cx

print_ones:
mov dl, cl
add dl, '0'
mov ah, 02h
int 21h

mov dl, ' '


int 21h

add bl, 5 ; Next multiple of 5


cmp bl, 55 ; Loop until 50 is printed
jne print_loop

mov ah, 4Ch


int 21h

Problem 15: Write a program in assembly to print lowercase vowels.


Expected Output: a e i o u

org 100h

section .data
vowels db 'a', 'e', 'i', 'o', 'u'

section .text
start:
mov si, vowels ; Load address of vowels array
mov cx, 5 ; 5 vowels to loop through

print_loop:
mov dl, [si] ; Load character from array
mov ah, 02h
int 21h

mov dl, ' ' ; Space separator


int 21h

inc si ; Point to next vowel in memory


loop print_loop

mov ah, 4Ch


int 21h
Problem 16: Write a program in assembly to print uppercase vowels.
Expected Output: A E I O U

org 100h

section .data
vowels db 'A', 'E', 'I', 'O', 'U'

section .text
start:
mov si, vowels ; Point to the array of vowels
mov cx, 5 ; Loop 5 times

print_loop:
mov dl, [si]
mov ah, 02h ; DOS print character function
int 21h

mov dl, ' ' ; Print space separator


int 21h

inc si ; Move to next vowel


loop print_loop

mov ah, 4Ch ; Exit


int 21h

Problem 17: Write a program in assembly to print # character 15 times.


Expected Output: # # # # # # # # # # # # # # #

org 100h

section .text
start:
mov cx, 15 ; Set loop counter to 15

print_loop:
mov dl, '#'
mov ah, 02h
int 21h

mov dl, ' ' ; Print space separator


int 21h
loop print_loop

mov ah, 4Ch


int 21h

Problem 18: Write a program in assembly to print reverse odd numbers.


Expected Output: 9 7 5 3 1

org 100h

section .text
start:
mov cx, 5 ; 5 odd numbers (9, 7, 5, 3, 1)
mov dl, '9' ; Start with '9'

print_loop:
push dx
mov ah, 02h
int 21h

mov dl, ' '


int 21h

pop dx
sub dl, 2 ; Decrement by 2 to get previous odd number
loop print_loop

mov ah, 4Ch


int 21h

Problem 19: Write a program in assembly to print reverse even numbers.


Expected Output: 10 8 6 4 2

org 100h

section .text
start:
mov bl, 10 ; Start value

print_loop:
cmp bl, 10 ; Check if we need to print '10' (two digits)
je print_ten

mov dl, bl
add dl, '0' ; Convert to ASCII character
mov ah, 02h
int 21h
jmp print_space
print_ten:
mov dl, '1' ; Print '1'
mov ah, 02h
int 21h
mov dl, '0' ; Print '0'
int 21h

print_space:
mov dl, ' '
mov ah, 02h
int 21h

sub bl, 2 ; Go to previous even number


cmp bl, 0 ; Stop when we reach 0
jne print_loop

mov ah, 4Ch


int 21h

Problem 20: Write a program in assembly to print digits with commas.


Expected Output: 1,2,3,4,5

org 100h

section .text
start:
mov cx, 5 ; Loop for 5 digits (1 to 5)
mov dl, '1' ; Start with '1'

print_loop:
push dx
mov ah, 02h ; Print digit
int 21h
pop dx

cmp dl, '5' ; If it's the last digit, skip printing the comma
je skip_comma

push dx
mov dl, ',' ; Print comma
mov ah, 02h
int 21h
pop dx

inc dl ; Next digit


loop print_loop
skip_comma:
mov ah, 4Ch
int 21h

Problem 21: Write a program in assembly to print your name 10 times.


Expected Output: John Doe
[Repeated 10 times]

org 100h

section .data
name_str db 'Mahaz Ali', 0Dh, 0Ah, '$' ; Configured with student's name

section .text
start:
mov cx, 10 ; Loop 10 times

print_loop:
push cx ; Save CX register
mov dx, name_str ; Load address of string
mov ah, 09h ; DOS print string function
int 21h
pop cx ; Restore CX register
loop print_loop

mov ah, 4Ch


int 21h

Problem 22: Write a program in assembly to print the following pattern.


Expected Output: 1 2 3 4 55 4 3 2 1

org 100h

section .text
start:
; --- Part 1: Ascending 1 to 5 ---
mov cx, 5
mov dl, '1'
print_up:
push dx
mov ah, 02h
int 21h

mov dl, ' ' ; Print space separator


int 21h
pop dx
inc dl
loop print_up

; --- Part 2: Descending 5 to 1 ---


mov cx, 5
mov dl, '5'
print_down:
push dx
mov ah, 02h
int 21h

; Skip space after the very last digit '1' to match expected output
structure precisely
cmp dl, '1'
je skip_space

mov dl, ' '


int 21h

skip_space:
pop dx
dec dl
loop print_down

mov ah, 4Ch


int 21h

Problem 23: Write a program in assembly to print uppercase and lowercase


letters.
Expected Output: A B C D E
a b c d e

org 100h

section .text
start:
; --- Line 1: Uppercase A to E ---
mov cx, 5
mov dl, 'A'
print_upper:
push dx
mov ah, 02h
int 21h
mov dl, ' '
int 21h
pop dx
inc dl
loop print_upper

; Print Newline
mov dl, 0Dh
mov ah, 02h
int 21h
mov dl, 0Ah
int 21h

; --- Line 2: Lowercase a to e ---


mov cx, 5
mov dl, 'a'
print_lower:
push dx
mov ah, 02h
int 21h
mov dl, ' '
int 21h
pop dx
inc dl
loop print_lower

mov ah, 4Ch


int 21h

Problem 24: Write a program in assembly to print all digits and alphabets.
Expected Output: 0 1 2 3 4 5 6 7 8 9
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z

org 100h

section .text
start:
; --- Line 1: 0 to 9 ---
mov cx, 10
mov dl, '0'
loop_digits:
push dx
mov ah, 02h
int 21h
mov dl, ' '
int 21h
pop dx
inc dl
loop loop_digits
call print_newline

; --- Line 2: A to Z ---


mov cx, 26
mov dl, 'A'
loop_upper:
push dx
mov ah, 02h
int 21h
mov dl, ' '
int 21h
pop dx
inc dl
loop loop_upper

call print_newline

; --- Line 3: a to z ---


mov cx, 26
mov dl, 'a'
loop_lower:
push dx
mov ah, 02h
int 21h
mov dl, ' '
int 21h
pop dx
inc dl
loop loop_lower

mov ah, 4Ch


int 21h

; Helper procedure for Newline


print_newline:
mov dl, 0Dh
mov ah, 02h
int 21h
mov dl, 0Ah
int 21h
ret
Problem 25: Write a program in assembly to print the following triangular
pattern.
Expected Output: 1
1 2
1 2 3

org 100h

section .data
row_count db 1 ; Holds current row limit

section .text
start:
mov bl, 3 ; Total rows to print = 3

outer_loop:
mov cl, [row_count] ; Set inner loop counter to row_count
mov dl, '1' ; Reset print character to '1' for every row

inner_loop:
push dx
mov ah, 02h ; Print current digit
int 21h

mov dl, ' ' ; Print space separator


int 21h
pop dx

inc dl ; Move to next digit


dec cl ; Decrement inner counter manually
jnz inner_loop

; Print Newline at end of row


mov dl, 0Dh
mov ah, 02h
int 21h
mov dl, 0Ah
int 21h

inc byte [row_count]; Increase row size limit


dec bl ; Decrement total rows remaining
jnz outer_loop

mov ah, 4Ch


int 21h
Problem 26: Write a program in assembly to print stars in triangular form.
Expected Output: *
* *
* * *

org 100h

section .data
row_count db 1

section .text
start:
mov bl, 3 ; Total rows = 3

outer_loop:
mov cl, [row_count]

inner_loop:
mov dl, '*'
mov ah, 02h
int 21h

mov dl, ' '


int 21h

dec cl
jnz inner_loop

; Print Newline
mov dl, 0Dh
mov ah, 02h
int 21h
mov dl, 0Ah
int 21h

inc byte [row_count]


dec bl
jnz outer_loop

mov ah, 4Ch


int 21h

Problem 27: Write a program in assembly to print letters vertically.


Expected Output: A
B
C
D
E

org 100h

section .text
start:
mov cx, 5 ; Print 5 letters (A to E)
mov dl, 'A'

print_loop:
push dx
mov ah, 02h
int 21h ; Print Character

mov dl, 0Dh ; Carriage return


int 21h
mov dl, 0Ah ; Line feed (move to next vertical line)
int 21h

pop dx
inc dl
loop print_loop

mov ah, 4Ch


int 21h

Problem 28: Write a program in assembly to print numbers vertically in


reverse order.
Expected Output: 5
4
3
2
1

org 100h

section .text
start:
mov cx, 5 ; Print 5 numbers (5 to 1)
mov dl, '5'

print_loop:
push dx
mov ah, 02h
int 21h ; Print Character
mov dl, 0Dh ; Carriage return
int 21h
mov dl, 0Ah ; Line feed
int 21h

pop dx
dec dl
loop print_loop

mov ah, 4Ch


int 21h

Problem 29: Write a program in assembly to print uppercase and lowercase


letters alternately.
Expected Output: A a B b C c D d E e

org 100h

section .text
start:
mov cx, 5 ; 5 pairs of letters
mov bl, 'A' ; Tracking current Uppercase character
mov bh, 'a' ; Tracking current Lowercase character

print_loop:
; Print Uppercase
mov dl, bl
mov ah, 02h
int 21h

mov dl, ' '


int 21h

; Print Lowercase
mov dl, bh
mov ah, 02h
int 21h

mov dl, ' '


int 21h

inc bl ; Increment both tracking registers


inc bh
loop print_loop

mov ah, 4Ch


int 21h

Problem 30: Write a program in assembly to print the following sequence.


Expected Output: 1 2 3 4 5 4 3 2 1

org 100h

section .text
start:
; --- Part 1: Ascending 1 to 5 ---
mov cx, 5
mov dl, '1'
print_up:
push dx
mov ah, 02h
int 21h

mov dl, ' '


int 21h

pop dx
inc dl
loop print_up

; --- Part 2: Descending 4 to 1 ---


mov cx, 4
mov dl, '4'
print_down:
push dx
mov ah, 02h
int 21h

cmp dl, '1' ; Skip trailing space on last digit


je skip_space

mov dl, ' '


int 21h

skip_space:
pop dx
dec dl
loop print_down

mov ah, 4Ch


int 21h

You might also like