Sunteți pe pagina 1din 19

PROGRAMS

1. ADDITION OF TWO 16-BIT NUMBERS

Aim : To add two 16-bit hex numbers residing in memory and store the result in memory Apparatus : 8086 Microprocessor Kit Example : Add two numbers in locations 8100 and 8102 and store the result at 8200 Input : [1100] = 1234 [1102] = 5678 Output: Flow Chart : Aim : To add two 16-bit numbers using masm. Apparatus : PC with masm software data segment num1 dw 9112h num2 dw 9587h sum dw 2 dup(?) data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ax,num1 add ax,num2 adc bx,00 mov sum,ax int 3 code ends end start Input : num1 = 9112h num2 = 9587h output : AX = 2699h [1200] = 68AC

2. 32-BIT ADDITION Aim : Two 32-bit numbers stored as double words in a consecutive memory locations are to be added and the result stored as a double word in memory Apparatus : 8086 Microprocessor kit Input : [1100] = 12345678h [1104] = 12345678h Outout : [1200] = 2468ACFOh Flow Chart : Aim : To add two 32-bit numbers using masm. Apparatus : PC with masm software data segment n1 dd 11119999h n2 dd 22229999h sum dd 2 dup(?) data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ax,n1 add ax,n2 mov bx,ax mov ax,n1+2 adc ax,n2+2 adc dx,00 int 3 code ends end start Input : n1 = 11119999h n2 = 22229999h output : AX = 3334h BX = 3332h 3. 16 BIT SUBTRACTION Aim : To Subtract two words in memory and place the difference in a memory location. Apparatus : 8086 Microprocessor kit

Input : Minuend Subtrahend Result Flow Chart

: : : :

[1100] = 9999h [1102] = 369Ch [1200] = 62FDh

Aim : Program to implement 16-bit subtraction using masm Apparatus : PC with masm Software data segment num1 dw A876h num2 dw 5432h res dw 2 dup(?) data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ax,num1 sub ax,num2 sbb bx,00 mov res,ax int 3 code ends end start Input : num1 = A876h num2 = 5432h output : AX = 5444h

4. 32-BIT SUBTRACTION Aim : To subtract two 32-bit numbers and store the result in memory. The input data is also to be fetched from memory. Apparatus : 8086 microprocessor kit Input: Minuend : [1100] = 5678h [1102] = 123Ah Subtrahend : [1104] = 123Ah [1106] = 5678h Result : [1200] = 443Dh [1202] = BBC2h Flow Chart :

Aim : Program to implement two 32-bit subtraction using masm. Apparatus : PC with masm software data segment n1 dd 33330000h n2 dd 22221111h diff dd 2 dup(?) data ends code segment assume cs:code, ds:data start: mov ax,data mov ds,ax mov ax,n1 sub ax,n2 mov bx,ax mov ax,n1+2 sbb ax,n2+2 int 3 code ends end start Input : n1 = 33330000h n2 = 22221111h output : AX = 1111h DX = eeeeh

5. FIXED POINT MULTIPLICATION Aim : To multiply two 16-bit numbers in memory and store the result in memory. Apparatus : 8086 Microprocessor kit Example : Input : [1100] = FFDCh [1102] = BA98h Result : [1200] = B9C3h [1202] = 2AA0h Flow Chart: Aim : Multiplication of two 16-bit numbers using masm

Apparatus : PC with masm software data segment multiplicand dw 0011h multiplier dw 0011h res dw 2 dup(?) data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ax,multiplicand imul multiplier int 3 code ends end start Input : multiplicand : 0011h multiplier : 0011h output : AX = 0121h DX = 0000h 6. FIXED POINT DIVISION (32-BIT DIVISION) Aim : To perform division of a 32-bit number by a 16-bit number and store the quotient and remainder in memory Apparatus : 8086 microprocessor kit. Input : Dividend : [1100] = FFFFh Dividend : [1102] = EFFFh Divisor Result Flow Chart : Aim : Program to implement 32-bit division Apparatus : PC with masm software data segment n1 dd 0000000bh n2 dw 0002h re dw 2 dup(?) qu dw 2 dup(?) : [1104] = FFFEh : Quotient : [1200] = F001h Remainder : [1202] = E001h

