Documente Academic
Documente Profesional
Documente Cultură
back:
end
;// Intialize
;data segment\\
;intialize block counter
;load the offset address of source memory location into SI
;load the offset address of destination mem location into DI
;load the element pointed by SI+4 to AL
;transfer the content of AL to mem location pointed by DI+2
;decrement SI to point to next element of the block
;decrement Destination pointer
;if counter is not zero continue the transfer
;// exit to
; DOS\\
;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:
Dept of ECE,
NMIT, Bangalore.
back:
;// intialize
;data segment\\
;intialize block counter
;load the offset address of src mem loc into SI
;load the offset address of dest mem loc into DI
;load the element pointed by SI to AL
;transfer the content of AL to mem loc pointed by
inc si
inc di
loop back
mov ah, 4ch
int 21h
DI
end
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:
Dept of ECE,
NMIT, Bangalore.
back:
;// Intialize
; the data segment\\
;intialize the counter
;effective address of mem loc1 in si
;effective address of mem loc1 in di
;transfer the contents of si into bl
;exchange the contents of di and bl
;load the contents of bl into si
;increment si
;increment di
;continue the transfer till count = 0
;// Terminate
; 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:
Dept of ECE,
NMIT, Bangalore.
;//Intialize the
; data segment\\
;get first number in al
;add al(first number) with 2nd number
; store the sum in result loc
;// terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
NMIT, Bangalore.
;//Intialize the
; data segment\\
;get first num word in ax
;CF = 0
;add first num word with 2nd word
;save the sum in result
;save the carry if any
;// terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
NMIT, Bangalore.
.code
mov ax, @data
mov ds, ax
mov ax, word ptr num1
mov bx, word ptr num2
clc
add ax, bx
mov bx, word ptr [num1+2]
mov cx, word ptr [num2+2]
adc bx, cx
mov word ptr [sum+2], bx
mov word ptr sum, ax
adc carry, 00h
mov ah, 4ch
int 21h
;//Intialize the
; data segment\\
;ax = LSBs of 1st num
;bx = LSBs of 2nd num
;ax = ax + bx
;bx = MSBs of 1st num
;cx = MSBs of 2nd num
;bx = bx + cx + CF
;// store the result
; in the memory\\
;save carry if any
;// Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
NMIT, Bangalore.
.code
mov ax, @data
mov ds, ax
clc
mov al, num1
sub al, num2
mov result, al
sbb borrow,00h
mov ah, 4ch
int 21h
;//Intialize the
; data segment\\
;CF = 0
;1st num in al
;subtract 2nd num from 1st num
;store the result
;save borrow if any
;// terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
NMIT, Bangalore.
.code
mov ax, @data
mov ds, ax
clc
mov ax, num
sub ax, num+2
mov result, ax
sbb borrow, 00h
mov ah, 4ch
int 21h
;//Intialize
; the data segment\\
;minuend in ax
;subtract subtrahend from minuend
;store the result in memory
;save the borrow if any
;//Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
NMIT, Bangalore.
;minuend
;subtrahend
.code
mov ax, @data
mov ds, ax
mov ax, word ptr num1
mov bx, word ptr num2
clc
sub ax, bx
mov bx, word ptr num1+2
mov cx, word ptr num2+2
sbb bx, cx
mov word ptr result+2, bx
mov word ptr result, ax
sbb borrow, 00h
mov ah, 4ch
int 21h
;//Intialize
; the data segment\\
;LSBs of minuend
;LSBs of subtrahend
;CF = 0
;ax = ax - bx
;MSBs of minuend
;MSBs of subtrahend
;bx = bx - cx
;// store the
; result in memory locations\\
;save borrow if any
;//Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
NMIT, Bangalore.
OBSERVED RESULT:
Dept of ECE,
10
NMIT, Bangalore.
OBSERVED RESULT:
Dept of ECE,
11
NMIT, Bangalore.
;dividend
;divisor
;//Intialize
; the data segment\\
;get the first no
;get the second no
;divide 1st num by 2nd num
;store the result in mem loc
;//Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
12
NMIT, Bangalore.
;dividend
;divisor
;//Intialize
; the data segment\\
;get the first no
;get the second no
;divide 1st num by 2nd num
;store the result in mem loc
;//Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
13
NMIT, Bangalore.
;// Intialize
; the data segment\\
;get the num to be converted
;intialize rotation count
;mask higher number
;save ax in bx
;restore ax
;mask lower nibble
;rotate ax, cl times
;dl = 0ah
;al * 10
;al = 60h + 07h, --> 43h
;store the result
;// Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
14
NMIT, Bangalore.
;number to be converted
;//Intialize
; the data segment\\
;ax = num
;bx = 10h
;cx = 00h ; clear counter
;dx = 00h
;ax = ax/bx
;save remainder
;increment counter
;test if quotient = 0
;if not divide again
;get remainder
;convert to ASCII
;display digit
;//Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
15
NMIT, Bangalore.
;// Intialize
; the data segment\\
;al = 05h
;al = al * al
;squ = al = 10h
;al = al(squ) * num
;cube = al = 40h
;// Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
16
NMIT, Bangalore.
Wrong program
.model small
.stack
.data
num1 db 05h, 03h
lcm dw (0)
.code
back:
exit:
;// Intialize
; the data segment\\
end
OBSERVED RESULT:
Dept of ECE,
17
NMIT, Bangalore.
;two numbers
.code
mov ax, @data
mov ds, ax
mov bx, num1
mov cx, num2
cmp bx, cx
jb divide
xchg bx, cx
divide: mov dx, 00h
mov ax, cx
div bx
cmp dx, 00h
je over
mov cx, bx
mov bx, dx
jmp divide
over:
mov gcd, bx
mov ah, 4ch
int 21h
end
;//Intialize
; the data segment\\
;get num1 in ax
;get num2 in bx
;compare for the biggest no
;//if cx is big then proceed
; else exchange the nos\\
;//dividend/divisor
;//if rem = 0, the
; divisor is the GCD\\
;//else divisor = dividend
; divisor = remainder
;store the GCD in mem loc
;//Terminate
; the main program\\
OBSERVED RESULT:
Dept of ECE,
18
NMIT, Bangalore.
Dept of ECE,
19
NMIT, Bangalore.
;// Intialize
; the data segment\\
;ax = 38h
;bx = 37h
;ax = ax + bx = 6fh
;ah = 01h, al = 05h
;convert to ascii value
;ax = 3135h
;// terminate the
; program\\
end
RESULT:
Input: num = 0038h, num+2 = 0037h
Output: result = 35, result+1 = 31
OBSERVED RESULT:
Dept of ECE,
20
NMIT, Bangalore.
;// Intialize
; the data segment\\
;ax = 39h
;bx = 33h
;ax = ax - bx = 06h
;ah = 00h, al = 06h
;convert to ascii value
;ax = 3036h
;// terminate the
;program\\
end
RESULT:
Input: num = 0039h, num+2 = 0033h
Output: result = 00, result+1 = 36
OBSERVED RESULT:
Dept of ECE,
21
NMIT, Bangalore.
;// Intialize
; the data segment\\
;al = 06h
;bl = 08h
;ax = al * bl = 30h
;ah = 04h, al = 08h
;convert to ascii value
;ax = 3438h
;// terminate the
;program\\
end
RESULT:
Input: num = 06h, num + 1 = 08h
Output: result = 38, result+1 = 34
OBSERVED RESULT:
Dept of ECE,
22
NMIT, Bangalore.
;// Intialize
; the data segment\\
;ax = 0205h
;bh = 07h
;ax = 19h --> 25 decimal
;ax = 0403
;// terminate the
;program\\
end
RESULT:
Input: num1 = 0205h, num2 = 07h
Output: result = 03, result+1 = 04
OBSERVED RESULT:
Dept of ECE,
23
NMIT, Bangalore.
;//Intialize
; the data segment\\
;get the number in al to be checked
;retain only the MSB
;if ZF = 1, the number is negative
;//else the number is positive
; and display the message
; on console\\
;//display the negative number
; message
; on console\\
;// Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
24
NMIT, Bangalore.
even:
odd:
;// Intialize
; the data segment\\
;al = num
;check for the LSB
;if CF = 0 --> even else odd number
;display message for odd
;display message for even
;// Terminate
;
the program\\
end
OBSERVED RESULT:
Dept of ECE,
25
NMIT, Bangalore.
;//Intialize
; the data segment\\
;al = 40h
;cx = count (no of bits in al)
;rotate each bit right
;if CF = 0, count as no of zeros
;else count as no of ones
;no of zeros
;repeat until all the bits are checked
;// Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
26
NMIT, Bangalore.
back:
next:
skip:
end1:
;//Intialize
; the data segment\\
;al = data1
;intialize the counter
;rotate right al bit by bit
;if CF = 0 jump to next
;if CF = 1, count no of ones
;repeat to count no of ones in the 1st 5-bits
;compare no of ones with 02h
;if no of ones is 2 then it is 2 out of 5 code
;//display the message
; as valid 2 out of 5 code\\
;//if no of ones is not 2 then
; display the message as
; invalid 2 out of 5 code\\
;// Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
27
NMIT, Bangalore.
;//Intialize
; the data segment\\
;get the number in al
;save a copy in bl
;intialze the counter to 8
;rotate al to right once
;if no carry jump to skip
;else rotate bl left once
;if carry jump to go_on
;else jump to term
;rotate bl left once
;if carrry jump to term
;else cx = cx-1 & if cx != 0, jump back
;// display msg1
; if given number is
;
a bitwise palindrome\\
;jump to last
;//display msg2
; if given number is
;
not a bitwise palindrome\\
;// Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
28
NMIT, Bangalore.
succ:
last:
;//Intialize
; the data segment\\
;al = num
;mask the higher nibble
;save al in bl
;again al = num
;mask the lower nibble
;intialize counter as 04
;//compare both lower
; and higher nibbles\\
;if both the nibbles are same jump to succ
;//else display the number
; is not a palindrome\\
;//display the message as
; given no is a palindrome\\
;//terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
29
NMIT, Bangalore.
back:
;//Intialize
; the data segment\\
;intialize the counter
;clear di register
;bx = effective address of array
;al = first element of array
;clear higher byte of ax
;//add sum and array
; elements one by one\\
;add all the elements of the array
;// Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
30
NMIT, Bangalore.
back:
;//Intialize
; the data segment\\
;intialize the counter
;clear di
;CF = 0
;bx = effective address of array
;al = first element of array
;ah = 00h
;// add all the elements
; of the array
; and the result will be in sum\\
;ax = sum
;cl = no of elements in array
;al = ax/cl
;avg = al
;//Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
31
NMIT, Bangalore.
back:
skip:
;// Intialize
; the data segment\\
; di = 0
;cx = no of elements in the array
;bx = effective address of array
;assume lrgst no at present is 0
;compare lrge no to the first element
;// if CF= 0, the element is smaller
; else move large no into
; al using 3rd register\\
;repeat for all the elements of the array
;store largest no in mem loc
;//Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
32
NMIT, Bangalore.
back:
skip:
;//Intialize
; the data segment\\
; di = 0
;cx = no of elements in array
;bx = effective address of array
;al <-- first element of array
;compare 1st and 2nd element of array
;//if al = small, skip
; else take the small no
; into al and then proceed
;
to check the next element\\
;store small number in mem loc
;//Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
33
NMIT, Bangalore.
;//Intialize
; the data segment\\
;no of passes
;no of checks
; si = 0
;al = 1st element
;compare 1st and 2nd element
;//if below jump to
; nxtemt otherwise
; exchange the elements\\
;proceed with next pass
;dx = dx - 1
;continue with next check
;//Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
34
NMIT, Bangalore.
;//Intialize
; the data segment\\
;no of passes
;no of checks
; si = 0
;al = 1st element
;compare 1st and 2nd element
;//if greater jump to
; nxtemt otherwise
; exchange the elements\\
;proceed with next pass
;dx = dx - 1
;continue with next check
;//Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
35
NMIT, Bangalore.
loop1:
loop2:
loop3:
;//Intialize
; the data segment\\
;cx = 2
;dx = cx
;dx = dx - 1
;si = dx
;si = si + si
;//compare the first
; and 2nd element\\
;if below leave as it is
;//else exchange the elements
;//decrement si
; two times\\
;//Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
36
NMIT, Bangalore.
loop1:
loop2:
loop3:
;//Intialize
; the data segment\\
;cx = 2
;dx = cx
;dx = dx - 1
;si = dx
;si = si + si
;//compare the first
; and 2nd element\\
;if above leave as it is
;//else exchange the elements
;//decrement si
; two times\\
;//Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
37
NMIT, Bangalore.
;//Intialize
; the data and
; extra segments\\
;intialize the counter for no of chars
;si = offset address of source string
;di = offset address of destination memory
;DF = 0; auto increment of si & di
;trnsfr the contents pointed by si to mem pointed by
;//Terminate
; the program\\
di
end
OBSERVED RESULT:
Dept of ECE,
38
NMIT, Bangalore.
;//Intialize
; the data segment\\
;Intialize the array counter
;si = pointer to beginning of string
;//di = pointer to
; end of the string\\
;compare si & di
;if di <= si, exit
;// otherwise
; exchange the contents
;
of si & di\\
;decrement di
;increment si
;jump to repeat
;// display the
; reversed string\\
;// Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
39
NMIT, Bangalore.
;//Intialize
; data and
; extra segment\\
;intialize string counter
; di = offset of string
;al = character to be searched
;compare char with first element in the string
;if found jump to found
;//else proceed with
; comparing all chars in string\\
;// if not found display
;
msg2 using DOS services\\
;//if found display
; msg1 using DOS services\\
;// store the offset
; location of the desired
;
char in a string\\
;//Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
40
NMIT, Bangalore.
back:
disp:
last:
exit:
;//Intialize
; the data
; and extra segment\\
;intialize the counter
;decrement counter
;si = offset of source string
;source offset in di also
;si point to last location
;last char in ah
;first char in al
;//if they are not
; equal go to last\\
;//if they are equal
; decrement si and increment di\\
;//compare si & di if they are equal
; display msg2\\
;else continue to compare for nxt chars
;display msg2
;display msg1
;//Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
41
NMIT, Bangalore.
; 6:- PROGRAM 01
; FILE NAME: readkb.asm
; Program is tested and found OK
; // PROGRAM TO READ A CHARACTER FROM THE KEYBOARD\\
.model small
.stack
.data
.code
mov ax, @data
mov ds, ax
mov ah, 01h
int 21h
mov ah, 4ch
int 21h
end
;//Intialize
; the data segment\\
;//DOS function to get a
; character from keyboard\\
;//Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
42
NMIT, Bangalore.
OBSERVED RESULT:
Dept of ECE,
43
NMIT, Bangalore.
;//Intialize
; the data segment\\
;//call DOS service
; to display the char 'E'
; on console\\
;//Terminate
; the program\\
OBSERVED RESULT:
Dept of ECE,
44
NMIT, Bangalore.
;//Intialize
; the data segment\\
;dx = offset address of str
;//call DOS service to
; display the string\\
;//Terminate
; the program\\
end
OBSERVED RESULT:
Dept of ECE,
45
NMIT, Bangalore.
Dept of ECE,
46
NMIT, Bangalore.
;Specify the model for the executable. Must for every program.
.DATA
; Any data declarations here.
Message1 DB 'DEMONSTRATION PROGRAM FOR KEYBOARD
INTERFACE',13,10,'$'
Message2 DB 'This program will display the key you pressed on the
Interface.',13,10,'$'
Message3 DB 'This program is running...',13,10,'Press any key to EXIT.',13,10,'$'
Message4 DB 13,'The Key You Pressed is : ','$'
Keys
DB '0 1 2 3 4 5 6 7 8 9 . + - X / % ACCECK= MCMRM M+','$'
Show
DB '01','$ '
CR EQU 0c003H
PA EQU 0c000H
PB EQU 0c001H
PC EQU 0c002H
.CODE
MOV AX,@DATA
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 AX, 92h
MOV DX, CR
OUT DX, AX
GETKEY:
MOV BH, 1h
MOV BL, 00h
SCANLINES:
MOV AL, BH
MOV DX, PC
OUT DX, AL
MOV DX, PA
IN AL, DX
Dept of ECE,
47
NMIT, Bangalore.
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
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
JZ GETKEY
Dept of ECE,
NMIT, Bangalore.
Dept of ECE,
49
NMIT, Bangalore.
Dept of ECE,
50
NMIT, Bangalore.
51
NMIT, Bangalore.
52
NMIT, Bangalore.
Dept of ECE,
53
NMIT, Bangalore.
Dept of ECE,
54
NMIT, Bangalore.
;Specify the model for the executable. Must for every program.
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
55
NMIT, Bangalore.
NOT AL
MOV DX, PA
OUT DX, AL
; Compliment it.
; Put Data to Register A
Dept of ECE,
56
NMIT, Bangalore.
Dept of ECE,
57
NMIT, Bangalore.
DW 0FFH
.CODE
CALL CLRSCR
;Clear Screen
58
NMIT, Bangalore.
; *********************************************************************
;
;
Procedures used by this program
;
; *********************************************************************
;
CLRSCR PROC
;Clears Display
PUSH AX
MOV AH,0Fh ;Get current mode
Dept of ECE,
59
NMIT, Bangalore.
60
NMIT, Bangalore.
Dept of ECE,
61
NMIT, Bangalore.