You are on page 1of 69

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68

SYLLABUS 1. Data Transfer Instructions: Byte and Word data transfer in different addressing modes. Block Interchange Block move 2. Arithmetic and logical operations: Addition and subtraction of multi precision numbers. Multiplication and division of signed and unsigned Hexadecimal numbers ASCII Adjustment Instructions Code Conversions ( BCD to binary and vice versa) (16 bit data) Arithmetic programs to find Square, Cube, LCM, GCD and Factorial. 3. Bit Manipulation Instructions Data positive and negative Data odd or Even Logical 1s and 0s in a given data 2 out of 5 code Bit wise and Nibble wise palindrome 4. Branch/Loop Instructions: Programs on Arrays: Addition/Subtraction of N numbers, Ascending/Descending order Near and Far conditional and unconditional jumps, Calls and returns 5. String manipulations: String Transfer String reversing Searching for a character in a string Palindrome 6. Software Interrupts 7. DOS Interrupt INT 21H function calls for Reading a character from the keyboard Buffered Keyboard input Display of character/string on console Creation of a new file, Read/write from a file Read system date, Set system date Read system time, set system time 8. Interfacing Experiments: Logic Controller Seven Segment Display Stepper Motor 3X8 Keypad 9. Interfacing a printer to an 8086 microcomputer kit Largest/smallest,

Page1

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68

LIST OF EXPERIMENTS LAB 1 1.1 Develop and execute an Assembly language to transfer a given block of data (byte/word) from source memory block to destination memory block without overlap. 1.2 Develop and execute an Assembly language to transfer a given block of data (10 bytes/10 words) from source memory block at location 300H to destination memory block at 306H with overlap. 1.3 Develop and execute an Assembly language to transfer a given block of data (4 bytes/4 words) from source memory block to destination memory block in reverse order. 1.4 Develop and execute an Assembly language to exchange the data in location 1000H with the data in location 2000H. 1.5 Develop and execute an Assembly language to move the data using all addressing modes. LAB 2 2.1 Develop and execute an ALP to add two numbers (bytes/words). 2.2 Write a program to perform the multiplication of two 16 bit unsigned numbers stored in consecutive locations. 2.3 Write a program to perform the division of 32 bit unsigned number by a 16 bit unsigned number stored in consecutive memory location. 2.4 ASCII addition of 2 bytes 2.5 ASCII subtraction of 2 bytes 2.6 Develop and execute an ALP to multiply two ASCII byte numbers and display. 2.7 Program to divide 2 ASCII numbers LAB 3 2.8 Develop and Execute an ALP to add 16 bytes/words. 2.9 Multibyte addition and subtraction (more than 2 bytes) 2.10 Develop and execute an assembly language program to find the LCM of two 16 bit unsigned integers. 2.11 Write an assembly level program to find the GCD of two 16-bit unsigned integers. 2.12 Develop and execute an ALP to compute the factorial of a positive integer N using recursive procedure. The 16-bit binary result can be left in a memory word location. (Use a value for N which will ensure that N can be stored as a 16-bit unsigned integer.) 2.13 Square and cube of a number (byte/word) 2.14 Develop and execute an ALP to multiply two 32 bit numbers and display. LAB 4 2.15 Develop and Execute an ALP to convert a 16 bit binary value(Assume to be an unsigned integer) to BCD and to display it on the Display interface.(you can assume that the BCD equivalent will be less than or equal to 9999). 2.16 Develop and execute an ALP to read a 4-digit hexadecimal number from the keyboard and store the corresponding 16 bit binary value in a word location.
Page2

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68

2.17 BCD (ASCII) to binary code conversion 2.18 Displaying hexadecimal number LAB 5 3.1 Display number of 1s and 0s in a given data 3.2 2 out of 5 code (for a 2 out of 5 code, the first 3 MSBs must be zero and in the remaining 5 bits 2 bits must be 1s) 3.3 Number of even and odd numbers/ positive and negative numbers 3.4 To separate odd and even numbers/ positive and negative numbers 3.5 Program to check whether the given word is bitwise and nibble-wise palindrome. LAB 6 4.1 Develop an assembly language program to sort a given set of 16 bit unsigned integers into ascending order using insertion sort algorithm 4.2: Write an ALP to sort a given set of 8bit unsigned integers into ascending order using the bubble sort algorithm. 4.3 Develop and execute an Assembly language program that implements a binary search algorithm. Assume that the data consists of sorted 16 bit unsigned integers. The search key is also a 16-bit unsigned integer. 4.4 Largest and smallest numbers LAB 7 5.1 Write an ALP to find whether a given byte is in the string. Find out the relative address of the byte from the starting location of the string. 5.2 Reverse a string 5.3 Find whether the string is palindrome or not 5.4 Develop and execute an ALP to perform the following string operations: Reverse a string, Search a word from string, and check if the string is a palindrome or not. 5.5 Develop and Execute an ALP to transfer a given source string to destination string using string instructions 5.6 Develop and execute an Assembly Language Program that determines if a given substring is present or not in a main string of characters. The result (1: present, 0: absent) can be left in a memory location. LAB 8 6.1 Write an assembly language program with the following features. It has a macro with one parameter called LOC. The macro reads the keyboard using INT 21H (Function 06) and places the ASCII code of the key read in LOC. The macro defined above is used twice to read the keyboard and store the ASCII codes in two consecutive memory locations. 6.2: Create an Assembly language source file containing two PUBLIC Procedures called READKB and ECH. READKB reads from keyboard using INT 21H(Function 06)leaving the ASCII codes of key read in AL. procedure ECH displays the ASCII character in AL
Page3

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68

on the screen using INT 21H. Develop an Assembly level language program which uses the READKB and ECH procedure once. This is the main program which calls the READKB procedure and ECH procedure. 6.3 Write an ALP to read a character from key board using dos interrupts 6.4 Write an ALP to display the string using dos interrupts 6.5 Write an ALP to create a file and to read/write to file. 6.6 Read string of characters from keyboard and display LAB 9 7.1 Develop and execute an Assembly Language program to perform the following: Read the current time from the system (INT 21H, Function 2Ch) format it as HH:MM AM/PM and display it on the video screen (INT 21H, Function 2). 7.2 Program to read system date 7.3 Set system date 7.4 Write an alp to set the system time LAB 10 8.1 Read the status of eight input bits from the logic controller interface and display FF if it is even parity bits otherwise display 0. Also display the number of 1s in the input data. 8.2 Display messages fire and help alternately with flickering effects on a 7 segment display interface for a suitable period of time. Ensure a flashing rate that makes it easy to read both the messages. 8.3a. Stepper in clockwise direction 8.3b Stepper in anticlockwise direction 8.4 Scan the 3x8 keypad for key closure and to store the code of the key pressed in a memory location or display on the screen. also display row and column numbers of the key pressed.

Page4

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 1.1 Develop and execute an Assembly language to transfer a given block of data (byte/word) from source memory block to destination memory block without overlap.

ALGORITHM: Data memory: 1. Initialize source and destination blocks. 2. Initialize counter. Code memory: 1. Initialize data segment register 2. Initialize pointers to source and destination using blocks. 3. Interchange data between source and destination using registers. 4. Increment pointers 5. Decrement counter 6. Repeat steps 3& 4 till counter become zero. 7. Terminate the program. (i) Block movement (byte) without overlap

.model small .data org 300h x db 11h, 22h, 33h, 44h, 55h org 400h y db 5 dup(?) .code mov ax, @data mov ds, ax lea si, x lea di, y mov cx, 0005h back: mov al, [si] mov [di], al inc si inc di dec cx jnz back mov ah, 4ch int 21h end Store 5 bytes at location 300h to 304h and check the contents of memory location 400h to 404h after execution.

Page5

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 (ii) Block movement (Word) without overlap

.model small .data org 300h x dw 1111h,2222h,3333h,4444h,5555h org 400h y dw 5 dup(?) .code mov ax, @data mov ds, ax lea si, x lea di, y mov cx,0005h back: mov ax, [si] mov [di], ax inc si inc si inc di inc di dec cx jnz back mov ah, 4ch int 21h end Store 5 words at location 300h to 309h and check the contents of memeory location 400h to 409h after execution.

Page6

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 1.2 Develop and execute an Assembly language to transfer a given block of data (10 bytes/10 words) from source memory block at location 300H to destination memory block at 306H with overlap. ALGORITHM: (Transfer the data in reverse order) Data memory: 1. Initialize source and destination blocks. 2. Initialize counter. Code memory: 1. Initialize the data segment register 2. Initialize the pointers to source a destination. 3. Change the pointers to end of the block 4. Fetch the data from source block 5. Store data in destination block. 6. Decrement pointers and counters. 7 Repeat steps 4,5,6 till counter becomes zero. 8. Terminate the program Block movement (Byte) with overlap (FOR 10 BYTES) .model small .data org 300h src db 10h,20h,30h,40h,50h,60h,70h,80h,90h,0a0h org 306h dst db 10 dup(?) .code mov ax, @data mov ds, ax lea si, src lea di, dst mov cx, 10 dec cx add si, cx add di, cx inc cx back: mov al, [si] mov [di], al dec si dec di dec cx jnz back mov ah, 4ch int 21h end ; initialize data segment ; initialize src pointer ; initialize dst pointer ; initialize the count

; transfer the data with overlap ; repeat until all data bytes are transferred ; terminate the program

Store 10 bytes at location 300h to 309h. and check the contents of memory location 306h onwards after execution.