data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ax,n1 mov dx,n1+2 mov cx,n2 div cx mov re,ax mov qu,dx int 3 code ends end start Input : n1 = 0000000bh n2 = 0002h Output : AX = 0005h DX = 0001h Aim : Program to implement 16-bit division (division of word by byte) Apparatus : PC with masm software data segment dividend dw 2223h divisor dw 02h res dw 2 dup(?) data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ax,dividend div divisor int 3 code ends end start Input : Dividend : 2223h Divisor : 02h Output : AX = 1111h

DX = 0001h 7. FLOATING POINT MULTIPLICATION AND DIVISION Aim : To carry out the floating point multiplication / division on two three digit numbers. Apparatus: 8086 Microprocessor kit along with 8087 co processr Convert the three digit multiplicand into short real form and store the multiplicand locations 0100, 0101, 0102, 0103. Convert the multiplier also into short real form and store it in ,locations 0104, 0105 and 0107. FINIT FLD 0100 FMUL 0104 FST 0108 HLT Input : Operand 1: 52.5 0100:00 0101:00 0102:52 0103:42 Operand 2: 35.25 0104:00 0105:00 0106:32 0107:42 Output : 0108 : 0109: 010A: 010B: Note : Floating point division is implemented in the same manner by replacing FMUL with FDIV. 8. CODE CONVERSION 16-BIT HEX TO DECIMAL Aim : To convert the number FFFF to its decimal equivalent and store the result in memory. Apparatus : 8086 Microprocessor kit Input : (AX) = FFFF Result : [1200] = 06 [1201] = 05 [1202] = 05 [1203] = 03 [1204] = 05 Flow Chart : Aim : To convert a given hexadecimal number to its equivalent decimal number Apparatus : PC with masm software data segment num dw 0100h tt dw 10000 ot dw 1000 hund dw 100 one dw 10

res db 5 dup(?) data ends code segment start mov ax,data mov ds,ax mov dx,[num] mov cx,5 lea si,tt lea di,res calc: mov ax,dx mov dx,0 div word ptr[si] or al,30h mov [di],al add si,2 add di,1 loop calc mov al,$ mov [di],al lea dx,res mov ah,9 mov ah,1 int 3 code ends end start

assume ds:data, cs:code

Output : AX = 0256

9. CALCULATING THE LENGTH OF A STRING Aim : To find the number of characters in a string Apparatus : 8086 microprocessor kit Example : The sting is assumed to start at 1200 and end of string is the value FF. Let the content of location 1300 be FF. Then the result, which is the length of the string , is checked in 1100 to be 0100. Please note that FF is not part of the string. Result : [1100] = 0100 Flow Chart : Aim : Program to find the string length using masm Apparatus : PC with masm software data segment msg db 'anand karnati$' data ends code segment assume ds:data, cs:code start:

mov ax, data mov ds, ax lea si, msg mov cx,0 mov ah,'$' label1: inc cx mov al,[si] inc si cmp al,ah jne label1 int 3 code ends end start Output : CX = 14

10. SUM OF NUMBERS IN A WORD ARRAY Aim : To obtain the sum of a 16-bit array in memory, using index register SI and store the result in memory Apparatus : 8086 microprocessor kit Example : Data in array from START = 1110 [1110] = 0FFF [1112] = 0FFF [1114] = 0FFF [1116] = 0FFF [1118] = 0FFF Result : [1200] = 4FFB Flow Chart : Aim : Program to find the sum of n numbers using masm. Apparatus : PC with masm software data segment array dw 0001h,0002h,0003h,0004h,0005h m dw 5h sum dw 2 dup(?) data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov cx,m

