8086 programs

June 28, 2017 | Autor: Girisha G K | Categoria: 8086 Assembly Language Programming
Share Embed


Descrição do Produto

– 1: PROGRAMS INVOLVING DATA TRANSFER INSTRUCTIONS


; 1:- PROGRAM 01a.

; FILE NAME: blktrawl.asm

; Program is tested and found OK

; //PROGRAM TO TRANSFER A BLOCK OF DATA FROM ONE MEMORY
; LOCATION TO ANOTHER MEMORY LOCATION WITH OVERLAP\\


.model small
.stack
.data
memloc1 db 02h, 04h, 06h, 08h, 0ah
memloc2 db 01h, 03h, 05h, 07h, 09h

.code
mov ax, @data ;// Intialize
mov ds, ax ;data segment\\
mov cx, 05h ;intialize block counter
lea si, memloc1 ;load the offset address of source memory
location into SI
lea di, memloc2 ;load the offset address of destination mem
location into DI
back: mov al, [si+4] ;load the element pointed by SI+4 to AL
mov [di+2], al ;transfer the content of AL to mem location
pointed by DI+2
dec si ;decrement SI to point to next element of the block
dec di ;decrement Destination pointer
loop back ;if counter is not zero continue the transfer
mov ah, 4ch ;// exit to
int 21h ; DOS\\
end ;end the program


EXAMPLE RESULT:
Before execution:
[????]: 02h, 04h, 06h, 08h, 0ah, 01h, 03h, 05h, 07h, 09h
After execution:
[????]: 02h, 04h, 06h, 02h, 04h, 06h, 08h, 0ah, 07h, 09h

OBSERVED RESULT:
; 1:- PROGRAM 01b.

; FILE NAME: blktrawo.asm

; Program is tested and found OK

; //PROGRAM TO TRANSFER A BLOCK OF DATA FROM ONE MEMORY
; LOCATION TO ANOTHER MEMORY LOCATION WITHOUT OVERLAP\\


.model small
.stack
.data
memloc1 db 02h, 04h, 06h, 08h, 0ah
memloc2 db 5 dup (0)

.code
mov ax, @data ;// intialize
mov ds, ax ;data segment\\
mov cx, 05h ;intialize block counter
lea si, memloc1 ;load the offset address of src mem loc
into SI
lea di, memloc2 ;load the offset address of dest mem loc
into DI
back: mov al, [si] ;load the element pointed by SI to AL
mov [di], al ;transfer the content of AL to mem loc pointed
by DI
inc si ;increment SI to point to next element of the
block
inc di ;increment Destination pointer
loop back ;if counter is not zero continue the transfer
mov ah, 4ch ;// exit to
int 21h ; DOS\\
end ;end the program


EXAMPLE RESULT:
Before execution:
Memloc1: [????]: 02h, 04h, 06h, 08h, 0ah
Memloc2: [????]: 00h, 00h, 00h, 00h, 00h
After execution:
Memloc1: [????]: 02h, 04h, 06h, 08h, 0ah
Memloc2: [????]: 02h, 04h, 06h, 08h, 0ah


OBSERVED RESULT:
; 1:- PROGRAM 02

; FILE NAME: blkint.asm

; Program is tested and found OK

; //program to interchange a block of data of two memory
; locations\\


.model small
.stack
.data
memloc1 db 02h, 04h, 06h, 08h, 10h
memloc2 db 12h, 14h, 16h, 18h, 20h

.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
mov cx, 05h ;intialize the counter
lea si, memloc1 ;effective address of mem loc1 in si
lea di, memloc2 ;effective address of mem loc1 in di
mov es, ax
back: mov bl, [si] ;transfer the contents of si into bl
xchg bl, [di] ;exchange the contents of di and bl
mov [si], bl ;load the contents of bl into si
inc si ;increment si
inc di ;increment di
loop back ;continue the transfer till count = 0
mov ah, 4ch ;// Terminate
int 21h ; the program\\
end


EXAMPLE RESULT:
Before execution:
Memloc1: [????]: 02h, 04h, 06h, 08h, 10h
Memloc2: [????]:12h, 14h, 16h, 18h, 20h
After execution:
Memloc1: [????]:12h, 14h, 16h, 18h, 20h
Memloc2: [????]: 02h, 04h, 06h, 08h, 10h

OBSERVED RESULT:
-2: PROGRAMS INVOLVING ARITHMETIC AND LOGICAL OPERATIONS


; 2:- PROGRAM 01a

; FILE NAME: addbyte.asm

; Program is tested and found OK

; //Assembly program to add two 8-bit data\\

.model small
.stack
.data
num1 db 33h
num2 db 44h
result dw (0)