Page7

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 (ii) Block movement (Word) with overlap (FOR 10 WORDS) .model small .data org 300h src dw 1110h,2120h,3130h,4140h,5150h,6160h,7170h,8180h,9190h,0a1a0h org 306h dst dw 10 dup(?) .code mov ax, @data mov ds, ax lea si, src lea di, dst mov cx, 10 mov bx, cx dec bx add bx,bx add si, bx add di, bx ; initialize data segment ; initialize src pointer ; initialize dst pointer ; initialize the count

back: mov ax, [si] mov [di], ax ; transfer the data with overlap dec si dec si dec di dec di dec cx ; repeat until all data bytes are transferred jnz back mov ah, 4ch ; terminate the program int 21h end Store 10 bytes at location 300h to 313h. And check the contents of memeory location 305h onwards after execution.

Page8

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 1.3 Develop and execute an Assembly language to transfer a given block of data (4 bytes/4 words) from source memory block to destination memory block in reverse order. .model small .data org 1000h list dw 2357h, 0a579h, 0c322h, 0c911h count equ 04h org 2000h dstad dw 4 dup(?) .code mov ax, @data mov ds, ax lea si, list+6 mov cx, count lea di, dstad back: mov ax, [si] mov [di], ax dec si dec si inc di inc di loop back mov ah, 4ch int 21h end

Store 4 bytes/words at location 1000h to 1007h (1004h for bytes) and check the contents of memory location 2000h to 2007h (2004h for bytes) after execution.

Page9

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 1.4 Develop and execute an Assembly language to exchange the data in location 1000H with the data in location 2000H. ALGORITHM Data memory 1. Initialize source and destination block 2. Initialize counter Code memory 1. Initialize data segment register 2. Initialize pointers to source and destination block 3. Interchange data between source and destination using registers 4. Increment pointers 5. Decrement counter 6. Repeat steps 3 & 4 till counter becomes zero. 7. Terminate program .model small .data org 1000h list1 dw 2357h, 0a579h org 2000h list2 dw 0c322h, 0c911h count equ 02h .code mov ax, @data mov ds, ax lea si, list1 mov cx, count lea di, list2 back: mov ax, [si] xchg ax, [di] mov [si], ax inc si inc si inc di inc di dec cx jnz back mov ah, 4ch int 21h end

Store 2 bytes/words at location 1000h to 1003h (1001h for bytes) and store 2 bytes/words at location 2000h to 2003h (2001h for bytes) check the contents of memeory location 1000h to 1003h and 2000h to 2003h after execution.

Page 10

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 1.5 Develop and execute an Assembly language to move the data using all addressing modes. .model small .data dst dw 04h dup (?) list dw ? .code mov ax, @data mov ds, ax lea di, dst mov ax, 0004h mov [di], ax mov dx, ax mov [di+2], ax mov bx, 0004h mov [bx][di], ax mov [bx+di+02h], ax mov list, ax mov ah, 4ch int 21h end Check the result in memory locations labeled by dst and list and in ax, dx, and bx registers

Page 11

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 2.1 Develop and execute an ALP to add two numbers (bytes/words). ADDITION OF BYTES .model small .data x db 0a6h y db 63h z dw 1 dup (?) .code mov ax, @data mov ds, ax mov dl, 0 mov al, x add al, y jnc next inc dl next: lea di, z mov [di], al inc di mov [di], dl mov ah, 4ch int 21h end ADDITION OF WORDS .model small .data x dw b4a6h y dw 5463h z dw 2 dup(?) .code mov ax, @data mov ds, ax mov dx, 0 mov ax, x add ax, y jnc next inc dx next: lea di, z mov [di], ax inc di inc di mov [di], dx mov ah, 4ch int 21h end Result of addition of two numbers (bytes/words) is checked in the memory location labeled by z.

Page 12

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 2.2 Write a program to perform the multiplication of two 16 bit unsigned numbers stored in consecutive locations. data segment mcand dw 0ffffh mplier dw 00ffh product dw ?,? data ends code segment assume cs: code, ds: data start:mov ax, data mov ds, ax mov ax, mcand mul mplier mov product, ax mov product+2, dx mov ah, 4ch int 21h code ends end start. Give two16 bit numbers at memory location multiplicand and multiplier & observe the result after execution. ; first number ; second number ; result of multiplication

2.3 Write a program to perform the division of 32 bit unsigned number by a 16 bit unsigned number stored in consecutive memory location. data segment divd dw 0040h, 0000h divr dw 0002h quo dw ? rem dw ? data ends code segment assume cs: code, ds: data start:mov ax, data mov ds, ax mov ax, divd mov dx, divd+2 mov cx, divr div cx mov quo, ax mov rem, dx mov ah, 4ch int 21h code ends end start. Give 32 bit dividend and 16 bit divisor at memory location & observe the result after execution. ; (number is 00000040h)

Page 13

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 2.4 ASCII addition of 2 bytes .model small .data msg1 db press any key:,$ msg2 db 13,10,press another key:,$ res db 13,10,their sum is: sum db 2 dup(?),$ .code mov ax,@data mov ds,ax read macro num mov ah,1 int 21h mov num, al endm print macro msg mov ah, 09 lea dx, msg int 21h endm print msg1 read cl print msg2 read bl xor ah, ah add cl, bl mov al, cl aaa add ax, 3030h mov sum, ah mov sum+1, al print res mov ah, 4ch int 21h end

2.5 ASCII subtraction of 2 bytes .model small .data msg1 db press any key:,$ msg2 db 13,10,press another key:,$ res db 13,10,their difference is: diff db 2 dup(?),$ .code mov ax,@data mov ds,ax read macro num

Page 14

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 mov ah,1 int 21h mov num, al endm print macro msg mov ah, 09 lea dx, msg int 21h endm print msg1 read cl print msg2 read bl xor ah, ah sub cl, bl mov al, cl aas add ax, 3030h mov diff, ah mov diff+1, al print res mov ah, 4ch int 21h end

2.6 Develop and execute an ALP to multiply two ASCII byte numbers and display. PROGRAM TO MULTIPLY 2 ASCII NUMBERS .model small .data msg1 db enter first number:,$ msg2 db 13,10,enter second number:,$ res db 13,10,their product is: prod db 2 dup(?),$ .code mov ax,@data mov ds,ax read macro num mov ah,1 int 21h mov num, al endm print macro msg mov ah, 09 lea dx, msg int 21h endm print msg1

Page 15

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 read al sub al, 30h print msg2 read bl sub bl, 30h mul bl aam add ax, 3030h mov prod, ah mov prod+1, al print res mov ah, 4ch int 21h end

The result is displayed on the screen.

2.7 Program to divide 2 ASCII numbers .model small .data msg1 db enter upper digit of dividend:,$ msg2 db 13, 10 enter lower digit of dividend:,$ msg3 db 13, 10 enter the divisor:,$ res1 db 13, 10 the quotient is: quotient db 2 dup(?),$ res2 db 13, 10 the remainder is: remndr db 2 dup(?),$ .code mov ax, @data mov ds, ax read macro num mov ah,1 int 21h mov num, al endm print macro msg mov ah, 09 lea dx, msg int 21h endm print msg1 read ch sub ch, 30h print msg2 read cl

Page 16

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 sub cl, 30h print msg3 read bl sub bl, 30h mov ax, cx aad div bl mov ch, ah aam add ax, 3030h mov quotient, ah mov quotient+1, al print res1 mov al, ch aam add ax, 3030h mov remndr, ah mov remndr+1, al print res2 mov ah, 4ch int 21h end 2.8 Develop and Execute an ALP to add 16 bytes/words. 16 Bytes .model small .data numlist db 16 dup(35h) count equ 16 result dw ? .code mov ax,@data mov ds,ax lea si,numlist mov cx,count mov ax,00h mov bx, 0h back: mov bl,[si] add ax,bx inc si dec cx jnz back lea di,result mov [di],ax mov ah,4ch int 21h end

Page 17

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68

16 Words .model small .data numlist dw 16 dup(3535h) count equ 16 result dw 02 dup (?) .code mov ax,@data mov ds,ax lea si,numlist mov cx,count mov ax,00h mov dx,0h back: mov bx,[si] add ax,bx jnc next inc dx next:inc si inc si dec cx jnz back lea di,result mov [di],ax inc di inc di mov [di],dx mov ah,4ch int 21h end

The result of the addition is stored in the memory location pointed by the label result.

2.9 Multibyte addition and subtraction .model small .data n1 db 23h, 57h, 0a5h, 79h, 0c3h, 22h, 0c9h, 11h n2 db 12h, 37h, 0c5h, 0deh, 0a3h, 9ah, 29h, 14h sum db 8 dup (?) diff db 8 dup (?) .code mov ax,@data mov ds, ax mov cx, 8 mov bx, 7

Page 18

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 mov dx, 0 clc addagn:mov al, n1[bx] adc al, n2[bx] mov sum[bx], al dec bx loop addagn jnc next inc dx next: mov cx, 8 mov bx, 7 clc subagn:mov al, n1[bx] sbb al, n2[bx] mov diff[bx], al dec bx loop subagn mov ah, 4ch int 21h end

Result of addition of two multibyte numbers is stored in the memory location labeled by sum and result of subtraction of two multibyte numbers is stored in the memory location labeled by diff.