mov ax,0 mov si,ax start_loop: add ax,array[si] add si,2 loop start_loop mov sum,ax int 3 code ends end start Output: 000Fh 11. LARGEST OF GIVEN NUMBERS IN A WORD ARRAY Aim : To find the largest of given numbers using masm Apparatus : PC with masm software data segment array dw 1h,3h,9h,5h,7h m dw 5h data ends code segment assume ds:data,cs:code start: mov ax,data mov ds,ax dec m mov cx,m mov si,0 mov bx,array[si] add si,2 start_loop: mov dx,array[si] cmp dx,bx jbe bigg mov bx,array[si] bigg: add si,2 loop start_loop int 3 code ends end start Output: BX = 0009h

12. BCD ADDITION Aim : Program to implement BCD Addition Apparatus : PC with masm Software data segment v1 dw 0009h v2 dw 0008h total dw ? data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ax,v1 add ax,v2 daa int 3 code ends end start Output: AX = 0017 13. AVERAGE OF N NUMBERS Aim : Program to find average of n numbers Apparatus : PC with masm software data segment m dw 0005h array dw 0002h,0002h,0003h,0004h,0005h v_avg db ? data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov cx,m mov ax,0 mov dx,0 mov si,ax start_loop: add ax,array[si] add si,2 loop start_loop

div m mov v_avg,al int 3 code ends end start Output: AL = 03h 14. PROGRAM TO PRINT THE STRING Aim : Program to print the string Apparatus : PC with masm software data segment str db 'cbitcse$' data ends code segment assume ds:data,cs:code start: mov ax,data mov ds,ax mov ah,09h mov dx,offset(str) int 21h int 3 code ends end start Output: cbitcse 15. PROGRAM TO COUNT THE NUMBERS IN AN ARRAYAim : program to count the numbers in an array Apparatus : PC with masm software data segment array dw 0001h,0002h,0003h,0004h,0005h,0010h,0040h,0011h data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov dx,0011h lea si,array mov cx,0

loop1: inc cx mov ax,[si] add si,2 cmp ax,dx jnz loop1 int 3 code ends end start Output: CX = 0008h

16. SORTING OF AN ARRAY Aim : To arrange an array of unsigned words in descending order Apparatus : 8086 Microprocessor kit Example : Number of elements : 8 Unsorted array : [1100] = 00FF [1102] = 0100 [1104] = 0101 [1106] = 00FE [1108] = 00CC [110A] = CDEF [110C] = ABCD [110E] = 1234 Sorted array : [1100] = CDEF [1102] = 0100 [1104] = 1234 [1106] = 0101 [1108] = 0100 [110A] = 00FF [110C] = 00FE [110E] = 00CC

Flow Chart :

data segment array dw 2h,7h,1h,3h,6h

n dw 5h data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov cx,n dec cx loop1: mov di,cx mov bx,0 loop2: mov ax,array[bx] cmp ax,array[bx+2] jge conti xchg ax,array[bx+2] mov array[bx],ax conti: add bx,2 loop loop2 mov cx,di loop loop1 int 3 code ends end start Note : For Ascending Order jge instruction should be replaced by jle instruction. 18. WAVEFORM GENERATING PROGRAM Aim : Program for Digital to Analog conversion Apparatus : 8086 Microprocessor kit with D/A converter Module. MOVW DX #CMD55 MOVB AL #MODE OUTB DX MOVB AL #00H LOOP: MOVW DX, #PORTA OUTB DX MOVW DX, #PORTB OUTB DX INCW AX JMP LOOP OPCODE: 8000 BA E7 FF

BO 80 EE BO 00 BA 00 BA E1 FF EE BAA E3 FF EE 40 EB F5 Output: The output waveform is as shown in figure below. The amplitude and time period of the waveform are to be noted. 19. SCREEN PROCESSING Aim : Program to clear the Screen Apparatus : PC with masm software data segment rows dw 19h cols dw 50h data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov cx,rows loop1: push cx mov cx,cols loop2: mov ah,02h mov dl,' ' int 21h loop loop2 pop cx loop loop1 int 3 code ends end start Output : The Screen is cleared 20. PRINT SCREEN USIN BIOS INTERRUPTS Aim : Program to perform print screen operation