.code
mov ax, @data ;//Intialize the
mov ds, ax ; data segment\\
mov al, num1 ;get first number in al
add al, num2 ;add al(first number) with 2nd number
mov result, al ; store the sum in result loc
mov ah, 4ch ;// terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 01b

; FILE NAME: addword.asm

; Program is tested and found OK

; //Assembly program to add two 16-bit numbers\\


.model small
.stack
.data
num dw 1133h, 2244h
result dw 2 dup(0)
carry db (0)

.code
mov ax, @data ;//Intialize the
mov ds, ax ; data segment\\
mov ax, num ;get first num word in ax
clc ;CF = 0
add ax, num+2 ;add first num word with 2nd word
mov result, ax ;save the sum in result
adc carry, 00h ;save the carry if any
mov ah, 4ch ;// terminate
int 21h ; the program\\
end


OBSERVED RESULT:



; 2:- PROGRAM 01c

; FILE NAME: adddword.asm

; Program is tested and found OK

; //Assembly program to add two 32-bit (Multi-precision)
; numbers\\

.model small
.stack
.data
num1 dd 01234567h ;// two 32-bit numbers
num2 dd 89abcdefh ; to be added\\
sum dd (0)
carry db (0)

.code
mov ax, @data ;//Intialize the
mov ds, ax ; data segment\\
mov ax, word ptr num1 ;ax = LSBs of 1st num
mov bx, word ptr num2 ;bx = LSBs of 2nd num
clc
add ax, bx ;ax = ax + bx
mov bx, word ptr [num1+2] ;bx = MSBs of 1st num
mov cx, word ptr [num2+2] ;cx = MSBs of 2nd num
adc bx, cx ;bx = bx + cx + CF
mov word ptr [sum+2], bx ;// store the result
mov word ptr sum, ax ; in the memory\\
adc carry, 00h ;save carry if any
mov ah, 4ch ;// Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 02a

; FILE NAME: subbyte.asm

; Program is tested and found OK

; //Assembly program to subtract two 8-bit numbers\\

.model small
.stack
.data
num1 db 77h ;//the two numbers
num2 db 88h ; to be added\\
result db (0)
borrow db (0)

.code
mov ax, @data ;//Intialize the
mov ds, ax ; data segment\\
clc ;CF = 0
mov al, num1 ;1st num in al
sub al, num2 ;subtract 2nd num from 1st num
mov result, al ;store the result
sbb borrow,00h ;save borrow if any
mov ah, 4ch ;// terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 02b

; FILE NAME: subword.asm

; Program is tested and found OK

; //Assembly program to subtract two 16-bit numbers\\


.model small
.stack
.data
num dw 5555h, 4444h ;two words for subtraction
result dw 2 dup(0)
borrow db (0)

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
clc
mov ax, num ;minuend in ax
sub ax, num+2 ;subtract subtrahend from minuend
mov result, ax ;store the result in memory
sbb borrow, 00h ;save the borrow if any
mov ah, 4ch ;//Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 02c

; FILE NAME: subdword.asm

; Program is tested and found OK

; //Assembly program to subtract two 32-bit numbers\\


.model small
.stack
.data
num1 dd 89abcdefh ;minuend
num2 dd 01234567h ;subtrahend
result dd (0)
borrow db(0)

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov ax, word ptr num1 ;LSBs of minuend
mov bx, word ptr num2 ;LSBs of subtrahend
clc ;CF = 0
sub ax, bx ;ax = ax - bx
mov bx, word ptr num1+2 ;MSBs of minuend
mov cx, word ptr num2+2 ;MSBs of subtrahend
sbb bx, cx ;bx = bx - cx
mov word ptr result+2, bx ;// store the
mov word ptr result, ax ; result in memory locations\\
sbb borrow, 00h ;save borrow if any
mov ah, 4ch ;//Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 03a

; FILE NAME: mulsign.asm

; Program is tested and found OK

; //ASSEMBLY LEVEL PROGRAM TO MULTIPLY SIGNED HEXADECIMAL
; NUMBERS\\


.model small
.stack
.data
num db -19h, -05h ;two unsigned nos for multiplication
result db ?
.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov al, num ;get the first no
mov bl, num+1 ;get the second no
imul bl ;multiply two signed nos
mov result, al ;store the result in mem loc
mov ah, 4ch ;//Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 03b

; FILE NAME: mulusign.asm

; Program is tested and found OK

; //ASSEMBLY LEVEL PROGRAM TO MULTIPLY UNSIGNED HEXADECIMAL
; NUMBERS\\


.model small
.stack
.data
num db -19h, -05h ;two unsigned nos for multiplication
result db ?
.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
mov al, num ;get the first no
mov bl, num+1 ;get the second no
mul bl ;multiply two unsigned nos
mov result, al ;store the result in mem loc
mov ah, 4ch ;//Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 04a

; FILE NAME: divsign.asm