2.10 Develop and execute an assembly language program to find the LCM of two 16 bit unsigned integers. Explanation: The LCM of two numbers is found by dividing the first number by the second number. If there is no remainder, then the first number is the LCM. If there is a remainder, the first number is added to itself to get a new number. Again divide the new number by the second number. If there is no remainder, then the new number is the LCM. If there is the remainder, the new number is added to the first number and once again this number becomes the new number. The process is continued till there is no remainder Example: First No=25 second No=15 Iteration Operation 1 25 % 15 10 2 50 % 15 5 3 75 % 15 0 Therefore LCM is 75. ALGORITHM 1. 2. 3. 4. 5. 6. 7. 8. 9. Initialize word data in the data memory locations. Fetch the 16-bit data into AX and BX from address location N and N +2. Initialize DX to 0000H. Save both AX and DX on top of the stack. Divide the A--DX by contents of BX. Is the remainder Zero? Yes go to step 10. No, restore the data from top of the stack. Add the contents of N to AX_DX and go to step4. Reminder New Number 25+25=50 50+25=75

Page 19

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 10. The result is popped from the top of the stack (First Higher order 16-bits and these lower order 16bits are popped). 11. Terminate the program. .model small ;both code & data segment <=64k each. .stack ;stack initialized .data n dw 000fh,0005h ;initialize data memory locations for the ;operands lcm dw 2 dup(?) ;the calculated result is stored in lcm. .code ;the code part of the program starts here mov ax,@data mov ds,ax mov dx,0 ;initialize data segment

;clear dx register

mov ax,n ;load the first number mov bx,n+2 ;load the second number back:push ax ;save the both numbers on top of the stack push dx div bx ;divide first number by the second number cmp dx,0 ;is there is a number ? je exit pop dx pop ax add ax,n jnc next ;no, terminate the program ;yes, pop the data stored

;add the first number to the contents of ax ;if the result is greater then 16-bits ;increment dx inc dx ;register next:jmp back ;repeat till the remainder is zero exit:pop lcm+2 ;pop the lcm value from the top of stack pop lcm mov ah,4ch ;terminate the program int 21h end 000F is stored in the memory location pointed by lcm.

Page 20

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 2.11 Write an assembly level program to find the GCD of two 16-bit unsigned integers. Explanation: GCD of two numbers are performed by dividing the greater number by smaller number till the remainder is zero. If it is zero, the divisor is the GCD. If not the remainder and the devisor of the previous division are the new set of two numbers. The process is repeated by dividing greater of the two numbers by the smaller number till the remainder is zero. Example : First No.=90 second No.=120 Iteration Operation 1 120 % 90 2 90 % 30 Hence the GCD is 30. Remainder 30 0

ALGORITHM 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. Initialize the data memory with data and the data segment register with appropriate address. Load AX and BX registers with the operands (N1 and N2). Are the two numbers N1 and N2 equal? If yes, go to step 10. Is N1 greater than N2? if yes, go to step 6. Exchange AX and BX register contents such that AX contains the bigger number. Initialize DX register with 00H. Perform divide operation (Contents of AX/contents BX). If there is no remainder go to step 10. Move the remainder into AX register and go to step 4. Save the contents of BX as GCD. Terminate the program normally. ;both code & data segment <=64k each ;stack initialized

.model small .stack .data

n1 dw 000fh ;initializing n1 with 000fh n2 dw 0005h ;initializing n2 as a data word & giving it the ;value 0005h gcd dw ? ;the result will be stored in gcd .code mov ax, @data ;initialize the data segment mov ds, ax ;initialize the ds register mov ax, n1 ;n1 is initialized mov bx, n2 ;n2 is initialized back:cmp ax, bx ;are they equal? je exit ;if yes, save the gcd jb intrg ;if no, is ax<bx? if yes, interchange the ;numbers

divn:mov dx, 0 div bx ;check whether ax is divisible by bx cmp dx, 0 je exit ;if yes, save gcd mov ax, dx ;move the remainder as n1 data jmp back ;repeat the procedure intrg:xchg ax, bx ;load the higher number is ax and

Page 21

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 jmp divn exit:mov gcd, bx mov ah, 4ch int 21h end ;lower number in dx and continue ;save the gcd number ;terminate the program

0005 is stored in the memory location pointed by gcd.

2.12 Develop and execute an ALP to compute the factorial of a positive integer N using recursive procedure. The 16-bit binary result can be left in a memory word location. (Use a value for N which will ensure that N can be stored as a 16-bit unsigned integer.)

.model small .stack .data num dw 5 result dw ? .code mov ax,@data mov ds,ax

; initialize the ds register

mov ax,01 ;initialize the result as 01 if the number is 0 mov cx,num ;initialize the number cmp cx,0 ;check whether number is 0 je exit ;if yes, go to terminate the program mov bx,cx ;save the number in bx call fact ;call the factorial function exit:mov result,ax ;save the factorial in result mov ah,4ch ;terminate the program int 21h fact proc near ;function for factorial cmp bx,01 ;is bx content=01? jz st01 ;if yes, go to initialize ax push bx ;if no, save intermediate value on stack dec bx ;reduce bx value call fact pop bx ;pop the value stored and mul bx ;multiply with ax register ret ;return to the called program st01:mov ax,01 ;initialize ax register 01 ret ;return to the called program fact endp ;end of the factorial function end

Result: 78, 00

; The factorial of 5 is 0078H

The factorial of 05h (0078h) is stored in the memory location pointed by the label result.

Page 22

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 2.13 Square and cube of a number (byte/word) .model small .data num dw 0111h sq dw 2 dup (?) cube dw 3 dup (?) .code mov ax, @data mov ds, ax mov ax, num mul num mov sq+2, ax mov sq, dx mov si, dx mov bx, num mul bx mov cube+4, ax mov cube+2, dx mov ax, si mul bx add cube+2, ax adc cube, dx mov ah, 4ch int 21h end ; (these two lines can be replaced with .exit)

; (these two lines can be replaced with .startup)

Page 23

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 2.14 Develop and execute an ALP to multiply two 32 bit numbers and display. .model small .stack .data mr dw 0004h,0003h md dw 0002h,0001h result dw 5 dup (0) .code disp macro local skip cmp al,0ah jb skip add al,07h skip: add al,30h mov ah,02h mov dl,al int 21h endm mov ax,@data mov ds,ax mov ax,mr mul md mov result,ax mov result+2,dx mov ax,mr mul md+2 add result+2,ax adc result+4,dx adc result+6,00h mov ax,mr+2 mul md add result+2,ax adc result+4,dx adc result+6,00h mov ax,mr+2 mul md+2 add result+4,ax adc result+6,dx adc result+8,00h ; to display lea si,result add si,09h mov bx,0ah

Page 24

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 back:mov al,[si] and al,f0h mov cl,04h ror al,cl disp mov al,[si] and al,0fh disp dec si dec bx jnz back mov ah,4ch int 21h end The result is stored in the memory location pointed by the label result. (000000000003000a0008)

2.15 Develop and Execute an ALP to convert a 16 bit binary value(Assume to be an unsigned integer) to BCD and to display it on the Display interface.(you can assume that the BCD equivalent will be less than or equal to 9999). .model small .stack .code mov ax,@data mov ds,ax mov ax, 04A3h call dispx mov ah, 4ch int 21h dispx proc near mov cx, 0 mov bx, 10 dispx1: mov dx, 0 div bx push dx inc cx or ax, ax jnz dispx1 dispx2: pop dx mov ah, 6 add dl, 30h int 21h loop dispx2 ret dispx endp end Binary number 04A3 is converted to decimal number and is displayed on the screen.

Page 25

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 2.16 Develop and execute an ALP to read a 4-digit hexadecimal number from the keyboard and store the corresponding 16 bit binary value in a word location. .model small .stack .data temp dw ? .code mov ax,@data mov ds,ax call readh mov temp, ax mov ah,4ch int 21h readh proc near mov cx, 4 mov si. cx mov bx, 0 readh1: mov ah, 1 int 21h call conv shl bx, cl add bl, al dec si jnz eadh1 mov ax, bx ret readh endp conv proc near cmp al,9 jbe conv2 cmp al, a jb conv1 sub al, 20h conv1: sub al, 7 conv2: sub al, 30h ret conv endp end ; the resulted binary equivalent value to be stored ;initialize ds

If the typed hexadecimal number from the keyboard is a, b, c and d, the data is stored as CD, AB

Page 26

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 2.17 BCD (ASCII) to binary code conversion .model small .data temp dw ? .code mov ax, @ data mov ds, ax call readn mov temp, ax mov ah, 4ch int 21h readn proc near mov cx, 10 mov bx, 0 readn1: mov ah, 1 int 21h cmp al, 0 jb readn2 cmp al. 9 ja readn2 sub al, 0 push ax mov ax, bx mul cx mov bx, ax pop ax mov ah, 0 add bx, ax jmp readn1 readn2: mov ax, bx ret readn endp end

Page 27

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 2.18 Displaying hexadecimal number .model small .code .startup mov ax, 0abch call disph .exit disph proc near mov cl, 4 ; load rotate count mov ch, 4 ; load digit count h1: rol ax, cl ; position the digit push ax and al, 0fh add al, 30h ; convert to ascii cmp al, 9 jbe h2 add al, 7 h2: mov ah, 2 mov al, al int 21h pop ax dec ch jnz h1 ret disph endp end ; display hex digit

