EEE 3104 Codes Only
EEE 3104 Codes Only
push ax
push bx
mov ah, 01h ; get char from keyboard
int 21h ; call DOS service
sub al, '0' ; ASCII num to decimal
mov bh, 0ah
mul bh ; multiply by 10
mov num, al ; store first digit in NUM
mov ah, 01h ; get char from keyboard
int 21h ; call DOS service
sub al, '0' ; ASCII num to decimal
add num, al ; add second digit
pop bx
pop bx
endm
endm
_DATA ends
_CODE segment
start:
mov ax, _DATA ; initialize DS to the data segment
mov ds, ax
printstring msg1
readnum num ; read count
mov si, offset ntable ; SI = table address
mov ch, 00
mov cl, num ; CX = num = number of data
nextread:
printstring msg2
mov bh, 00
mov bl, [si]
add ax, bx ; add number with previous sum
inc cl
jmp nextchk
nomore:
rpt2:
pop ax ; pop data
inc si ; advance result string pointer
mov [si], al ; store in result
loop rpt2 ; are all data popped out, if not repeat
inc si
mov al, '$'
mov [si], al ; append end of string
pop si ; restore the registers
pop dx
pop cx
pop bx
pop ax
ret
hex2asc endp
Exp-02
Write and execute an assembly language program that reads a number and
checks whether it is odd or even or prime.
mov num, al
mov ah, 01h
int 21h
sub al, '0'
add num, al
endm
endm
_DATA segment
cr equ 0dh
lf equ 0ah
msg1 db 'Enter number <XX>: ', '$'
msg2 db cr, lf, 'Even number.', '$'
msg3 db cr, lf, 'Odd number.', '$'
msg4 db cr, lf, 'Prime number.', '$'
msg5 db cr, lf, 'Not prime number.', '$'
num db ?
_DATA ends
_CODE segment
mov ds, ax
printstring msg1
readnum num
mov ah, 00
mov al, num
mov bl, 02
div bl
mov bh, 00
mov bl, al
cmp ah, 00
je evennum
printstring msg3
jmp checkprime
checkprime:
and dx, 00
mov ah, 00
mov al, num
cmp al, 01
jle notprime
cmp al, 02
je isprime
mov ch, 00
mov cl, 02
chkprm2:
div cx
cmp dx, 00
je notprime
and dx, 00
mov ah, 00
mov al, num
inc cx
cmp bx, cx
jge chkprm2
isprime:
printstring msg4
jmp skip
notprime:
printstring msg5
skip:
_CODE ends
end start
Exp-03
Write and execute an ALP that reads N numbers from the keyboard and sorts
these N numbers in ascending/descending order.
_DATA segment
cr equ 0dh
lf equ 0ah
msg1 db 'Number of elements <XX>: $'
msg2 db cr, lf, 'Enter element <XX>: $'
msg3 db cr, lf, 'Elements in ascending order...$'
count db ?
tabl db 20 dup(0)
tnum db ?
resdisp db 4 dup(0)
_DATA ends
_CODE segment
assume cs: _CODE, ds: _DATA
start: mov ax, _DATA
mov ds, ax
printstring msg1
readnum count
mov ch, 00h
mov cl, count
mov bx, 01
rdnxt:
printstring msg2
readnum tnum
mov al, tnum
mov tabl[bx], al
inc bx
loop rdnxt
mov ch, 00
mov cl, count
cmp cx,01
je done
nextpass:
mov dl, 00
mov bx, 01
nextj:
mov al, tabl[bx]
mov ah, tabl[bx+1]
cmp al, ah
jle skip
mov dl,01
mov tabl[bx], ah
mov tabl[bx+1], al
skip:
inc bx
cmp bx, cx
jl nextj
dec cx
jz done
cmp dl, 01
je nextpass
done:
mov ch, 00h
mov cl, count
mov bx, 01
mov si, offset resdisp
printstring msg3
prnxt:
mov ah, 00
mov al, tabl[bx]
call hex2asc
printstring resdisp
inc bx
loop prnxt
rpt2: pop ax
inc si
mov [si], al
loop rpt2
inc si
mov al,'$'
mov [si], al
pop si
pop dx
pop cx
pop bx
pop ax
ret
hex2asc endp
_CODE ends
end start
Exp-04
Write and execute an assembly language program to calculate the largest number
from N numbers. All N numbers should be read interactively from the keyboard.
pop bx
pop ax
endm
endm
_DATA segment
cr equ 0dh
lf equ 0ah
msg1 db 'How many numbers <XX>: $'
msg2 db cr, lf, 'Enter number: $'
msg3 db cr, lf, 'Largest number is: $'
count db ?
tnum db ?
tabl db 100 dup(0)
result db 4 dup('$')
_DATA ends
_CODE segment
start:
readnext:
printstring msg2
readnum tnum
mov al, tnum
mov tabl[bx], al
inc bx
loop readnext
mov ch, 00
mov cl, count
mov bx, 00
mov dx, 00
checknext:
skip:
inc bx
loop checknext
mov ax, dx
mov si, offset result
call hex2asc
printstring msg3
printstring result
mov ah, 4ch
mov al, 00h
int 21h
push ax
push bx
push cx
push dx
push si
mov cx, 00h
mov bx, 0ah
rpt1:
mov dx, 00
div bx
add dl, '0'
push dx
inc cx
cmp ax, 0ah
jge rpt1
rpt2:
pop ax
inc si
mov [si], al
loop rpt2
inc si
mov al, '$'
mov [si], al
pop si
pop dx
pop cx
pop bx
pop ax
ret
hex2asc endp
_CODE ends
end start
Exp-05
Write and execute an ALP that displays any 10 decimal numbers and its
corresponding ASCII characters.
endm
_DATA segment
cr equ 0dh
lf equ 0ah
tab equ 09h
msg1 db 'ASCII table set display...$'
msg2 db cr, lf, 'Decimal', tab, 'Character$'
newline db cr, lf, '$'
asc_char db 48
result db 20 dup('$')
_DATA ends
_CODE segment
start:
nextchar:
mov ah, 00
mov al, asc_char
mov si, offset result
call hex2asc
printstring newline
printstring result
mov ah, 02
mov dl, tab
int 21h
mov ah, 02
mov dl, asc_char
int 21h
inc asc_char
loop nextchar
push ax
push bx
push cx
push dx
push si
rpt1:
mov dx, 00
div bx
add dl, '0'
push dx
inc cx
cmp ax, 0ah
jge rpt1
add al, '0'
mov [si], al
rpt2:
pop ax
inc si
mov [si], al
loop rpt2
inc si
mov al, '$'
mov [si], al
pop si
pop dx
pop cx
pop bx
pop ax
ret
hex2asc endp
_CODE ends
end start
Exp-06
Write and execute an ALP to read an 8-bit binary number from the keyboard,
store it in BX and display the number in reverse order in the next line.
mov ah,09h
mov dx,offset msg
int 21h
endm
_DATA segment
cr equ 0dh
lf equ 0ah
msg1 db 'Enter the 8-bit number:','$'
msg2 db cr,lf,'Binary number in reverse order:','$'
msg3 db cr,lf,'Illegal Input','$'
_Data ends
_CODE segment
assume cs:_CODE,ds:_DATA
start:
mov ax,_DATA
mov ds,ax
printstring msg1
xor bx,bx
mov cx,8
mov ah,01h
input:
int 21h
cmp al,'0'
je continue
cmp al,'1'
jne errormsg
continue:
sub al,'0'
shl bx,1
or bl,al
loop input
printstring msg2
mov cx,8
mov ah,02h
output:
sar bx,1
jnc zero
mov dl,31h
jmp display
zero:
mov dl,30h
display:
int 21h
loop output
jmp finish
errormsg:
printstring msg3
finish:
mov ah,4ch
mov al,00h
int 21h
_CODE ends
end start
Exp-07
Write and execute an Assembly Language Program (ALP) to 8086 processor to
reverse the given string and verify whether it is a palindrome.
mov ah,09h
mov dx,offset msg
int 21h
endm
_DATA segment
_DATA ends
_CODE segment
assume cs:_CODE,ds:_DATA
start:
mov ax,_DATA
mov ds,ax
printstring msg1
mov si, offset buff
mov bx, 00
rdchar:
dec bx
mov strlen, bx
mov si, offset buff
add si, bx
mov di, offset revbuff
mov cx, bx
nxtchar1:
dec si
mov al, [si]
mov [di], al
inc di
loop nxtchar1
nxtchar2:
inc si
inc di
loop nxtchar2
palindrome:
printstring msg3
jmp skip
notpali:
printstring msg4
skip:
_CODE ends
end start
Exp-08
Write and execute an ALP to read an 8-bit binary number from the keyboard,
save it in DH register, convert it in Hexadecimal code and display the result in
the next line.
endm
_DATA segment
cr equ 0dh
lf equ 0ah
msg1 db 'Enter the 8-bit binary number: ', '$'
msg2 db cr, lf, 'Hexadecimal code of the binary number: ', '$'
msg3 db cr, lf, 'Illegal input.', '$'
_DATA ends
_CODE segment
start:
input:
int 21h
cmp al, '0'
je continue
cmp al, '1'
jne errormsg
continue:
done:
output:
cmp cx, 2
je finish
inc cx
mov dl, bh
push cx
mov cx, 4
shift1:
shr dl, 1
loop shift1
pop cx
cmp dl, 0ah
jl digit
add dl, '7'
jmp next
digit:
next:
int 21h
push cx
mov cx, 4
shift2:
rol bx, 1
loop shift2
pop cx
jmp output
errormsg:
printstring msg3
finish:
_CODE ends
end start
Exp-09
Write and execute an ALP to 8086 processor to add, subtract and multiply two
16 bit unsigned numbers. Store the result in extra segment.
_DATA segment
cr equ 0dh
lf equ 0ah
num1 dw 6532h
num2 dw 3452h
_DATA ends
_EXTRA segment
sum dw 0
subt dw 0
multl dw 0
multh dw 0
_EXTRA ends
_CODE segment
assume cs:_CODE, ds:_DATA, es:_EXTRA
start:
mov ax, _DATA
mov ds, ax
mov ax, _EXTRA
mov es, ax
printstring msg1
mov bx, es:sum
call printhex
mov bh, bl
call printhex
printstring msg2
mov bx, es:subt
call printhex
mov bh, bl
call printhex
printstring msg3
mov bx, es:multh
call printhex
mov bh, bl
call printhex
mov dl, bh
shr dl, 4
hexout:
cmp dl, 10
jge alt
add dl, '0'
jmp fin
alt:
add dl, '7'
fin:
int 21h
mov dl, bh
and dl, 0fh
loop hexout
pop dx
pop cx
pop bx
pop ax
ret
_CODE ends
end start
Exp-10
Write and execute an ALP to 8086 processor to find the length of a given string.
DATA segment
cr equ 0dh
lf equ 0ah
msg1 db 'Enter string: $'
msg2 db cr,lf,'String length= $'
strlen dw 0
result dw 20 dup(0)
DATA ends
CODE segment
assume cs:CODE,ds:DATA
start:
mov ax,DATA
mov ds,ax
printstring msg1
mov ah,01h
string:
int 21h
cmp al,cr
je finish
inc strlen
loop string
finish:
printstring msg2
mov si,offset result
mov ax,00
mov ax,strlen
call hex2asc
printstring result
mov ah,4ch
mov ah,00h
int 21h
mov cx,00
mov bx,0ah
rpt:
mov dx,00
div bx
add dl,'0'
push dx
inc cx
cmp ax,0ah
jge rpt
add al,'0'
mov [si],al
rpt2:
pop ax
inc si
mov [si],al
loop rpt2
inc si
mov al,'$'
mov [si],al
pop si
pop dx
pop cx
pop bx
pop ax
ret
hex2asc endp
CODE ends
end start
Exp-11
Write and execute an ALP to 8086 processor to verify the password.
CODE segment
assume cs:CODE,ds:DATA
start: mov ax,DATA
mov ds,ax
mov ch,00
mov cl,count
printstring msg1
mov si,offset given
read:
mov ah,07
int 21h
cmp al,cr
je next
mov [si],al
mov ah,02
mov dl,'*'
int 21h
inc si
jmp read
compare:
mov al,[si]
mov bl,[di]
cmp al,bl
jne inco
inc si
inc di
loop compare
jmp cor
inco:
printstring msg2
jmp finish
cor:
printstring msg3
finish:
mov ah,4ch
mov ah,00h
int 21h
CODE ends
end start