8085_exambles

Post on 08-Apr-2018

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

8/7/2019 8085_EXAMBLES

http://slidepdf.com/reader/full/8085exambles 1/4

8/7/2019 8085_EXAMBLES

http://slidepdf.com/reader/full/8085exambles 2/4

dcr b ;i--jnz NextI ;goto Loop if i>0sta 1hlt

------FINDS HIGHEST AND LOWEST---

;Aman's "highest and lowest.85";modified and commented by DFW;Finds min and max bytes of N bytes starting at 0;N at 2000;D max;E min; for (i=1; i<N; i++); if (M[i] < D) D=M[i]; if (M[i] > D) E=M[i]

;lxi h,2000 ;HL=2000;mov c,m ;C=M[HL] =N

;easier to do this:lda 2000mov c,a

lxi h,0 ;HL=0mov d,m ;D=E=M[0]. first datummov e,m

dcr c ;N-1

;loop N-1 timesloop:

inx h ;HL++ next byte address in Memory

mov a,d ;current maxcmp m ;compare current max with Mjnc skip1 ;if D>=M. no change to Dmov d,m ;D<M, so D=M. a new high

skip1:mov a,e ;current mincmp m ;compare current min with Mjc skip2 ;if E<M. no change to Emov e,m ;E>=M, so E=M. a new low

skip2:dcr c ;started at N.jnz loop ;until ==0

mov a,dsta 3000mov a,esta 3001hlt

------Sum i to N integers -------;sum of first N integers;looping from 1 to N; for i=1 to N

; sum += i

;N in B

8/7/2019 8085_EXAMBLES

http://slidepdf.com/reader/full/8085exambles 3/4

;i in C;sum in D

lda 0 ;get Nmov b,a ;B is Nmvi c,0 ;C is i=0mvi d,0 ;D is sum=0

loop: inr c ;i++mov a,d ;sum to Aadd c ;A=sum(A) + imov d,a ;new sum back to Dmov a,c ;i to Acmp b ;A-B ie. i-Njnz loop ;goto loop if i!=N

mov a,d ;sum to Asta 1hlt

;avoid memory accesses: slower than accessing registers

;8085 limitation of result to A forces the excessive moves

------LOOP X TIMES----;loop_x_times.85

lda 0 ;load xLoop: dcr a ;A--

jnz loop ;goto Loop if x!=0hlt

----Swap hex digits ------;swap hex digits in a byte

LDA 0 ;get valueMOV C,A ;copy to CANI F0h ;mask off low nibbleRRC ;right shift to low nibbleRRCRRCRRCMOV B,A ;to BMOV A,C ;original value back from CRLC ;shift left 4 placesRLCRLCRLCORA B ;OR with firstSTA 1HLT

------Sum M to N -------;sum of integers from M to N, inclusive

;looping M-N+1 from M thru N; for i=M to N; sum += i

8/7/2019 8085_EXAMBLES

http://slidepdf.com/reader/full/8085exambles 4/4

;N in B;i in C, starts with M;sum in D, starts with M

lda 0 ;get Mmov c,a ;C is i=M

mov d,a ;D is sum=Mlda 1 ;get Nmov b,a ;B is N

loop: inr c ;i++mov a,d ;sum to Aadd c ;A=sum(A) + imov d,a ;new sum back to Dmov a,c ;i to Acmp b ;A-B ie. i-Njnz loop ;goto loop if i!=N

mov a,d ;sum to Asta 2hlt

top related