Page 28

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 3.1 Display number of 1s and 0s in a given data .model small .data x dw 0088h zero dw 01h dup (00) one dw 01h dup (00) .code mov ax, @data mov ds, ax mov ax, x mov cx, 16 back: shr ax, 01h jnc next inc one jmp fw next: inc zero fw: dec cx jnz back mov ah, 4ch int 21h end Number of 1s is stored in memory location pointed by the label one and number of 0s is stored in memory location pointed by the label zero 3.2 2 out of 5 code (for a 2 out of 5 code, the first 3 msbs must be zero and in the remaining 5 bits 2 bits must be 1s) .model small .stack .data dat db 03h msg1 db valid code,$ msg2 db invalid code,$ one_c db 0 .code mov ax, @data mov ds, ax mov cx, 05 mov al, dat and al, 0e0h cmp al, 00h jnz fail mov al, dat back: ror al, 01

Page 29

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 jnc next inc one_c next: loop back cmp one_c, 02 jnz fail lea dx, msg1 jmp disp fail: lea dx, msg2 disp: mov ah, 09h int 21h mov ah, 4ch int 21h end For the given data in the memory location labeled by dat, check the message displayed on the screen.

3.3 Number of even and odd numbers/ positive and negative numbers .model small .data count equ 05h list dw 2357h, 0a579h, 0c322h, 0c911h, 0c000h .code mov ax, @data mov ds, ax lea si, list mov cl, count mov bx, 0 mov dx, 0 back: mov ax, [si] ror ax, 01 jc odd inc bx jmp next odd: inc dx next: add si, 02 dec cl jnz back mov ah, 4ch int 21h end 3.4 To separate odd and even numbers/ positive and negative numbers .model small .data count equ 05h list dw 2357h, 0a579h, 0c322h, 0c911h, 0c000h ae dw 5 dup (?) ao dw 5 dup (?)

; (shl ax, 01 for +ve (no carry)& -ve (carry) numbers)

Page 30

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68

.code mov ax, @data mov ds, ax lea si, list mov cl, count lea di, ae lea bp, ao back: mov ax, [si] ror ax, 01 jc odd mov ax, [si] mov [di], ax jmp next odd: mov ax, [si] mov ds:[bp], ax next: add si, 02 inc di inc di inc bp inc bp dec cl jnz back mov ah, 4ch int 21h end Odd and even numbers/ positive and negative numbers are separated and store in the memory locations. ;(shl ax, 01 for +ve (no carry) & -ve (carry) numbers)

3.5 Program to check whether the given word is bitwise and nibblewise palindrome. .model small .data msg1 db nibblewise pal,$ msg2 db not nibblewise pal,$ msg3 db bitwise pal,$ msg4 db not bitwise pal,$ num dw 9889h .code .startup mov ax, num mov cl, 4 ror ah, cl cmp ah,al jnz notnib lea dx, msg1 jmp cont

Page 31

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 notnib: lea dx, msg2 cont: mov ah, 09h int 21h mov ax, num xor bx, bx mov cx, 8 back: rcr al, 1 jnc next inc bl next: rcl ah, 1 jnc next1 inc bh next1: cmp bl, bh jnz not bit loop back lea dx, msg3 jmp cont1 notbit: lea dx, msg4 cont1: mov ah, 09h int 21h .exit end

Page 32

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 4.1 Develop an assembly language program to sort a given set of 16 bit unsigned integers into ascending order using insertion sort algorithm Explanation: We arrange the given set of numbers 7800,4800,9200,2311 in ascending order using insertion sort. We treat the first term 7800 as sorted. Now we insert the second term 4800 in the correct position, so that two elements are sorted. The sorted elements are 4800, 7800. Now we insert the third element 9200 in the corresponding position, so that three elements are sorted. The three-sorted elements are 4800, 7800, 9200. Finally, we insert the last term 2311, 4800, 7800, and 9200. Algorithm 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Initialize data in the data memory location. Initialize to calculate the number of integers in location size 1. Initialize DS register with data memory. Initialize SI register with the count 2(to sort first two integers) Check whether all the numbers up to the count indicated by CX register is sorted No, sort them by comparing and inserting it in the right position. Yes, include the next number and increment the count in CX register. Have all the numbers include and sorted? No, go to step 5. Yes, terminate the program.

.model small .stack .data a dw 0004h, 0003h, 0001h, 0002h l dw ($-a)/2 .code mov ax,@data ; initialize the ax register mov ds,ax ;initialize ax value to ds register mov cx,02h ;initialize 2 to cx register ol:mov dx, cx dec dx mov si, dx add si, si mov ax, a[si] inl:cmp a[si-2], ax jbe next mov di, a[si-2] mov a[si], di dec si dec si dec dx jnz inl next:mov a[si], ax inc cx cmp cx, l jbe ol mov ah,4ch int 21h end ;yes, terminate the program

16 bit unsigned integers are sorted into ascending order using insertion sort algorithm

Page 33

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 4.2: Write an ALP to sort a given set of 8bit unsigned integers into ascending order using the bubble sort algorithm. Explanation: We arrange the given set of numbers 78,34,12,56 in ascending order using bubble sort. We compare the first two elements i.e., 78 and 34. 34 is less than 78 and hence they are changed. Next, we compare 2nd and 3rd element i.e., 78 and 12. Because they are not in order, the elements are exchanged. Now the elements of the vector appear as 34, 12, 78, 56. Next we compare 3rd and the last element, i.e., 78 and 56. Because they are not in order, they are interchanged. Thus the largest element of the unsorted vector is placed in the correct position. Now the elements of the vector are 34, 12, 56, and 78. This completes the first pass. We compare the first two elements, i.e., 34 and 12 of 34, 12,56 and 78. Because 12 is less than 34, the two are not in proper order. Hence they are exchanged. Next we compare 2nd and last element, i.e., 34 and 6. They are in proper. Now the elements of the vectors are 12,34,56,78. This completes the second pass. Now, we compare the only two elements, i.e., 12 and 34, which forms the unsorted portion. Because 12 is less than 34, the two elements are in order and so, they are not exchanged. Thus the larger of the two elements of the unsorted vector is placed now in the correct position. Now, the elements of the vectors appear as 12, 34, 56 and 78. This completes the third pass.

Algorithm 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. Initialize the data in the memory. Initialize the size of data. Initialize the DS register. Initialize BX with L. Copy the contents of BX to CX register. Load the first element into AL and use a pointing to the next element Compare this element with the next element. If AL is greater exchange the two elements in memory. Increment the points and decrement CX register. Has all the element compared in the array (i.e., Is CX=0?) No, go to step 6. Yes, decrement BX, if BX content is not zero go to step 5. If BX is zero terminate the program.

.model small .stack .data a db 0dh,0ch,0ah,0bh,0eh l dw $-a ;calculate the size of numbers .code mov ax,@data ;initialize the data segment mov ds,ax mov bx,l ;the number of data byte is initialized in bx ;register dec bx ;load bx with (n-1) nxtpass:mov cx,bx ;save the count in cx register mov si,0 ;initialize the pointer nxtcomp:mov al,a[si] ;load the data in to al pointed by si inc si ;increment the point cmp al,a[si] ;is the content of al less than that of si ;pointed data? jb next ;yes, go to next xchg al,a[si] ;no, exchange two data in memory

Page 34

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 mov a[si-1],al ;repeat till the end of the memory next:loop nxtcomp ;has all the comparison over in this pass? ;no, go to nxtcomp to continue dec bx ;has all the passes completed? jnz nxtpass ;no, go to nxtpass mov ah,4ch ;terminate the program int 21h end Result: 0A, 0B, 0C, 0D, 0E

8 bit unsigned integers are sorted into ascending order using bubble sort algorithm

4.3 Develop and execute an Assembly language program that implements a binary search algorithm. Assume that the data consists of sorted 16 bit unsigned integers. The search key is also a 16-bit unsigned integer. .model small .stack .data msg1 db 'search fails $' msg2 db 'search successful position is:' result db ?,$ array dw 00ffh,01feh,23fdh,45fch,0abfbh,0bbfah,0cdf0h,0eeeeh length dw ($-array)/2 key dw 0eeeeh .code mov ax,@data ;initialize the data segment mov ds,ax mov bx, 1 mov dx, length mov cx, key again:cmp bx, dx ja fail mov ax, bx add ax, dx shr ax, 1 mov si, ax dec si add si, si cmp cx, array [si] jae big dec ax mov dx, ax jmp again big: je success inc ax mov bx, ax jmp again success: mov result, al add result, 30h lea dx, msg2 jmp display

Page 35

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 fail: lea dx, msg1 display: mov ah, 9 int 21h exit: mov ah, 4ch int 21h end ; terminate the program normally

search successful position is:7 is the message displayed on the screen.

4.4 To find the largest and smallest numbers in a given series. .model small .data count equ 05h largest db 01h dup(?) list db 52h, 23h, 26h, 45h, 15h .code mov ax, @data mov ds, ax lea si, list mov cl, count mov al, [si] dec cl again:cmp al, [si+1] jnc next ;(jc next for smallest number) mov al, [si+1] next: inc si dec cl jnz again lea di, largest mov [di], al mov ah, 4ch int 21h end The largest or the smallest number is stored in the memory location.

Page 36

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 5.1 Wap to find whether a given byte is in the string. Find out the relative address of the byte from the starting location of the string. .model small .data count equ 05h byte1 equ 57h string db 23h, 57h, 0a5h, 79h, 0c3h relad dw 01h dup (?) .code mov ax, @data mov ds, ax mov es, ax lea di, string mov cx, count mov bx, di mov al, byte1 cld repne scasb jnz x1 dec di mov ax, di sub ax, bx mov relad, ax jmp x2 x1:mov relad, offh x2: mov ah, 4ch int 21h end 5.2 Reverse a string .model small .stack .data count equ 05h x db aruna,$ res db 5 dup (?),$ .code mov ax, @data mov ds, ax mov es, ax lea si, x lea di, res mov cx, count add di, cx dec di back: cld lodsb std