Apparatus : PC with masm software .model small .stack 64 .data cr equ 0dh lf equ 0ah prnstat dd 00500000h msgsuc db "print screen operation succesful",cr,lf,"$" norights db "'print screen operation is disabled",cr,lf,"$" msgerr db "error during print screen operation",cr,lf,"$" .code ;para1 prinscr: mov ax,@data ;[move to ds the segment address of the data mov ds,ax ; area. invoke bios interrupt 05h, to perform int 05h ; print screen operation] ; para2 push ds ;[save ds on stack top. load ds with 0050h and lds si,prnstat ; si with 0000h. get print screen status from mov al,[si] ; byte location 0050:0000 = 00500h and load it pop ds ; in al. get back segment address of data area ;para3 in ds from the stack top cmp al,0 ;[if al=0, the print screen operation is je sucmsg ; a success. in such a case go to para 6 ;para4 cmp al,01 ;[if al=0, it means print screen operation je disabled ; is disabled. in such a case go to para7] ;para5 cmp al,0ffh ;[if al = ffh, it means therer is an error in print je errmsg ;screen operation. it could be because printer is jmp exit ;offline, or printer is switched off, etc., in such ; a case go to para 8. if al value is none of ;para6 these, go to para10 to terminate the program] sucmsg : lea dx,msgsuc ;load dx with offset of sucmsg and goto prar9 jmp disp ;for display or success message on the crt ;para7 disabled: lea dx,norights ;[load dx with offset of norights and go to

jmp disp ;para 9 for display of appropriate failure ;para8 ;message on crt] errmsg: ;[load dx with offset of msgerr, for display lea dx,msgerr ; of appropriate error message on crt in para9] ;para9 disp: mov ah,09h ;[display success / appropriate failure message int 21h ;on the crt using dos function call 09h] ;para10 exit: mov ah,4ch ;[terminate the program using int 21h ;dos function call 4ch end prinscr output: Display of result on the CRT (for success case) PRINT SCREEN OPERATION SUCCESSFUL Display of result on the CRT (for print screen disabled case) PRINT SCREEN OPERATION IS DISABLED Display of result on the CRT (for error case) ERROR DURING PRINT SCREEN OPERATION 21. READING AND WRITING CONTENTS OF A FILE Aim : Program for reading and writing to a file Apparatus : PC with masm software data segment filen db "infile",0 filex db "outfile",0 buf db 2048 dup(?) data ends code segment assume ds:data, cs:code start mov ax,data mov ds,ax mov ah,3dh ; access permissions to first file mov dx, offset filen int 21h mov bx,ax mov ax,4200h ; for setting pointer-00 starting position

mov dx,0 mov cx,0 int 21h mov ah,3fh ;reading a file mov cx,2048 mov dx,offset buf int 21h mov ah,3eh ; closing a file int 21h mov ah,3dh mov dx,offset(filex) int 21h mov bx,ax mov ax,4200h mov dx,0 mov cx,0 int 21h mov ah,40h ; write a file mov dx,offset(buf) mov cx,2048 int 21h mov ah,3eh int 21h int 3 code ends end start Input : Infile This is an input file which is opened in read mode and the contents will be copied on the output file which is opened in write mode. Output: outfile This is an input file which is opened in read mode and the contents will be copied on the output file which is opened in write mode.

21. PROGRAM TO APPEND A GIVE FILE Aim : Program to append a file Apparatus : PC with masm software data segment filen db "infile",0 mesg db "this line to be appended to the existing file" data ends code segment assume ds:data, cs:code start

mov ax,data mov ds,ax mov ax,3d02h mov dx,offset(filen) int 21h mov bx,ax mov ax,4202h mov dx,0 mov cx,0 int 21h mov ah,40h mov cx,45 mov dx,offset(mesg) int 21h mov ah,3eh int 21h int 3 code ends end start Output : This is an input file which is opened in read mode and the contents will be copied on the output file which is opened in write mode. this line to be appended to the existing file

S-ar putea să vă placă și