1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

very urgent..plz help!!

Discussion in 'Assembly Language Programming (ALP) Forum' started by Tanya Moitra, Sep 10, 2011.

  1. Tanya Moitra

    Tanya Moitra New Member

    Joined:
    Sep 10, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    could u plz suggest the 8085 assembly code for the following problem statement?
    find the square roots of a few integer numbers stored in contiguous memory locations and store the results into other contiguous memory locations.(also the integer values may not be perfect squares)
     
  2. oldisgold

    oldisgold New Member

    Joined:
    Apr 16, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    sorry for the belated response; but i joined this forum only today & just now saw your post.
    you might have already got some program to do your required job. if not, you can modify my program (given below; it finds root of one number only) to deal with an array of numbers.

    Integer Square Root (Decimal)

    (find integer square root of given PackedBCD number; result also in PackedBCD form)

    Input : N : 4 digit decimal number (2 bytes PackedBCD) : starting at 8100h
    Output: S : square root of N : 2 digit decimal number (1 byte PackedBCD) : at 8200h
    (if root is not an integer, that is, if N is not a perfect square, result will be 0).

    Programming Notes :

    This program uses the fact that the sum of first N odd numbers is N2. The root is obtained by comparing successive sums of odd numbers 1,1+3,1+3+5,… from the given number, keeping a count of comparisons (that is the number of odd numbers in the sum). If we find a sum which is equal to N, the count = square root of N. If, at some stage, the sum becomes greater than N, N is not a perfect square (that is, root of N is not an integer, and the result is made 0. This circuitous method is adopted since DAA does not adjust after subtraction.


    Code:
    Addr	Machine		AL Instruction			Comments
    	code
    
    
    8000	21  00  81		LXI	H,	8100h
    8003	7E			MOV	A,	M
    8004	FE  00		CPI	0
    8006	C2  10  80		JNZ	P2
    
    8009	23			INX	H
    800A	7E			MOV	A,	M
    800B	FE  00		CPI	0		
    800D	CA 60  80		JZ	P6			; if N=0, make root=0.
    
    8010	AF			XRA	A
    8011	32  F1  81		STA	81F1h			; initial value=,  01
    8014	32  F3  81		STA	81F3h			; for count;
    8017	3C			INR	A			; =00 01 for
    8018	32  00  82		STA	8200h			; odd number
    801B	32  F0  81		STA	81F1h			; & sum of odd nos.
    801E	32  F2  81		STA	81F2h
    
    8021	21 F3  81	P3:	LXI	H,	81F3h
    8024	3A  01  81		LDA	8101h
    8027	BE			CMP	M
    8028	DA 60  80		JC	P6		; if N<sum, make root=0.
    802B	C2  39  80		JNZ	P5		; if N>sum, go to take next odd no.
    
    802E	2B		P31:	DCX	H
    802F	3A  00 81		LDA	8100h
    8032	BE			CMP	M
    8033	DA 60  80		JC	P6		; if N<sum, make root=0.
    8036	CA 64  80		JZ	P7		; if N=sum, root found.
    
    8039	3A  00  82	P5:	LDA	8200h
    803C	3C			INR	A		; increment count.
    803D	27			DAA
    803E	32  00  82		STA	8200h
    
    8041	21  F0  81		LXI	H,	81F0h
    8044	7E			MOV	A,	M
    8045	C6  02  		ADI	2
    8047	27			DAA
    8048	77			MOV	M,	A
    8049	23			INX	H
    804A	7E			MOV	A,	M
    804B	CE  00		ACI	0
    804D	27			DAA
    804E	77			MOV	M,	A
    
    804F	2B			DCX	H
    8050	11  F2  81		LXI	D,	81F2h
    8053	1A			LDAX	D
    8054	86			ADD	M
    8055	27			DAA
    8056	12			STAX	D
    8057	23			INX	H
    8058	13			INX	D
    8059	1A			LDAX	D
    805A	8E			ADC	M
    805B	27			DAA
    805C	12			STAX	D
    805D	C3  21  80		JMP	P3
    
    8060	AF		P6:	XRA	A
    8061	32  00  82		STA	8200h
    
    8064	76		P7:	HLT
    
    
    
    Sample Data	
    
    	        Run 1	Run 2	Run 3
    Input	        00 25	01 69	31 22
    Output	05	        13	         00
    
    
    			
    Memory Map	
    
    	   Address	        Run 1	Run 2	Run 3
    Input	   8100	         25	         69	         22
    	   8101	         00	         01	         31
    Output  8200	         05	         13	         00
     
    Last edited by a moderator: Apr 17, 2012
  3. oldisgold

    oldisgold New Member

    Joined:
    Apr 16, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    i see that tabs are not displayed properly. the data used for the 3 runs of the program is given here again.

    Sample Data

    Run 1
    Input 00 25
    Output 05

    Run 2

    Input 01 69
    Output 13

    Run 3

    input 31 22
    output 00


    Memory Map (how the data are located/seen in memory)

    Run 1

    Input
    25 at memory address 8100
    00 at memory address 8101
    Output
    05 at memory address 8200

    run 2

    input
    69 at memory address 8100
    01 at memory address 8101
    output
    13 at memory address 8200

    run 3

    input
    22 at memory address 8100
    31 at memory address 8101
    output
    00 at memory address 8200

    by the way, the program was written for & run/tested in commercial 8085 trainer kits
    Model ESA85-2 and Model MPS85-3
    made by Electro System Associates, Bangalore (India).
    other kits may tell you to use a different memory address range.
     

Share This Page