Page 37

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 stosb loop back mov ah, 09h lea dxc, res int 21h mov ah, 4ch int 21h end

5.3 Find whether the string is palindrome or not .model small .stack .data count equ 05h x db aruna,$ msg1 db pal,$ msg2 db not pal,$ .code mov ax, @data mov ds, ax lea si, x lea di, x+4 mov cx, count back: mov al, [si] mov bl, [di] cmp al, bl jnz fail inc si dec di dec cx jnz back lea dx, msg1 jmp disp fail: lea dx, msg2 disp: mov ah, 09h int 21h mov ah, 4ch int 21h end

Page 38

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 5.4 Develop and execute an ALP to perform the following string operations: Reverse a string, Search a word from string, check if the string is a palindrome or not. .model small .data cr equ 13 if equ 10 src db ghoshal,$ len equ ($-src)-1 dst db len dup (?),cr,if,$ s key db n,$ fail msg db s key failure,cr,if,$ succ msg db s key success,cr,if,$ palin db palindrome,cr,if,$ no palin db not a palindrome,cr,if,$ .code mov ax,@data mov ds,ax mov es,ax lea si,src lea di,dst mov cx,len add di,cx dec di ; program to reverse a string back: cld lodsb std stosb loop back ; program for palindrome lea si,src lea di,dst cld mov cx,len repe cmpsb jnz fail lea dx,palin jmp disp fail: lea dx,nopalin disp: mov ah,09h int 21h ; program to search for a key lea di,src cld mov al,[s_key] mov cx,len repne scasb jnz next lea dx,succ msg jmp skip next: lea dx,fail msg

Page 39

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 skip: mov ah,09h int 21h mov ah,09h lea dx,dst int 21h mov ah,4ch int 21h end

5.5 Develop and Execute an ALP to transfer a given source string to destination string using string instructions .model small .stack .data x db aruna,$ y db 5 dup(?),$ .code mov ax,@data mov ds,ax mov es,ax lea si,x lea di,y mov cx,0005h cld rep movsb mov ah,09h lea dx,y int 21h mov ah,4ch int 21h end source string (x) = aruna destination string (y) = aruna

Page 40

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 5.6 Develop and execute an Assembly Language Program that determines if a given sub-string is present or not in a main string of characters. The result (1:present,0:absent) can be left in a memory location. .model small .stack .data str db 'love is god',$ ;initialize the main string coun1 dw $-str ;determine the length of the main string sub_st db 'is',$ count2 dw $-sub_st ;initialize the sub string ;determine the length of the sub string

result db ? ;allocate the one byte for the result .code mov ax,@data ;initialize ds and es with data memory area mov ds,ax mov es,ax mov cx,coun1 ;initialize cx register with the length ;of main string lea si, sub_st ;initialize si register with the starting ;address of main string lea di, str ;initialize si register with the starting ;address of main string cld ;clear direction flag mov al,[si] next:repnz scasb ;compare the first character of sub-string ;with main string till they match inc si ;point si to the next character of the ;sub-string mov dx,cx ;check whether the length of the sub-string is ;greater than the remaining length of ;sub-string sub cx,count2 jb stop ;if yes, stop as sub-string is not ;available in main string mov cx,count2 ;if no, check whether the sub-string dec cx ;matches with the remaining part of the ;main string repnz cmpsb ;if no, go and search if the sub-string ;is present jnz not_found mov result,01h end_all:mov ah,4ch ;terminate the program int 21h stop:mov result,00h jmp end_all not_found:mov cl,dl ;once again start loading in length of the ;sub-string in cl lea si, sub_st ;initialize the starting address of sub-string jmp next end Result: 0001 ;When sub-string is changed to IT the result is 0000

Page 41

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 6.1 Write an assembly language program with the following features. It has a macro with one parameter called LOC. The macro reads the keyboard using INT 21H(Function 06) and places the ASCII code of the key read in LOC. The macro defined above is used twice to read the keyboard and store the ASCII codes in two consecutive memory locations.

rdkbd macro loc ;initialize the macro local back ;directive in macro to generate unique label back:mov ah,06h ;call dos interrupt function 06 mov dl,0ffh int 21h jz back mov loc,al endm

;yes, wait till a key is pressed ;no, save the read key code in memory ;terminate the data memory area

.model small .stack .data mem db 2 dup(?) ;initialize data memory area .code mov ax,@data ;initialize the data segment register mov ds,ax rdkbd mem ;invoke macro rekb with the memory address as ;parameter rdkbd mem+1 ;invoke macro rekb with the memory address as ;parameter mov ah,4ch ;terminate the program int 21h end Result: 31, 32 ;It is assumed that keys 1 and 2 are pressed

Page 42

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 6.2: Create an Assembly language source file containing two PUBLIC Procedures called READKB and ECHO. READKB reads from keyboard using INT 21H(Function 06)leaving the ASCII codes of key read in AL. procedure ECHO displays the ASCII character in AL on the screen using INT 21H. Develop an Assembly level language program which uses the READKB and ECHO procedure once. This is the main program which calls the READKB procedure and ECHO procedure. Here there are three programs. Assembling and linking in the following manner can execute this program. 1. Assemble all the three programs separately. 2. Link the three programs together by using the command. Link<file1.obj>+<file2.obj>+<file3.obj> 3. An .EXE file is generated by the first file name file1.exe. (This is the first program called <file1.asm>) .model small .stack .code extrn readkb:far ;these two procedures are not available in this ;file extrn echo:far mov cx,10 ;initialize the number of data character ;required. back:call readkb ;call the procedure to read the characters call echo ;call the procedure to display the character loop back ;call the above procedure 10 times mov ah,4ch ;terminate the program normally int 21h end

Program to display (echo) on the screen using int 21h(function 06h). (this is the second program called <file2.asm>) .model small .stack .code public echo ;echo is available externally to all programs echo proc ;name of the procedure mov dl,al mov ah,06h ;function to display a character on crt screen int 21h ret ;return to the calling program echo endp end Program to read the data from keyboard using int 21h(function 06). (this is the third program called <file3.asm>) .model small .stack .code public readkb ;this procedure is made public readkb proc far mov ah,06h ;call interrupt to read the key pressed mov dl,0ffh int 21h jz readkb ;no, go to check again

Page 43

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 ret ;yes, return the main program readkb endp ;return the called program end

6.3 Write an alp to read a charater from key board using dos interrupts data segment msg db key board input with traditional call <type any key>:$ data ends code segment assume cs: code, ds: data mov ax, data mov ds, ax mov ah, 09h mov dx, offset msg int 21h mov ah, 01h int 21h mov ah, 4ch int 21h code ends note: after execution press any key on the keyboard and observe the pressed key on the display. 6.4 Write an alp to display the string using dos interrupts data segment msg db hello world ,$ data ends code segment assume cs: code, ds: data mov ax, data mov ds, ax mov ah, 09h mov dx, offset msg int 21h code ends note : execute the program and observe the given string on the screen 6.5 Write an alp to create a file and to read/write to file. FILE CREATION .model small .data filen db 'pg1.asm','$' hdl dw ? .code mov ax, @data mov ds, ax mov ah, 3ch ; (dos function call 09h)

; file creation

Page 44

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 mov cx, 0000h lea dx, filen int 21h mov hdl, ax mov ah, 3eh int 21h mov ah, 4ch int 21h end ; close the file ; normal file

WRITE INTO A FILE .model small .data filen db 'pg1.asm','$' file_content db 'amp2','$' hdl dw ? buf db 4 dup(?) .code start: mov ax, @data mov ds, ax mov ah, 3dh lea dx, filen mov al, 02h int 21h mov hdl, ax mov bx, hdl mov ah, 40h ; file handle mov cx, 04h lea dx, file_content int 21h mov ah, 3eh int 21h mov ah, 4ch int 21h end READ FROM A FILE .model small .data filen db 'pg1.asm','$' hdl dw ? ; close the file ; write to file ; open a file

Page 45

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 buf db 4 dup(?) .code start: mov ax, @data mov ds, ax mov ah, 3dh lea dx, filen mov al, 02h int 21h mov hdl, ax mov bx, hdl mov ah, 3fh mov cx, 4 lea dx, buf int 21h mov ah, 3eh int 21h mov ah, 4ch int 21h end ; open a file

; read from a file

; close the file

6.6 Read string of characters from keyboard and display .model small .data buf db 20 dup (?),$ .code .startup line proc mov ah, 0ah int 21h ret line endp disp proc lea dx, buf mov ah, 09h int 21h ret disp endp start: mov buf,20 lea dx,buf call line call disp .exit end start

Page 46

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 7.1 Develop and execute an Assembly Language program to perform the following: Read the current time from the system(INT 21H, Function 2Ch) format it as HH:MM AM/PM and display it on the video screen( INT 21H, Function 2). PROGRAM TO READ SYSTEM TIME .model small .data .code disp macro char push ax push dx mov dl, char mov ah,2 int 21h pop dx pop ax endm mov ax, @data mov ds, ax call times mov ah, 4ch int 21h ; the time is available from dos, using int 21h function call number 2ch. ; this returns with hours in ch and minutes in cl. also available are seconds in dh ; and hundredths of second in dl. times proc near mov ah, 2ch int 21h mov bh, a cmp ch, 12 jb times1 mov bh, p sub ch, 12 times1: or ch, ch jne times2 mov ch, 12 times2: mov al, ch mov ah, 0 aam or ah, ah jz times3 ; convert hours into unpacked bcd format ; if no tens of hours ; set a for am ; if below 12;00 noon ; set p for pm ; adjust to 12 hrs ; test for 0 hrs ; if not 0 hrs ; change 0 hrs to 12 ; get time, hours in ch and minutes in cl registers