; Program is tested and found OK

; //ASSEMBLY LEVEL PROGRAM TO DIVIDE TWO UNSIGNED HEXADECIMAL
; NUMBERS\\


.model small
.stack
.data
dividend dw -19h ;dividend
divisor db -05h ;divisor
result db ?
.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov ax, dividend ;get the first no
mov bl, divisor ;get the second no
idiv bl ;divide 1st num by 2nd num
mov result, al ;store the result in mem loc
mov ah, 4ch ;//Terminate
int 21h ; the program\\
end



OBSERVED RESULT:
; 2:- PROGRAM 04b

; FILE NAME: divusign.asm

; Program is tested and found OK

; //ASSEMBLY LEVEL PROGRAM TO DIVIDE TWO UNSIGNED HEXADECIMAL
; NUMBERS\\


.model small
.stack
.data
dividend dw 19h ;dividend
divisor db 05h ;divisor
result db ?
.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov ax, dividend ;get the first no
mov bl, divisor ;get the second no
div bl ;divide 1st num by 2nd num
mov result, al ;store the result in mem loc
mov ah, 4ch ;//Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 05a

; FILE NAME: bcdtobin.asm

; Program is tested and found OK

; //program to convert a BCD number to BINARY number (Hex
; number)\\

.model small
.stack
.data
num db 67h
result db (0)

.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
mov al, num ;get the num to be converted
mov cl, 04 ;intialize rotation count
and al, 0fh ;mask higher number
mov bl, al ;save ax in bx
mov al, num ;restore ax
and al, 0f0h ;mask lower nibble
rcr al, cl ;rotate ax, cl times
mov dl, 0ah ;dl = 0ah
mul dl ;al * 10
add al, bl ;al = 60h + 07h, --> 43h
mov result, al ;store the result
mov ah, 4ch ;// Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 05b

; FILE NAME:- bintobcd.asm

; Program is tested and found OK

; //Assembly program to convert a BINARY (HEX) number to BCD
; number\\

.model small
.stack
.data
num dw 0abch ;number to be converted
.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov ax, num ;ax = num
mov bx, 0ah ;bx = 10h
mov cx, 00h ;cx = 00h ; clear counter
repeat: mov dx, 00h ;dx = 00h
div bx ;ax = ax/bx
push dx ;save remainder
inc cx ;increment counter
cmp ax, 00h ;test if quotient = 0
jnz repeat ;if not divide again
skip: pop dx ;get remainder
add dl, 30h ;convert to ASCII
mov ah, 06h ;display digit
int 21h
loop skip
mov ah, 4ch ;//Terminate
int 21h ; the program\\
end



OBSERVED RESULT:
; 2:- PROGRAM 06

; FILE NAME: squcube.asm

; Program is tested and found OK

; //program to find the square and cube of a given number\\


.model small
.stack
.data
num db 04h
squ db (0)
cube db (0)

.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
mov al, num ;al = 05h
mul al ;al = al * al
mov squ, al ;squ = al = 10h
mul num ;al = al(squ) * num
mov cube, al ;cube = al = 40h
mov ah, 4ch ;// Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 07

; FILE NAME: lcm.asm

; Program is tested and found OK

; Assembly level program to find the LCM of two numbers

Wrong program
.model small
.stack
.data
num1 db 05h, 03h ;// two numbers
lcm dw (0)

.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
mov ax, 00h
mov dx, 00h
mov bx, 00h
mov al, num1 ;store num1 into al
mov bl, num1+1 ;store num1+1 into bl
back: push ax
div bx ;divide ax by bx
cmp dx, 00h ;compare if remainder = 0
je exit ;if yes, ax is LCM otherwise not
pop ax ;retrieve ax
add al, num1 ;add ax with num1
mov dx, 00 ;clear dx
jmp back ;jump to back
exit: pop lcm ;get the result (LCM)
mov ah, 4ch ;// Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 08

; FILE NAME:- gcd.asm

; Program is tested and found OK

; //program to find the GCD of two 16-bit numbers\\


.model small
.stack
.data
num1 dw 15 ;two numbers
num2 dw 20
gcd dw ?

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov bx, num1 ;get num1 in ax
mov cx, num2 ;get num2 in bx
cmp bx, cx ;compare for the biggest no
jb divide ;//if cx is big then proceed
xchg bx, cx ; else exchange the nos\\
divide: mov dx, 00h
mov ax, cx
div bx ;//dividend/divisor
cmp dx, 00h ;//if rem = 0, the
je over ; divisor is the GCD\\
mov cx, bx ;//else divisor = dividend
mov bx, dx ; divisor = remainder
jmp divide
over: mov gcd, bx ;store the GCD in mem loc
mov ah, 4ch ;//Terminate
int 21h ; the main program\\
end


