8051 assembly get value x from p2 and send x2 to p2 program

Thread Starter

antiantianti

Joined Aug 4, 2016
45
Hi
I need help understanding this program or try to answer my question I left as comments
Code:
ORG 0 ; ROM locations starts from 0000H
MOV DPTR, #300H ; DPTR is a pointer starting from 300H ( why choose this adress ? 300h)
MOV A, #0FFH ; Make P1 as an INPUT why choose #0ffh ?
MOV P1, A ;
Back: MOV A, P1 ; get x from P1
MOVC A, @A+DPTR ; get x2

MOV P2, A
SJMP Back
ORG 300H
Table: DB 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 ;where do these values come from were they chosen  arbitrary
END
 

embedtechnology

Joined Dec 25, 2015
35
p1 must communicate to another device or hard ware or a part of hardware.If so, then it is necessary to
initiate it with logic high. For this reason FF is written into it. DPTR should be initiated according to look up table
starting address. which is in your code 300H. If line 6 execution brings a value >0 to accumulator then line 7 execution must load accumulator with a code which is situated in the absolute address location of 300H+ A
This code is not clear to me, I think it to be wrong.
 

absf

Joined Dec 29, 2010
1,942
Your program is used for displaying the squares, of what you entered in P1 and the result is displayed on P2.

P1=0, P2=0 ;
P1=1, P2=1 ;
P1=2, P2=4 ;
P1=3, P2=9 ;
P1=4, P2=16 ;
P1=5, P2=25 ;
P1=6, P2=36 ;
P1=7, P2=47 ;
P1=8, P2=64 ;
P1=9, P2=81 ;

here is a simulation with proteus

AAC homework3.PNG
Allen
 

absf

Joined Dec 29, 2010
1,942
I need help understanding this program or try to answer my question I left as comments
Code:
ORG 0 ; ROM locations starts from 0000H
MOV DPTR, #300H ; DPTR is a pointer starting from 300H ( why choose this adress ? 300h)
MOV A, #0FFH ; Make P1 as an INPUT why choose #0ffh ?
MOV P1, A ;
Back: MOV A, P1 ; get x from P1
MOVC A, @A+DPTR ; get x2

MOV P2, A
SJMP Back
ORG 300H
Table: DB 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 ;where do these values come from were they chosen  arbitrary
END
Code:
     ORG 0 ; ROM locations starts from 0000H
     MOV DPTR, #300H ; DPTR is a pointer starting from 300H ( because it is within the code area)
     MOV A, #0FFH ; Make P1 as an INPUT why choose #0ffh ?
;#0ffH or b11111111 is to set all bits in P1 as input port
     MOV P1, A ;
Back:   MOV A, P1 ; get x from P1
     MOVC A, @A+DPTR ; get x2

     MOV P2, A
     SJMP Back
     ORG 300H
Table:  DB 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 ;where do these values come from were they chosen  arbitrary
;see simulation
     END
You dont have to choose 300H as the starting point of the Table. You write it this way and it should work as well

Code:
     ORG 0                           ; ROM locations starts from 0000H
     MOV DPTR, #Table    ; change #300h to #Table
     MOV A, #0FFH           ; Make P1 as an INPUT why choose #0ffh ?
     MOV P1, A ;
Back:   MOV A, P1            ; get x from P1
     MOVC A, @A+DPTR  ; get x squared from table
     MOV P2, A
     SJMP Back
Table:  DB 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 
     END
Allen
 
Top