You are on page 1of 12

Provided by www.cleverinfo.do.am .

1)How many pairs of rabbits will be produced in a year, beginning with a single pair, if in every month each pair bears a new pair which becomes productive from the second month on?The result can be expressed numerically as: 1, 1, 2, 3, 5, 8, 13, 21, 34 Label..Mnemonic LXI H, F200; F200 is used to store the counter MOV A, M.; move the counter to A SUI 02; subtract it by 2 MOV C, A..; C now is used as the counter INX H.; go to F201, location of the first Fibonacci number BACK.MOV A, M.; move the first number to A INX H.; go to the location of the second Fibonacci number MOV B, M.; move the second number to B INX H.; go to the next memory location to store the next number ADD B.; generate the next number DAA.; decimal adjust MOV M, A..; move the generated number to the appropriate location DCX H..; go back 1 location DCR C; decrement the counter JNZ BACK; if it is 0, stop, otherwise generate the next Fibonacci number HLT Input : F200 <- 0A F201 <- 00 F202 <- 01 Output : F201 <- 00

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

F202 <- 01 F203 <- 01 F204 <- 02 F205 <- 03 F206 <- 05 F207 <- 08 F208 <- 13 F209 <- 21 F20A <- 34 2)Problem : Reverse a block of size N hex numbers.reverse the given block without transferring it anywhere in the memory. For eg F100 <- 11 F101 <- 55 F102 <- AA F103 <- 44 F104 <- BB After reversing, the given block will be reversed as following : F100 <- BB F101 <- 44 F102 <- AA F103 <- 55 F104 <- 11

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

Label..Mnemonic LDA F300.; memory location of the counter MOV C, A..; C is used as the counter LXI H, F100.; intialize the first pointer LXI D, F100.; initialize the second pointer MOV E, C; move the second pointer to one position after the last location DCX D..; decrement it,the second pointer is pointing to the last element ORA A.; clear the carry flag RAR..; divide the counter by 2 MOV C, A; move it back to C, BACK.LDAX D.; move the last element to accumulator MOV B, M; move the first element to register B MOV M, A; move the last element to the first location MOV A, B.; move the first element to A STAX D.; move the first element now in A to the last location INX H; increment the first pointer by 1 DCX D; decrement the second pointer by 1 DCR C; decrement the counter JNZ BACK; if the counter is 0, stop, otherwise swapping the next 2 numbers HLT Sample output :

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

Input : F100 <- 11 F101 <- 55 F102 <- AA F103 <- 44 F104 <- BB Output : F100 <- BB F101 <- 44 F102 <- AA F103 <- 55 F104 <- 11 3)Problem : Write an assembly program to test whether a given 2-out-of-5 code is valid or not. (Store FFH in memory location F300 if it is a valid code, otherwise Store 00H in memory location F300 if it is an invalid code.Let us consider an 8-bit hex number in general form as follows : D7 D6 D5 D4 D3 D2 D1 D0 .2-out-of-5 code is the code that the bit D7, D6 and D5 is all 0s. The last remaining 5 bits has only 2 1s and 3 0s. For example, some of the valid 2-out-of-5 code are : 0001 1000 -> 18H 0000 1100 -> 0AH 0001 0010 -> 12H Followings are examples of some invalid 2-out-of-5 code : 0011 0001 -> 31H (there is a 1 in the first 3 bits) 0001 1001 -> 19H (there is 3 1s in the last 5 bits)

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

This code is sometimes used in communications. It helps in decoding and provides for better error detection than the single parity bit method. Following is the 2-out-of-5 code representation of decimal numbers from 0 to 9

DECIMAL2-out-of-5 CODE 0..0000 0011 1..0000 0101 2..0000 0110 3..0000 1001 4..0000 1010 .5..0000 1100 .6..0001 0001 7..0001 0010 8.. 0001 0100 90001 1000 Label..Mnemonic LXI H, F200.; starting address of the program, store 00H here MOV B, M..; counter to keep track of number of 1s INX H MOV C, M..; counter to keep track of number of rotation, intialized to 05H INX H MOV A, M..; the number to be checked ANI E0H.; ANDed with E0H JNZ INVALID..; result is not zero, invalid code BACK.RRC..; otherwise, rotate the given number 5 times JNC NEXT..; if it is not a 1, decrement the counter C

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

INR B; otherwise, increment the counter B NEXT.DCR C JNZ BACK; continue rotating 5 times MOV A, B CPI 02H; check the number of 1s JNZ INVALID; if it is not 3, then the given number is an invalid code MVI A, FFH.; otherwise, it is a valid one, store FFH in memory JMP LAST INVALID.MVI A, 00H..; invalid code, store 00H in specified memory location LAST.STA F300 HLT Sample Output 1 : Input : F200 <- 18 Output : F300 <- FF Sample Output 2 : Input : F200 <- 27 Output : F300 <- 00 4)Problem : Transfer a block of Hex numbers into some another memory locations in reverse order.