OBSERVED RESULT:
; 2:- PROGRAM 09

; FILE NAME:- factorl.asm

; Program is tested and found OK

; //program to find the factorial of a given number\\

.model small
.stack
.data
num dw 05h
msg db 'factorial of 0 is 1 $'
factorl dw (?)
.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov bx, num ;get the number
cmp bx, 00h ;//factorial of zero
je disp ; is one\\
call factorial ;find factorial calling subroutine
mov factorl, ax ;store factorial in mem loc
jmp exit
disp: mov ah, 09h ;//string display
lea dx, msg ; interrupt\\
int 21h
exit: mov ah, 4ch ;//Terminate
int 21h ; the program\\

; //SUBROUTINE TO FIND FACTORIAL OF A GIVEN NUMBER\\
factorial proc near ;start of the procedure
cmp bx, 01h ;//factorial of
jbe return ; one is one\\
push bx ;save bx in stack
dec bx ;decrement bx
call factorial ;call the subroutine recursively
pop bx ;get back the value for bx
mul bx ;multiply the factors of a given num
ret ;return to the main prgm
factorial endp ;end of the procedure

return: mov ax, 01h ;// return the
ret ; factorial for one\\
end
OBSERVED RESULT:
; 2:- PROGRAM 10a

; FILE NAME: aaa.asm

; Program is tested and found OK

; //Assembly program using AAA instruction after addition\\


.model small
.stack
.data
num dw 38h, 37h
result dw ?

.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
mov ax, num ;ax = 38h
mov bx, num+2 ;bx = 37h
add ax, bx ;ax = ax + bx = 6fh
aaa ;ah = 01h, al = 05h
add ax, 3030h ;convert to ascii value
mov result, ax ;ax = 3135h
mov ah, 4ch ;// terminate the
int 21h ; program\\
end

RESULT:
Input: num = 0038h, num+2 = 0037h

Output: result = 35, result+1 = 31

OBSERVED RESULT:
; 2:- PROGRAM 10b

; FILE NAME: aas.asm

; Program is tested and found OK

; //Assembly program using AAS instruction after addition\\

.model small
.stack
.data
num dw 39h, 33h
result dw ?

.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
mov ax, num ;ax = 39h
mov bx, num+2 ;bx = 33h
sub ax, bx ;ax = ax - bx = 06h
aas ;ah = 00h, al = 06h
add ax, 3030h ;convert to ascii value
mov result, ax ;ax = 3036h
mov ah, 4ch ;// terminate the
int 21h ;program\\
end

RESULT:
Input: num = 0039h, num+2 = 0033h

Output: result = 00, result+1 = 36


OBSERVED RESULT:
; 2:- PROGRAM 10c

; FILE NAME: aam.asm

; Program is tested and found OK

; //Assembly program using AAM instruction after addition\\


.model small
.stack
.data
num db 06h, 08h
result dw ?

.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
mov al, num ;al = 06h
mov bl, num+1 ;bl = 08h
mul bl ;ax = al * bl = 30h
aam ;ah = 04h, al = 08h
add ax, 3030h ;convert to ascii value
mov result, ax ;ax = 3438h
mov ah, 4ch ;// terminate the
int 21h ;program\\
end



RESULT:
Input: num = 06h, num + 1 = 08h

Output: result = 38, result+1 = 34

OBSERVED RESULT:
; 2:- PROGRAM 10d

; FILE NAME: aad.asm

; Program is tested and found OK

; //Assembly program using AAM instruction after addition\\


.model small
.stack
.data
num1 dw 0205h
num2 db 07h
result dw ?

.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
mov ax, num1 ;ax = 0205h
mov bh, num2 ;bh = 07h
aad ;ax = 19h --> 25 decimal
div bh ;ax = 0403
mov result, ax
mov ah, 4ch ;// terminate the
int 21h ;program\\
end




RESULT:
Input: num1 = 0205h, num2 = 07h

Output: result = 03, result+1 = 04

OBSERVED RESULT:
-3: PROGRAMS INVOLVING BIT MANIPULATION INSTRUCTIONS


; 3:- PROGRAM 01

; FILE NAME: posorneg.asm

; Program is tested and found OK

; //Assembly program to find the given number is positive or
; negative\\


.model small
.stack
.data
message1 db 'Number is Positive $'
message2 db 'Number is Negative $'
num db 0c0h

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov al, num ;get the number in al to be checked
and al, 80h ;retain only the MSB
jnz negnum ;if ZF = 1, the number is negative
mov ah, 09h ;//else the number is positive
mov dx, offset message1 ; and display the message
int 21h ; on console\\
jmp exit
negnum:mov ah, 09h ;//display the negative number
mov dx, offset message2 ; message
int 21h ; on console\\
exit: mov ah, 4ch ;// Terminate
int 21h ; the program\\
end