Page 47

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 add ah, 30h disp ah times3: add al, 30h disp al disp : mov al, cl mov ah, 0 aam add ax, 3030h push ax disp ah pop ax disp al disp disp bh disp . disp m disp . ret times endp end ; convert tens place ; display tens place ; convert units place ; display units place ; display colon

; convert minutes

; display tens ; display units ; display space ; display a or p ; display . ; display m ; display .

7.2 Program to read system date .model small .data .code disp macro char push ax push dx mov dl, char mov ah,2 int 21h pop dx pop ax endm mov ax, @data mov ds, ax call dates mov ah, 4ch int 21h

Page 48

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 ; the date is available by using int 21h function call number 2ah. this leaves the the year in cx, the day of the month in dl, and the month ; in dh. dates proc near mov ah, 2ah int 21h push dx mov al, dl mov ah, 0 aam or ah, ah jz dates1 add ah, 30h disp ah dates1: add al, 30h disp al disp . pop dx mov al, dh mov ah, 0 aam or ah, ah jz dates2 add ah, 30h disp ah dates2: add al, 30h disp al disp . cmp cx, 2000 jb dates3 sub cx, 100 disp 2 disp 0 jmp dates4 dates3: disp 1 disp 9 dates4: sub cx, 1900 mov ax, cx aam add ax, 3030h disp ah disp al ret dates endp end ; scale to 00-99 ; convert to bcd ; convert to ascii ; display tens ; display units ; test for year 2000 ; scale to 1900-1999 ; get month ; get day of the month ; day of the week in al,

; display tens ; display units

; display tens ; display units

Page 49

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68

7.3 Set system date .model small .data msg db invalid date,$ day db 24 month db 12 year dw 2020 .code mov ax, @data mov ds, ax mov ah, 2bh mov dl, day mov dh, month mov cx, year int 21h cmp al, 00 je succ lea dx, msg mov ah, 9 int 21h succ: mov ah, 4ch int 21h end

7.4 Write an alp to set the system time read num macro num mov ah, 01h int 21h sub al,0 mov bh, 0ah mul bh mov num,al mov ah, 01h int 21h sub al,0 add num, al endm printstring macro msg mov ah, 09h mov dx, offset msg int 21h endm

Page 50

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 data segment cr equ 0dh lf equ 0ah msg1 db enter hour<00-23>:,$ msg2 db cr, lf,enter minute<00-59>,$ msg3 db cr, lf, invalid time:$ hour db? minute db? second db? data ends code segment assume cs: code, ds: data start: mov ax, data mov ds, ax printstring msg1 read num hour printstring msg 2 read num minute prints string msg3 readnum second mov ah, 2dh mov ch, hour mov cl, minute mov dh, second mov dl,00 int 21h cmp al, 00 je succ printstring msg4 succ: mov ah, 4ch mov al, 00h int 21h code ends end start

Page 51

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 8.1 Read the status of eight input bits from the logic controller interface and display FF if it is even parity bits otherwise display 0. Also display the number of 1s in the input data. .model small .data pa equ _________ ; ADDRESS OF PORT A pb equ _________; ADDRESS OF PORT B pc equ _________; ADDRESS OF PORT C cr equ _________; ADDRESS OF CONTROL REGISTER msg1 db 13,10,'the no. of 1s in input data is:','$' msg2 db ? ,'$' .code mov ax, @data mov ds, ax lea dx, msg1 mov ah, 09h int 21h mov dx, cr mov al, 82h out dx, al mov dx, pb in al, dx mov bl, 00h mov cx, 08h loop1: ror al, 01h jnc nocount inc bl nocount: loop loop1 mov al, bl and al, 0fh add al, 30h mov msg2, al lea dx, msg2 mov ah, 09h int 21h mov al, bl ror al, 01h jc oddp mov al, 0ffh mov dx, pa out dx, al mov ah, 4ch int 21h

x2:

oddp: mov al, 00 jmp x2 end

Page 52

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 8.2 Display messages fire and help alternately with flickering effects on a 7 segment display interface for a suitable period of time. ensure a flashing rate that makes it easy to read both the messages. .model small .data pa equ _________ ; ADDRESS OF PORT A pb equ _________; ADDRESS OF PORT B pc equ _________; ADDRESS OF PORT C cr equ _________; ADDRESS OF CONTROL REGISTER first db 86h, 0afh, 0f9h, 08eh second db 8ch, 0c7h, 86h, 89h .code begin:mov ax, @data mov ds, ax mov al, 80h mov dx, cr out dx, al mov cx, 05h next:mov si, offset first call flash call delay call delay mov si, offset second call flash call delay call delay loop next mov ah, 4ch int 21h flash proc near push cx push bx mov cx, 04h loop1:mov bl, 08h mov al, [si] loop2:rol al, 1 mov dx, pb out dx, al push ax mov dx, pc mov al, 0ffh out dx, al mov al, 00h out dx, al pop ax dec bl jz next1 jmp loop2

Page 53

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 next1:inc si loop loop1 pop bx pop cx ret flash endp delay proc near push cx push bx mov cx, 08fffh l1: mov bx, 0fffh l2: dec bx jnz l2 loop l1 pop bx pop cx ret delay endp end

Page 54

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 8.3a. Stepper in clockwise direction .model small .data pa equ _________ ; ADDRESS OF PORT A pb equ _________; ADDRESS OF PORT B pc equ _________; ADDRESS OF PORT C cr equ _________; ADDRESS OF CONTROL REGISTER .code mov dx, cr mov al, 80h out dx, al mov cx, 200 mov dx, pc mov al, 88h l1: out dx, al call delay ror al, 1 loop l1 mov ah, 4ch int 21h delay proc near push cx mov cx, 0fffh mov bx, 0fffh dec bx jnz l3 loop l2 pop cx ret delay endp end

l2: l3:

Page 55

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 8.3b) Stepper in anticlockwise direction .model small .data pa equ _________ ; ADDRESS OF PORT A pb equ _________; ADDRESS OF PORT B pc equ _________; ADDRESS OF PORT C cr equ _________; ADDRESS OF CONTROL REGISTER .code mov dx, cr mov al, 80h out dx, al mov cx, 200 mov dx, pc mov al, 88h l1: out dx, al call delay rol al, 1 loop l1 mov ah, 4ch int 21h delay proc near push cx mov cx, 0fffh mov bx, 0fffh dec bx jnz l3 loop l2 pop cx ret delay endp end

l2: l3:

Page 56

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 8.4 Scan the 3x8 keypad for key closure and to store the code of the key pressed in a memory location or display on the screen. also display row and column numbers of the key pressed. disp macro msg lea dx, msg mov ah, 09h int 21h endm .model small .stack .data pa equ _________ ; ADDRESS OF PORT A pb equ _________; ADDRESS OF PORT B pc equ _________; ADDRESS OF PORT C cr equ _________; ADDRESS OF CONTROL REGISTER m1 db 13,10,'entered key is:','$' m2 db 13,10,'row number is:','$' m3 db 13,10,'column number is:','$' m4 db 13,10,'press c to continue:','$' row db ? col db ? .code start1:mov ax, @data mov ds, ax mov al,90h mov dx, cr out dx, al start:mov al, 80h mov row, 1 mov col, 1 mov ch, 0 mov bl, 3 nextrow:rol al, 1 mov bh, al mov dx, pc out dx, al mov cl, 8 mov dx, pa in al, dx nextcol:ror al, 1 jc display inc ch inc col dec cl jnz nextcol mov col, 1 inc row mov al, bh dec bl jnz nextrow

Page 57

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 x: jmp start

display:disp m1 mov dl, ch cmp dl, 0ah jc digit add dl, 07h digit:add dl, 30h mov ah,2 int 21h add row, 30h add col, 30h disp m2 mov dl, row mov ah, 2 int 21h disp m3 mov dl, col mov ah, 2 int 21h disp m4 mov ah, 8 int 21h cmp al, 'c' jz x mov ah, 4ch int 21h end

Page 58

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 8.5. Program to interface printer to microcomputer kit data segment pa equ _________ ; ADDRESS OF PORT A pb equ _________; ADDRESS OF PORT B pc equ _________; ADDRESS OF PORT C cr equ _________; ADDRESS OF CONTROL REGISTER msg1 db APSCE ,0ah,0dh db SOMANAHALLI post0ah,0dh db bangalore,0ah,0dh,0ffh data ends code segment assume cs: code, ds: data start: mov bx,0ffset msg1 ;8255 configurtaion mov dx,cntl_port ;port a=o/p,port c=i/p,port b=o/p out dx,al back: mov al,0ffh mov dx,port_c ;set strobe signal out dx,al call delay chk_bsy:mov dx,port_c ;check busy line if high in al,dx ;check again otherwise proceed and al 80h jnz chk_bsy mov al,[bx] ;compare end of data cmp al,0ffh stop: jz stop mov dx,port_a ;out data to port b out dx,al mov al,0feh mov dx,port_c out dx,al inc bx jmp back delay: mov cx, 01ffh lp: loop lp ret code ends end start ;mask strobe low ;point to next char mov al,8ah