Eg;

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

F300 <- 11 F301 <- 22 F302 <- 33 F303 <- 44 F304 <- 55 F305 <- 66 after transferring, the destination block will contain the reverse result as follows : F200 <- 66 F201 <- 55 F202 <- 44 F203 <- 33 F204 <- 22 F205 <- 11 Label.Mnemonic LXI H, F300; initialize memory location for source block LXI D, F200; initialize memory location for destination block MVI C, 06H.; intialize the counter MOV A, L.; move the low-order address of source block to A ADD C; add it with the counter DCR A; decrement by 1 to get the last location in the source block MOV L, A.; move back to L, means we are at the end of the destination block LOCMOV A, M.; start transferring STAX D DCX H; decrement the address of the source block INX D; increment the address of the destination block

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

DCR C; decrement the counter JNZ LOC; if the counter is not 00, transfer the next number HLT..; otherwise, stop processing Sample output : Input : F300 <- 11 F301 <- 22 F302 <- 33 F303 <- 44 F304 <- 55 F305 <- 66 Output : F200 <- 66 F201 <- 55 F202 <- 44 F203 <- 33 F204 <- 22 F205 <- 11 5.Statement: Design a system that will cause 4 LEDs to flash 10 times when a push button switch is pressed. Use 8255. Assume persistence of vision to be 0.1 seconds.

LXI SP, 2000 H : Initialize stack pointer MVI A, 90H OUT CR : Initialize 8255 BACK: IN PA : [Read status ANI 01 : of push JNZ BACK : button] MVI B, 0AH : Initialize counter AGAIN: MVI A, 00H : Load data to light LEDs OUT PC : Send data on port C

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

CALL Delay : Call. Delay of 0.1 sec MVI A, FFH : Load data to switch off LEDs OUT PC : Send data on port C CALL Delay : Call Delay of 0.1 sec DCR B : Decrement count JNZ AGAIN : If not zero repeat JMP BACK : Jump back to read status

INTERFACING SCHEME

6.Write an 8085 assembly language program to delete a string of 4 characters from the tenth location in the given array of 50 characters.

LXI H, 2l0DH :Initialize source memory pointer at the 14thlocation of the array. LXI D, 2l09H : Initialize destination memory pointer at the 10th location of the array. MOV A, M : Get the character STAX D : Store character at new location INX D : Increment destination pointer INX H : Increment source pointer MOV A, L : [check whether desired CPI 32H bytes are shifted or not] JNZ REPE : if not repeat the process HLT : stop

7.Program to calculate factorial(write a program to get 120 using 5 0s)

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

Source program :

LXI SP, 27FFH ; Initialize stack pointer LDA 2200H ; Get the number CPI 02H ; Check if number is greater than 1 JC LAST MVI D, 00H ; Load number as a result MOV E, A DCR A MOV C,A ; Load counter one less than number CALL FACTO ; Call subroutine FACTO XCHG ; Get the result in HL SHLD 2201H ; Store result in the memory JMP END LAST: LXI H, 000lH ; Store result = 01 END: SHLD 2201H HLT

Subroutine Program:

FACTO:LXI H, 0000H MOV B, C ; Load counter BACK: DAD D DCR B JNZ BACK ; Multiply by successive addition XCHG ; Store result in DE DCR C ; Decrement counter CNZ FACTO ; Call subroutine FACTO

RET ; Return to main program 8.To find and replace a number PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT LIST DW 53H, 15H, 19H, 02H REPLACE EQU 30H COUNT EQU 05H

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV AX, 15H MOV SI, OFFSET LIST MOV CX, COUNT MOV AX, 00 CLD REP SCASW JNZ LOOP MOV DI, LABEL LIST MOV [DI], REPLACE LOOP MOV AH, 4CH INT 21H CODE ENDS END START

INPUT: LIST: 53H, 15H, 19H, 02H

Copyrighted by www.cleverinfo.do.am

Provided by www.cleverinfo.do.am .

OUTPUT: LIST: 53H, 30H, 19H, 02H

Copyrighted by www.cleverinfo.do.am

You might also like