OBSERVED RESULT:
; 3:- PROGRAM 02

; FILE NAME:oddorevn.asm

; Program is tested and found OK


; //Assembly program to find the given number is odd or even\\


.model small
.stack
.data
message1 db 'Number is even $'
message2 db 'Number is odd $'
num db 40h

.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
mov al, num ;al = num
ror al,01h ;check for the LSB
jnc even ;if CF = 0 --> even else odd
number
mov dx, offset message2 ;display message for odd
jmp odd
even: mov dx, offset message1 ;display message for even
odd: mov ah, 09h
int 21h
mov ah, 4ch ;// Terminate
int 21h ; the program\\
end

OBSERVED RESULT:
; 3:- PROGRAM 03

; FILE NAME: onszro.asm

; Program is tested and found OK

; //Assembly program to find the number of ones and zeros in a
; given number\\


.model small
.stack
.data
num db 40h
cnt_one db (0)
cnt_zero db (0)

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov al, num ;al = 40h
mov cx, 08h ;cx = count (no of bits in al)
repeat: rol al, 01h ;rotate each bit right
jnc next ;if CF = 0, count as no of zeros
inc cnt_one ;else count as no of ones
jmp skip
next: inc cnt_zero ;no of zeros
skip: loop repeat ;repeat until all the bits are checked
mov ah, 4ch ;// Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 3:- PROGRAM 04

; FILE NAME: 2outof5.asm

; Program is tested and found OK

; //Assembly program to check whether a byte belongs to 2 out
; of 5 code\\

;** The code is valid if the number of ones in the least 5 bits are 2**

.model small
.stack
.data
data1 db 80h
cnt_one db (0)
message1 db 'valid 2 out of 5 code $'
message2 db 'invalid 2 out of 5 code $'

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov al, data1 ;al = data1
mov cx, 05h ;intialize the counter
back: ror al, 01h ;rotate right al bit by bit
jnc next ;if CF = 0 jump to next
inc cnt_one ;if CF = 1, count no of ones
next: loop back ;repeat to count no of ones in the 1st 5-bits
cmp cnt_one, 02h ;compare no of ones with 02h
jnz skip ;if no of ones is 2 then it is 2 out of 5
code
mov ah, 09h ;//display the message
lea dx, message1 ; as valid 2 out of 5 code\\
int 21h
jmp end1
skip: lea dx, message2 ;//if no of ones is not 2 then
mov ah, 09h ; display the message as
int 21h ; invalid 2 out of 5 code\\
end1: mov ah, 4ch ;// Terminate
int 21h ; the program\\
end

OBSERVED RESULT:
; 3:- PROGRAM 05a

; FILE NAME: bitpali.asm

; Program is tested and found OK

; //Assembly program to find whether a given byte is a bitwise
; palindrome or not\\


.model small
.stack
.data
num db 18h
msg1 db 'number is a bitwise palindrome $'
msg2 db 'number is not a bitwise palindrome $'

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov al, num ;get the number in al
mov bl, al ;save a copy in bl
mov cx, 08h ;intialze the counter to 8
back: ror al, 01h ;rotate al to right once
jnc skip ;if no carry jump to skip
rol bl, 01h ;else rotate bl left once
jc go_on ;if carry jump to go_on
jmp term ;else jump to term
skip: rol bl, 01h ;rotate bl left once
jc term ;if carrry jump to term
go_on: loop back ;else cx = cx-1 & if cx != 0, jump back
mov ah, 09h ;// display msg1
lea dx, msg1 ; if given number is
int 21h ; a bitwise palindrome\\
jmp last ;jump to last
term: mov ah, 09h ;//display msg2
lea dx, msg2 ; if given number is
int 21h ; not a bitwise palindrome\\
last: mov ah, 4ch ;// Terminate
int 21h ; the program\\
end

OBSERVED RESULT:
; 3:- PROGRAM 05b

; FILE NAME: nibpali.asm

; Program is tested and found OK

; //Assembly program to find whether a given byte/word is a
; nibble wise palindrome or not\\


.model small
.stack
.data
num db 45h
msg1 db 'number is a nibble wise palindrome $'
msg2 db 'number is not a nibble wise palindrome $'

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov al, num ;al = num
and al, 0fh ;mask the higher nibble
mov bl, al ;save al in bl
mov al, num ;again al = num
and al, 0f0h ;mask the lower nibble
mov cl, 04h ;intialize counter as 04
rol al, cl ;//compare both lower
cmp al, bl ; and higher nibbles\\
jz succ ;if both the nibbles are same jump to
succ
mov dx, offset msg2 ;//else display the number
mov ah, 09h ; is not a palindrome\\
int 21h
jmp last
succ: lea dx, msg1 ;//display the message as
mov ah, 09h ; given no is a palindrome\\
int 21h
last: mov ah, 4ch ;//terminate
int 21h ; the program\\
end