Page 59

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 VIVA QUESTIONS 1. Differentiate between microprocessor and microcomputer. 2. What are the differences between 8086 and 8088 P? 3. What are the functions of each general purpose registers? 4. What are the important features of queue? 5. How does the performance of P improve by having BIU and EU? 6. What is the importance of flag register? 7. What are the different types of data on which 8086 ALU works? 8. Why 8086 P cannot work on floating point numbers? 9. Give an example and explain how AF is used by the system? 10. How can you access data from the stack memory area without popping from the top of the stack? 11. How does the P generate 20 bit address even though it has 16 bit registers? 12. What are the control flags? Describe each one of them. 13. Give two instructions that clear the AX register to zero. 14. Which segment register may not be popped from the stack? 15. Which is more efficient-a MOV with an offset or an LEA instruction? 16. Explain how XLAT instruction works? 17. When is the address object transfer instruction used? 18. Name all the memory reference addressing modes. 19. What is the difference between register indirect and indexed or based addressing mode? 20. Explain why the P always fetches 16 bits code from memory into the queue, even though the queue is 8 bits? 21. What are the instructions that have a V bit in the instruction Opcode? 22. What is the use of MOD field in the instruction Opcode? 23. Does S and W field always appear together in an instruction Opcode? Why? 24. What does the Z bit in an instruction indicate? 25. What are the cases in which the segment override cannot be used? 26. Which are the addressing modes that are not available in MOV instruction? 27. What is the maximum size of the stack one can have at any instant of time in 8086? 28. Can a programmer have more than one stack memory? Support your answer. 29. Which register cannot be popped from the top of the stack? Give reasons. 30. In indirect addressing mode, how many I/O devices can 8086 access? 31. How many I/O devices can 8086 access? 32. How one can differentiate whether P is reading from memory or I/O. 33. Why is zero prefixed whenever there is an alphabet as first digit hexadecimal number? 34. Which are the instructions in data transfer group that affect the flags? 35. What is the difference between .EXE and .COM files? 36. How can one convert .EXE file into .COM file? 37. What is the difference between trace t and trace p in the debug/code view? 38. What are the different types of assembler construct models available and what are its functions? 39. What is the necessity to have special 1 bit indicators in an instruction Opcode? 40. What is the difference between MUL and IMUL instructions? 41. How do instructions DAA and AAA differ? 42. What is the difference between DIV and IDIV instructions? 43. When do you use CBW and CWD instructions? 44. Which is the instruction that is similar to TEST instruction? 45. What is the difference between Shift and Rotate instruction? 46. What is the difference between Arithmetic and Logic shift instruction? 47. What is the default registers used in string instructions? 48. What is the maximum number of times an instruction can be executed using Repeat prefix String instruction? 49. Why LOCK prefix should not be used when using REP prefix String instruction? 50. When do we use Conditional Repeat prefix instructions? 51. What is the difference between intersegment and intrasegment CALL instruction? 52. Give a sequence of operation for intersegment indirect CALL instruction. 53. When should the optional pop value be given in the RET instruction?

Page 60

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 54. What are the conditional transfer instructions for signed numbers? 55. What is the function of LOOP instruction? LOOP instruction can be replaced by which instruction? 56. How does INT 3 differ from other software interrupts? 57. When do you use ESC prefix instruction? 58. What is the use of WAIT instruction? 59. Why is NOP instruction required? 60. How is TRAP flag set and reset? 61. How is direction flag set and reset? 62. What are the different files that are created after assembling the program? 63. What is the procedure to convert .EXE file to .COM file? 64. What are the uses of DEBUG program? Mention some of the important commands. 65. What are the uses of assembler directives? 66. What is the difference between EQU directive and =? 67. When do we use EVEN directive and ORG directive? 68. Give some examples where Byte ptr, Word ptr directives are important. 69. What is control coupling and data coupling? 70. How are STRUC and RECIRD directive used? 71. What is recursion? What are its advantages and disadvantages? 72. Define Macro in assembly language program. How does it differ from a procedure? 73. What is the difference between a macro parameter and macro argument? 74. What is the use of directive Local in a macro program? 75. Can macro be nested? 76. How many times can a given identifier be defined locally in a given macro? 77. What is the use of conditional assembly? Give an example to support your answer. 78. Why must the NEAR or FAR attribute appear in a PROC statement? 79. What is the difference between DOS and BIOS interrupt? 80. What is time multiplexing mode of operation? 81. How does 8086 perform DMA control operating using only one line RQ/GT pin? 82. What is the advantage of using 8086 in maximum mode? 83. What is the use of TEST pin? 84. Why does 8086 require 8284 clock generator chip? 85. Who decodes S0, S1, S2 status pins? 86. What is the use of LOCK pin? 87. What is the necessity of QS0 and QS1 pins in 8086? 88. Is it possible to do without BHE signal in 8086? What is the problem faced in its absence? 89. What is an interrupt? Are these required? 90. How microprocessor is protected using DEN and DT/R signals? 91. How 8086 and 8088 differ with respect to pins? 92. What is the difference between memory read and I/O read cycle? 93. Describe the response of 8086 when its reset pin is asserted high. 94. Why are buffers often needed on the address, data and control busses in P system? 95. Why do we require PCLK signal in 8284 chip? 96. What are the sources of interrupt to 8086? 97. How does 8086 respond to an interrupt? 98. What is the priority of interrupts in 8086? 99. How is the interrupt vector table arranged? 100. Does nested interrupt work in 8086? How? 101. Why do we require PIC 8259? What are its important features? 102. What are the different ways in which SP/EN pin used in 8259? 103. Are CAS0-CAS2 (cascaded) lines required in 8259? Why? 104. What are the maximum numbers of interrupting devices that can be connected to 8259 in cascaded mode? How many 8259s are required for the same? 105. How does the priority resolver resolve the highest priority? 106. What is the sequence of operations performed when there is an interrupt to 8259 interrupt controller? 107. Is the call address of 8 advisable to program 8259 when interfaced to 8086? 108. How do the ICWs differ for master and slave in8259? 109. How is specially fully nested mode helpful? 110. What way is buffer mode helpful in system?

Page 61

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 111. How does 8259 know that you are programming operation command word? 112. What is the advantage of specific over non specific End of interrupt? 113. Mention the advantages and disadvantages of Automatic End of interrupt? 114. How do we set priority in 8259? 115. What is special mask mode? 116. What are the differences between static RWM and dynamic RWM? 117. How is static memories classified? 118. How does 8086 access 16 bit data from odd address? 119. Give some examples for conditional and unconditional CPU initiated I/O devices. 120. What are the differences between programmable and non programmable I/O devices? 121. When do you use common cathode and common anode 7-segment display unit? 122. Why do we require two address lines A0 and A1 on 8255? 123. What are the combinations that are available in Mode 0 in 8255? 124. How does the control word of 8255 change if the MSB bit is 0 and 1. 125. Explain the operation of 8255 in Mode 1. 126. Give some applications for using 8255 in Mode 1 and Mode 2. 127. What is dynamic refresh while interfacing 8 seven segment displays to microprocessor through 8255? 128. What is the function of GATE pin in 8254 timer? 129. What is the minimum and maximum clock frequency that can be provided to 8254? 130. What are the different modes in which 8254 can be programmed? Give some applications of each mode. 131. What is the use of counter latch command option in the control word of 8254? 132. Do we always get square wave in Mode 3 of 8254> Explain. 133. How is read back command helpful? 134. When do you prefer memory mapped I/O? What are its disadvantages? 135. What is fold back address? What are its advantages and disadvantages? 136. Is it possible to interface 8255 and 8253 to 8086 when only 8 I/O space is provided? 137. Give some practical applications of ADC and DAC together. 138. Why do we require a delay after exciting a winding in a stepper motor before exciting next? 139. What is the use of interrupt INTR in ADC? 140. What is an instruction, instruction set and a bus?

1) What are the flags in 8086? In 8086 Carry flag, Parity flag, Auxiliary carry flag, Zero flag, Overflow flag, Trace flag, Interrupt flag, Direction flag, and Sign flag. 2) What are the various interrupts in 8086? Maskable interrupts, Non-Maskable interrupts. 3) What is meant by Maskable interrupts? An interrupt that can be turned off by the programmer is known as Maskable interrupt. 4) What is Non-Maskable interrupts? An interrupt which can be never be turned off (ie. disabled) is known as Non-Maskable interrupt. 5) Which interrupts are generally used for critical events? Non-Maskable interrupts are used in critical events. Such as Power failure, Emergency, Shut off etc., 6) Give examples for Maskable interrupts?

Page 62

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 RST 7.5, RST6.5, RST5.5 are Maskable interrupts 7) Give example for Non-Maskable interrupts? Trap is known as Non-Maskable interrupts, which is used in emergency condition. 8) What is the Maximum clock frequency in 8086? 5 MHz is the Maximum clock frequency in 8086. 9) What are the various segment registers in 8086? Code, Data, Stack, Extra Segment registers in 8086. 10) Which Stack is used in 8086? FIFO (First In First Out) stack is used in 8086.In this type of Stack the first stored information is retrieved first. 11) What are RST 0 0000 H the address for the software interrupts? -

RST1

0008 H

RST2

0010 H

RST3

0018 H

RST4

0020 H

RST5

0028 H

RST6

0030 H

