Microprocessor and assembly language programming Group Assignment
School of informatics
Department of computer science
SECTION 1
GROUP NAME ID NO
1. Biniyam Girma…………………………………………………...UGR/53757/13
2. Jerbaw Amsaya……………………………………………………..UGR/55264/13
3. Nanati Getachew……………………………………………....UGR/53323/13
4. Genet Temesgen………………………………………………..UGR/52928/13
5. Kassahun Kefyalew……………………………………………..UGR/54203/13
6. Mehabaw Alehegn……………………………………………..UGR/52599/13
Assignment Questions
1. write the assembly language program to print a character from user
2. write the assembly language program to add two numbers
3. write the assembly language program to print A to Z numbers using
loop
4. write the assembly language program to check whether the entered
character is alphabet or special character or number
1
Microprocessor and assembly language programming Group Assignment
5. Write the assembly language program to print the following shape using
number
1
12
123
1234
12345
6. Write the assembly language program to display the following shape by
using stars.
7. Write the assembly language program to print the following shape
8. Write the assembly language program to print following shape
2
Microprocessor and assembly language programming Group Assignment
9. Write the assembly language program to print a character H
10. Write the assembly language program to print only vowels
11. Write the assembly language program that asks the user to enter
characters and printing that characters
12. Write the assembly language program that display 0 to 9 numbers
using loop
ANSWER
1. .MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1 ;READ
INT 21H
MOV BL,AL ;SAVE INPUT
MOV AH, 2
INT 21H
INT 21H
MOV AH,2 ;DISPLAY CHAR
MOV DL, BL
INT 21H
MOV AH, 4CH ;RETURN
INT 21H
MAIN ENDP
3
Microprocessor and assembly language programming Group Assignment
END
2. org 100h
.model small
.code
mov ax,3
mov bx,5h
add ax,bx
add ax,30h
mov ah,02h
mov dx,ax
int 21h
.exit
end
ret
3. .MODEL SMALL
.STACK 100H
.CODE
MOV CX, 26
MOV DX,65
L1:
MOV AH, 2
INT 21H
INC DX
LOOP L1
MOV AH, 4CH
INT 21H
END
4.
.MODEL SMALL
.STACK 100h
.DATA
CHAR DB ?
MSG_ALPHABET DB 'The entered character is an alphabet.', 0Dh, 0Ah, '$'
MSG_SPECIAL DB 'The entered character is a special character.', 0Dh, 0Ah, '$'
MSG_NUMBER DB 'The entered character is a number.', 0Dh, 0Ah, '$'
MSG_in DB 'Enter the input ', 0Dh, 0Ah, '$'
.CODE
4
Microprocessor and assembly language programming Group Assignment
MOV AX, @DATA
MOV DS, AX
MOV AH, 09h
LEA DX, MSG_in
INT 21h
MOV AH, 01h
INT 21h ; Read a character from the user
MOV CHAR, AL
CMP CHAR, 41h ; Check if the character is in the range A-Z
JL check_special ; If not, check if it is a special character
CMP CHAR, 5Ah ; Check if the character is in the range A-Z
JLE alphabet_found ; If so, it is an alphabet character
check_special:
CMP CHAR, 30h ; Check if the character is in the range 0-9
JL special_found ; If not, it is a special character
CMP CHAR, 39h ; Check if the character is in the range 0-9
JLE number_found ; If so, it is a number
special_found:
MOV AH, 09h
LEA DX, MSG_SPECIAL
INT 21h ; Display a message that the character is a special character
JMP exit_program
number_found:
MOV AH, 09h
LEA DX, MSG_NUMBER
INT 21h ; Display a message that the character is a number
JMP exit_program
alphabet_found:
MOV AH, 09h
LEA DX, MSG_ALPHABET
INT 21h ; Display a message that the character is an alphabet
exit_program:
MOV AH, 4Ch
INT 21h ; Exit program
END
5.
.model small
.stack 100h
5
Microprocessor and assembly language programming Group Assignment
.data
max_rows dw 5
current_row dw 1
current_column dw 1
number db 1
newline db 0ah, 0dh, '$'
.code
; Set up data segment
mov ax, @data
mov ds, ax
print_shape:
; Check if we have reached the maximum number of rows
mov ax, current_row
cmp ax, max_rows
jg end_program
; Print the numbers for the current row
mov ax, current_column
cmp ax, current_row
jg next_row
; Print the current number
mov ah, 02h
mov dl, number
add dl, '0' ; Convert the number to ASCII character
int 21h
; Increment the current number and column
inc number
inc current_column
; Go to the next number in the current row
jmp print_shape
next_row:
; Display newline
lea dx, newline
mov ah, 09h
int 21h
; Increment the current row and reset the current column and number
inc current_row
mov current_column, 1
mov number, 1
; Go to the next row
jmp print_shape
end_program:
; Exit the program
mov ah, 4Ch
int 21h
6
Microprocessor and assembly language programming Group Assignment
end
6.
.model small
.stack 100h
.data
STAR DB ? ; Number of rows in the pyramid
BLANK DB ?
.CODE
MAIN PROC
MOV CX, 5
MOV BH, 9
MOV BL, 1
MOV STAR, BH
MOV BLANK, BL
L4:
CMP BLANK, 0
JE L5
MOV AH,2
MOV DL, 32
INT 21H
DEC BLANK
JMP L4
L5:
MOV AH, 2
MOV DL, '*'
INT 21H
DEC STAR
CMP STAR, 0
JNE L5
L6:
MOV AH, 2
MOV DL, 10
INT 21H
7
Microprocessor and assembly language programming Group Assignment
MOV DL, 13
INT 21H
DEC BH
DEC BH
MOV STAR, BH
INC BL
MOV BLANK, BL
LOOP L4
MOV CX, 5
MOV BX, 1
L1:
PUSH CX
L2:
MOV AH, 2
MOV DL, 32
INT 21H
LOOP L2
MOV CX, BX
L3:
MOV AH, 2
MOV DL, '*'
INT 21H
LOOP L3
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
INC BX
INC BX
POP CX
LOOP L1
MOV AH, 4CH ;RETURN
8
Microprocessor and assembly language programming Group Assignment
INT 21H
MAIN ENDP
END
7. .model small
.stack 100h
.data
STAR DB ? ; Number of rows in the pyramid
BLANK DB ?
.CODE
MAIN PROC
MOV CX, 5
MOV BX, 1
L1:
PUSH CX
L3:
MOV AH, 2
MOV DL, '*'
INT 21H
LOOP L3
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
INC BX
MOV DL, 32
POP CX
LOOP L1
mov ah, 4Ch ; exit program
int 21h
main endp
end main
9
Microprocessor and assembly language programming Group Assignment
8. .model small
.stack 100h
.data
STAR DB ? ; Number of rows in the pyramid
BLANK DB ?
.CODE
MAIN PROC
MOV CX, 5
MOV BX, 1
L1:
PUSH CX
MOV CX, BX
L3:
MOV AH, 2
MOV DL, '*'
INT 21H
LOOP L3
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
INC BX
MOV DL, 32
POP CX
LOOP L1
mov ah, 4Ch ; exit program
int 21h
main endp
end main
9. org 100h
.model small
.data
message db " H $"
10
Microprocessor and assembly language programming Group Assignment
.code
main proc
mov ah,09h
mov dx,offset message
int 21h
mov ah,4ch
mov al,00
int 21h
endp
end main
10. .MODEL SMALL
.STACK 100h
.DATA
MSG_ENTER DB 'A E I O U $'
.CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 09h
LEA DX, MSG_ENTER
INT 21h ; Display a message to enter a string
END
11. .model small
.stack 100h
.data
message db 0ah, 0dh, 'Enter a character ($ to exit): $'
buffer db 0
.code
main proc
mov ax, @data
mov ds, ax
11
Microprocessor and assembly language programming Group Assignment
print_message:
lea dx, message ; load the address of the message
mov ah, 09h ; function to print string
int 21h ; call DOS interrupt
read_char:
mov ah, 01h ; function to read a character
int 21h ; call DOS interrupt
mov [buffer], al ; store the character in the buffer
cmp byte ptr [buffer], '$' ; check if the character is '$'
je exit_program ; if it is, jump to exit_program
print_char:
mov ah, 02h ; function to print character
mov dl, [buffer] ; load the character from buffer
int 21h
; call DOS interrupt
exit_program:
mov ah, 4Ch ; exit program
int 21h
main endp
end main
12. .MODEL SMALL
.STACK 100H
.CODE
MOV CX, 10
MOV DX,48
L1:
MOV AH, 2
INT 21H
INC DX
LOOP L1
MOV AH, 4CH
INT 21H
END
12