OBSERVED RESULT:
-4: PROGRAMS INVOLVING BRANCH/LOOP INSTRUCTIONS



; 4:- PROGRAM 01a

; FILE NAME: addndata.asm

; Program is tested and found OK

; //Assembly language program to add 'n' number of data in an
; array\\


.model small
.stack
.data
array db 02h, 04h, 06h, 08h, 10h, 12h, 14h, 16h, 18h, 20h
ary_cnt equ 0ah
sum dw (0)

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov cx, ary_cnt ;intialize the counter
xor di, di ;clear di register
lea bx, array ;bx = effective address of array
back: mov al, [bx+di] ;al = first element of array
mov ah, 00h ;clear higher byte of ax
add sum, ax ;//add sum and array
inc di ; elements one by one\\
loop back ;add all the elements of the array
mov ah, 4ch ;// Terminate
int 21h ; the program\\
end


OBSERVED RESULT:
; 4:- PROGRAM 01b

; FILE NAME: avgndata.asm

; Program is tested and found OK

; //Assembly language program to find average of 'n' number of
; data in an array\\


.model small
.stack
.data
array db 02h, 04h, 06h, 08h, 10h, 12h, 14h, 16h, 18h, 20h
ary_cnt equ 0ah
sum dw (0)
avg db (0)

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
mov cx, ary_cnt ;intialize the counter
xor di, di ;clear di
clc ;CF = 0
lea bx, array ;bx = effective address of array
back: mov al, [bx+di] ;al = first element of array
mov ah, 00h ;ah = 00h
adc sum, ax ;// add all the elements
inc di ; of the array
loop back ; and the result will be in sum\\
mov ax, sum ;ax = sum
mov cl, ary_cnt ;cl = no of elements in array
div cl ;al = ax/cl
mov avg, al ;avg = al
mov ah, 4ch ;//Terminate
int 21h ; the program\\
end

OBSERVED RESULT:
; 4:- PROGRAM 02a

; FILE NAME: lrgstnum.asm

; Program is tested and found OK

; //Assembly program to find the largest number in the array\\

.model small
.stack
.data
array db 10h, 06h, 04h, 08h, 12h
ary_cnt equ 05h
lrg_num db (0)

.code
mov ax, @data ;// Intialize
mov ds, ax ; the data segment\\
xor di, di ; di = 0
mov cx, ary_cnt ;cx = no of elements in the array
lea bx, array ;bx = effective address of array
mov al, lrg_num ;assume lrgst no at present is 0
back: cmp al, [bx+di] ;compare lrge no to the first element
jnc skip ;// if CF= 0, the element is smaller
mov dl, [bx+di] ; else move large no into
mov al, dl ; al using 3rd register\\
skip: inc di
loop back ;repeat for all the elements of the array
mov lrg_num, al ;store largest no in mem loc
mov ah, 4ch ;//Terminate
int 21h ; the program\\
end

OBSERVED RESULT:
; 4:- PROGRAM 02b

; FILE NAME: smlstnum.asm

; Program is tested and found OK

; //Assembly program to find the smallest number in the array\\

.model small
.stack
.data
array db 02, 07, 06, 10, 05
ary_cnt equ 05h
sml_num db (0)

.code
mov ax, @data ;//Intialize
mov ds, ax ; the data segment\\
xor di, di ; di = 0
mov cx, ary_cnt ;cx = no of elements in array
lea bx, array ;bx = effective address of array
mov al, [bx+di] ;al 1
INC AL
CMP AL, 08h ; All bits are compared
JNZ CHECK ; Go back for next scan line
SHL BH, 01h ; Move to next scan line
CMP BH, 10h
JNZ SCANLINES ; Repeat the SCAN Lines Loop (4 times)
JMP LOOPOUT

DISPLAY: ; Display the selected key
MOV AH, 9h ; Display the message line3.
MOV DX, OFFSET Message4
INT 21h

MOV AX, 0000h
MOV AL, BL
MOV BL, 02h
MUL BL
MOV BX, AX
MOV DI, OFFSET Show
MOV AL, Keys[BX]
MOV Show[0h], AL
MOV AL, Keys[BX + 1h]
MOV Show[1h], AL
MOV AH, 9h ; Display the character pressed.
MOV DX, OFFSET Show
INT 21h
MOV CX, 0FFFFh

DELAY:
MOV AX, 0FFh
DELAY1: DEC AX
JNZ DELAY1
LOOP DELAY

LOOPOUT:
MOV AH, 01h
INT 16h ; Get the Key
JZ GETKEY ; Check for the key