RST7

0038 H

Page 63

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 12) What is SIM and RIM instructions? SIM is Set Interrupt Mask. Used to mask the hardware interrupts. RIM is Read Interrupt Mask. Used to check whether the interrupt is Masked or not. 13) Which is the tool used to connect the user and the computer? Interpreter is the tool used to connect the user and the tool. 14) What is the position of the Stack Pointer after the PUSH instruction? The address line is 02 less than the earlier value. 15) What is the position of the Stack Pointer after the POP instruction? The address line is 02 greater than the earlier value. 16) Logic calculations are done in which type of registers? Accumulator is the register in which Arithmetic and Logic calculations are done. 17) What are the different functional units in 8086? Bus Interface Unit and Execution unit, are the two different functional units in 8086. 18) Give examples for Micro controller? Z80, Intel MSC51 &96, Motorola are the best examples of Microcontroller. 19) What is meant by cross-compiler? A program runs on one machine and executes on another is called as cross-compiler. 20) Which Segment is used to store interrupt and subroutine return address registers? Stack Segment in segment register is used to store interrupt and subroutine return address registers. 21) Which Flags are used to control the operation of the processor? Trap Flag, Interrupt Flag, Direction Flag. 22) What does EU do? Execution Unit receives program instruction codes and data from BIU, executes these instructions and store the result in general registers. 23) Which microprocessor accepts the program written for 8086 without any changes? 8088 is that processor. 24) What is the difference between 8086 and 8088?

Page 64

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 The BIU in 8088 is 8-bit data bus & 16- bit in 8086.Instruction queue is 4 byte long in 8088 and 6 byte in 8086. 25.)What is a Microprocessor? Microprocessor is a program-controlled device, which fetches the instructions from memory, decodes and executes the instructions. Most Micro Processor are single- chip devices. 26) Give examples for 8 / 16 / 32 bit Microprocessor? 8-bit Processor - 8085 / Z80 / 6800; 16-bit Processor - 8086 / 68000 / Z8000; 32-bit Processor - 80386 / 80486. 27) Is the address bus unidirectional? The address bus is unidirectional because the address information is always given by the Micro Processor to address a memory location of an input / output devices. 28)Is the data bus is Bi-directional? The data bus is Bi-directional because the same bus is used for transfer of data between Micro Processor and memory or input / output devices in both the direction. 29)What is the disadvantage of 8086 microprocessor? It has limitations on the size of data. this does not support floating-point operations. 30)What is meant by LATCH? Latch is a D- type flip-flop used as a temporary storage device controlled by a timing signal, which can store 0 or 1. The primary function of a Latch is data storage. It is used in output devices such as LED, to hold the data for display. 31)Why does microprocessor contain ROM chips? ROM chip is used to store monitor programs. 32)What is the difference between primary & secondary storage device? In primary storage device the storage capacity is limited. It has a volatile memory. In secondary storage device the storage capacity is larger. It is a nonvolatile memory. Primary devices are: RAM / ROM. Secondary devices are: Floppy disc / Hard disk. 33)Difference between static and dynamic RAM? Static RAM: No refreshing, 6 to 8 MOS transistors are required to form one memory cell, Information stored as voltage level in a flip flop. Dynamic RAM: Refreshed periodically, 3 to 4 transistors are required to form one memory cell, Information is stored as a charge in the gate to substrate capacitance. 34)What is interrupt? Interrupt is a signal send by external device to the processor so as to request the processor to perform a particular work. 35)Differentiate between RAM and ROM?

Page 65

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 RAM: Read / Write memory, High Speed, Volatile Memory. ROM: Read only memory, Low Speed, Non Volatile Memory. 36)What is a compiler? Compiler is used to translate the high-level language program into machine code . It doesnt require special instruction to store in a memory, it stores automatically. The Execution time is less compared to Interpreter. 37)Which processor structure is pipelined? All x86 processors have pipelined structure. 38)What is flag? Flag is a flip-flop used to store the information about the status of a processor and the status of the instruction executed most recently 39)What is stack? Stack is a portion of RAM used for saving the content of Program Counter and general purpose registers. 40)Can ROM be used as stack? ROM cannot be used as stack because it is not possible to write to ROM. 41)What is NV-RAM? Nonvolatile Read Write Memory, also called Flash memory. It is also know as shadow RAM.

Page 66

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68

QUESTION BANK FOR MICROPROCESSOR LAB 1. a. Develop and execute an Assembly language program to transfer a given block of data (byte/word) from source memory lock to destination memory block a) without overlap (b) with overlap. 1. b. Read the status of 8 input bits from the logic controller interface and display FF if it is even parity bits. Otherwise display 00. Also display the number of 1s present in the input data. 2. a. Develop and execute an Assembly language to transfer a given block of data (byte/word) from source memory block to destination memory block in reverse order. 2. b. Write an ALP to sort a given set of 8bit unsigned integers into ascending order using the insertion sort algorithm. 3. a. Develop and execute an Assembly language to interchange a given block of data (byte/word). 3. b. Develop and execute an ALP to compute the factorial of a positive integer N. The 16- bit binary result can be left in a memory word location.(Use a value for N which will ensure that N can be stored as a 16-bit unsigned integer.) 4. a. Write an ALP to set the system date. 4. b. Display messages FIRE and HELP alternately on a 7 segment display interface. 5. a. Write an ALP to find the number of 1s and 0s in a given data. 5. b. Develop and execute an Assembly Language program to drive a stepper motor interface to rotate the motor in clockwise direction. 6. a. Write an ALP to check whether the given data byte is a 2 out of 5 code. 6. b. Develop and execute an Assembly Language program to drive a stepper motor interface to rotate the motor in anticlockwise direction. 7. a. Write an ALP to demonstrate Byte and Word data transfer in different addressing modes. 7. b. Scan a 3X8 keypad for key closure and to store the code of the key pressed in a memory location or display on the screen. Also display row and column numbers of the key pressed. 8. a. Write an ALP to find the square and cube of a number. 8. b. Develop and execute an Assembly Language program to perform the following: Read the current date from the system (INT 21H, Function 2Ah)and display it on the video screen ( INT 21H,Function 2). 9. a. Develop and execute an assembly language program to find the LCM of two 16 bit unsigned integers. 9. b. Develop and execute an ALP to read/ display a 4-digit hexadecimal number from the keyboard and store it in a word location. 10. a. Write an assembly level program to find the GCD of two 16-bit unsigned integers. 10. b. Write an ALP to find number of positive and negative numbers from a series of signed numbers and separate them from the given array.

Page 67

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 11. a. Develop and execute an ALP to multiply/ divide two ASCII byte numbers and display. 11.b. Write an ALP to find number of even and odd numbers from a given series of 16 bit numbers and separate them from the given array. 12. a. Develop and execute an ALP to multiply two 32 bit numbers and display. 12. b. Write an ALP to sort a given set of 8bit unsigned integers into ascending order using the bubble sort algorithm. 13. a. Develop and execute an Assembly language program that implements a binary search algorithm. Assume that the data consists of sorted 16 bit unsigned integers. The search key is also a 16-bit unsigned integer. 13. b. Develop and Execute an ALP to add a series of bytes/words. 14. a. Develop and Execute an ALP to transfer a given source string to destination string using string instructions. 14. b. Write an ALP to convert Binary data to decimal (ASCII). 15. a. Write an ALP to check if the given data is nibble wise and bitwise palindrome or not. 15. b. Write an ALP to convert decimal (ASCII) number into Binary form. 16. a. Write an assembly language program with the following features. It has a macro with one parameter called LOC. The macro reads the keyboard using INT 21H (Function 06) and places the ASCII code of the key read in LOC. The macro defined above is used twice to read the keyboard and store the ASCII codes in two consecutive memory locations. 16. b. Develop and execute an ALP to create a file and write the data into the file. 17. a. Create an Assembly language source file containing two PUBLIC Procedures called READKB and ECHO. READKB reads from keyboard using INT 21H (Function 06) leaving the ASCII codes of key read in AL. Procedure ECHO displays the ASCII character in AL on the screen using INT 21H. Develop an Assembly level language program which uses the READKB and ECHO procedure once. This is the main program which calls the READKB procedure and ECHO procedure. 17. b. Write an ALP to find the largest/smallest of a given set of numbers. 18. a. Develop and execute an Assembly Language program to perform the following: Read the current time from the system(INT 21H, Function 2Ch) format it as HH:MM and display it on the video screen (INT 21H, Function 2). 18. b. Write an ALP to reverse a string. 19. a. Write an ALP to find whether a given byte is in the string. Find out the relative address of the byte from the starting location of the string. Store FF as the relative address if the byte is not present in the string. 19. b. Write an ALP to find whether the given string is a palindrome or not. 20. a. Develop and execute an ALP to create a file. Write an ALP to read the data from the file. 20. b. Write an ALP to demonstrate addition and subtraction of Multiprecision data. hexadecimal

Page 68

DEPARTMENTOFEC&TC,APSCE,MICROPROCESSORSLAB06ECL68 21. a. Develop and execute an ALP to add/ subtract two ASCII byte numbers and display. 21.b. Develop and execute an ALP to multiply two 16 bit numbers/ divide a 32 bit number by a 16 bit number 22. a. Develop and Execute an ALP to transfer a given source string to destination string using string instructions. 22. b. Read the status of 8 input bits from the logic controller interface and display FF if it is even parity bits. Otherwise display 00. Also display the number of 1s present in the input data.

Page 69

You might also like