Professional Documents
Culture Documents
Answer For Malp
Answer For Malp
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
2
Microprocessor and assembly language programming Group Assignment
ANSWER
1. .MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 2
INT 21H
INT 21H
INT 21H
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
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 CHAR, AL
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
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
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
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
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
.DATA
.CODE
MOV AX, @DATA
MOV DS, AX
END
.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
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
.CODE
MOV CX, 10
MOV DX,48
L1:
MOV AH, 2
INT 21H
INC DX
LOOP L1
END
12