MOV AH, 4ch ; Exit the program safely.
INT 21h
END ; This is the end of your program.
; 07:- PROGRAM 02

; FILE NAME: pcisev.asm

; Program is tested and found OK

; //Program to demonstrate interfacing of seven segment display\\

Schematic Diagram of Seven Segment Display:
.MODEL SMALL ;Specify the model for the executable. Must for every
program.
.STACK 5000H
.DATA ;Any data declarations here.
Message1 DB 'DEMONSTRATION PROGRAM FOR SEVEN SEGMENT
DISPLAY',13,10,'$'
Message2 DB 'Check the Message < ELECTRO SYSTEMS > on Seven Segment
Display',13,10,'$'
Message3 DB 'This program is running...',13,10,'Press any key to
EXIT.',13,10,'$'

DisplayData DB
0ffh,0ffh,0ffh,0ffh,0c6h,086h,0c7h,086h,0bfh,0c0h,0deh,087h,0bfh,092h,091h,0
92h,092h,0c8h,086h,087h
CR EQU 0c003H
PA EQU 0c000H
PB EQU 0c001H
PC EQU 0c002H

.CODE ;Start your coding here.

MOV AX,@DATA ;Initialize all segemnt regesters as needed here.
MOV DS,AX

MOV AH,9h ;Display the message line1.
MOV DX, OFFSET Message1
INT 21h
MOV AH,9h ;Display the message line2.
MOV DX, OFFSET Message2
INT 21h
MOV AH,9h ;Display the message line3.
MOV DX, OFFSET Message3
INT 21h

; Send the control word

MOV AL,80h
MOV DX,CR
OUT DX,AL

GETKEY:
MOV BX,0000h

LOOP1: ; Display the charecters 4 at a tine.
MOV AL,BL
AND AL,03h
CMP AL,00H
JNZ NO_DELAY
MOV CX,0FFFFh
DELAY : MOV AX,0FFFh
DELAY1: DEC AX
JNZ DELAY1
LOOP DELAY
NO_DELAY:

MOV CL,00h
MOV CH,DisplayData[BX]
LOOP2:
MOV AH,01h
INT 16h ;Get the Key
JNZ END_PROGRAM
;MOV CL,01
MOV AH,CH
AND AH,80h
CMP AH,00h
JNZ CONTROL
MOV DX,PB
MOV AL,00h
OUT DX,AL
JMP END_CONTROL
CONTROL:
MOV DX,PB
MOV AL,01h
OUT DX,AL
END_CONTROL:

MOV DX,PC
MOV AL,01h
OUT DX,AL
MOV DX,PC
MOV AL,00h
OUT DX,AL

SHL CH,1
INC CL
CMP CL,08h

JNZ LOOP2 ;LOOP2 Repeats from here.

INC BX
CMP BX,20
JNZ LOOP1 ;LOOP1 Repeats from here.

MOV AH,01h
INT 16h ;Get the Key
JZ GETKEY

END_PROGRAM:
MOV AH,4ch ; Exit the program safely.
INT 21h
END ;This is the end of your program.
; 07:- PROGRAM 03

; FILE NAME: pcilogic.asm

; Program is tested and found OK

; //Program to demonstrate interfacing of Logical controller interface\\

Schematic diagram of a Logic Controller:
.MODEL TINY ;Specify the model for the executable. Must for every
program.

.DATA ;Any data declarations here.

;; NOTE:
;; The follwing data declerations are common for every program.
;; The values of CR, PA, PB and PC will vary from PC to PC.
;; The user need to modify the values of CR, PA, PB, PC
;; for Assembling the program
;;

CR EQU 0c003H
PA EQU 0c000H
PB EQU 0c001H
PC EQU 0c002H


Message1 DB 'DEMONSTRATION PROGRAM FOR LOGIC CONTROLLER',13,10,'$'
Message2 DB 'This program will read input in Port B. and
outputs',13,10,'$'
Message3 DB 'it's compliment in Port A.',13,10,13,10,'$'
Message4 DB 'This program is running...',13,10,'Press any key to
EXIT.',13,10,'$'
.STACK
.CODE ; Start your coding here.
MOV AX,@DATA ; Initialize all segemnt regesters as needed here.
MOV DS, AX

MOV AH, 9h ; Display the message line1.
MOV DX, OFFSET Message1
INT 21h
MOV AH, 9h ; Display the message line2.
MOV DX, OFFSET Message2
INT 21h
MOV AH, 9h ; Display the message line3.
MOV DX, OFFSET Message3
INT 21h

MOV AH, 9h ; Display the message line4.
MOV DX, OFFSET Message4
INT 21h

MOV AL, 82H ; Initialize A - Output B-Input Ports
MOV DX, CR
OUT DX, AL ; Write to Control Register.

GETKEY:
MOV DX, PB ; Get Data from Register B
IN AL, DX

NOT AL ; Compliment it.

MOV DX, PA ; Put Data to Register A
OUT DX, AL

MOV AH, 01h
INT 16h ;Get the Key
JZ GETKEY

MOV AH, 4ch ; Exit the program safely.
INT 21h
END ;This is the end of your program.
; 07:- PROGRAM 04

; FILE NAME: pcistep.asm

; Program is tested and found OK

; //Program to demonstrate interfacing of Stepper motor interface\\

Schematic Diagram of a Stepper Motor Interface:























































.MODEL TINY ;Specify the model for the executable. Must for every
program.
.STACK ;100h
.DATA ;Any data declarations here.
;; NOTE:
;; The follwing data declerations are common for every program.
;; The values of CR, PA, PB and PC will vary from PC to PC.
;; The user need to modify the values of CR, PA, PB, PC
;; for Assembling the program

CR EQU 0c403H
PA EQU 0c400H
PB EQU 0c401H
PC EQU 0c402H

Message1 DB 'DEMONSTRATION PROGRAM FOR STEPPER MOTOR',13,10,'$'
Message2 DB 'User following Keys for operating.',13,10,9,9,'C -
Clockwise.',13,10,9,9,'A - Anti-Clockwise.','$'
Message3 DB 13,10,'This program is running...',13,10,'Press ESC key
to EXIT.',13,10,'$'

Speed DW 0FFH

.CODE ;Start your coding here.

CALL CLRSCR ;Clear Screen

MOV AX,@DATA ;Initialize all segemnt regesters as needed here.
MOV DS,AX

MOV AH, 9h ; Display the message line1.
MOV DX, OFFSET Message1
INT 21h
MOV AH, 9h ; Display the message line2.
MOV DX, OFFSET Message2
INT 21h
MOV AH, 9h ; Display the message line3.
MOV DX, OFFSET Message3
INT 21h

MOV DX, CR
MOV AL, 80h
OUT DX, AL

GETKEY:
MOV BL, AL
MOV AH, 01h
INT 16h ; Get the Key ZF = 1 (No Key), ZF = 0 (Key)
MOV AL, BL
JZ COMPARE0 ; If No key pressed,
; Key was pressed, then get the key
MOV AH, 00h
INT 16h

MOV BL, AL
SUB BL, 1BH ; 27 -Esc Key
JZ EXIT_PROGRAM

COMPARE0:
CMP AL,'C' ; For Clockwise motion
JNZ COMPARE1
CALL CLOCK_WISE
JMP END_COMPARE
COMPARE1:
CMP AL,'A' ;For Anti-Clockwise motion
JNZ COMPARE2
CALL ANTI_CLOCK_WISE
JMP END_COMPARE

COMPARE2:
CMP AL,'c' ;For Anti-Clockwise motion
JNZ COMPARE3
CALL CLOCK_WISE
JMP END_COMPARE

COMPARE3:
CMP AL,'a' ;For Anti-Clockwise motion
JNZ END_COMPARE
CALL ANTI_CLOCK_WISE
JMP END_COMPARE
END_COMPARE:
JMP GETKEY ; If No valid key pressed,

EXIT_PROGRAM:
MOV AH, 4ch ; Exit the program safely.
INT 21h

; ********************************************************************* ;
; Procedures used by this program ;
; ********************************************************************* ;
CLRSCR PROC ;Clears Display

PUSH AX
MOV AH,0Fh ;Get current mode
INT 10h
MOV AH,00h ;Set to current mode
INT 10h

POP AX
RET
CLRSCR ENDP

ANTI_CLOCK_WISE PROC
PUSH AX
MOV AL, 11h
CALL OUT_A
CALL DELAY

MOV AL, 22h
CALL OUT_A
CALL DELAY

MOV AL, 44h
CALL OUT_A
CALL DELAY

MOV AL, 88h
CALL OUT_A
CALL DELAY
POP AX
RET
ANTI_CLOCK_WISE ENDP

CLOCK_WISE PROC
PUSH AX
MOV AL, 88h
CALL OUT_A
CALL DELAY

MOV AL,44h
CALL OUT_A
CALL DELAY

MOV AL,22h
CALL OUT_A
CALL DELAY

MOV AL,11h
CALL OUT_A
CALL DELAY
POP AX
RET
CLOCK_WISE ENDP


OUT_A PROC
MOV DX,PA
OUT DX,AL
RET
OUT_A ENDP


DELAY PROC
MOV CX,01FFFh
LOOP1:
MOV AX,Speed
LOOP2: DEC AX
JNZ LOOP2
LOOP LOOP1
RET
DELAY ENDP

END ;This is the end of your program.
Lihat lebih banyak...

Comentários

Copyright © 2017 DADOSPDF Inc.