C5000 compiles SUBC instruction to implement division[Copy link]
Solve y=(ax^2-bx+c)/(dx+e) by programming, and put the quotient and remainder in the data memory 1000H and 1001H respectively. (1) Given a=8, b=6, c=10, d=7, e=9, x=5, find y. (2) Given a=0.9, b=0.1, c=0.5, d=0.4, e=0.2, x=0.8, find y. .title "division.asm" .mmregs Y .usect "Y",10H ; If the stack is to be used in the program, it must be set up first X .usect "X",1 .data ; Use pseudo instructions .sect, .text or .data to change the segment table: .word 8,6,10,7,9; Put a, b, c, d, e into the stack respectively tal: .word 5; Independently allocate space for the value of X .def start start: STM #Y,AR2 RPT #4 MVPD table,*AR2+ ;First open up a larger stack area and fill it with known numbers STM #X,AR3 MVPD tal,*AR3 ; From program memory to data memory LD #0,A LD #0,B; Clear the accumulator to 0 STM #Y,AR3; Give the first address of the data segment to ARx STM #X,AR2 SQURA *AR2,A ;A=(*AR2)^2 STL A,*AR4 ; Assign the low byte of the accumulator to the space pointed to by AR4 MAC *AR4,*AR3+,B ; After B=aX^2 calculation, AR3 points to the next address STL B,*(0201H) LD #0,A ; Accumulator initialization MAC *AR2,*AR3+,A ;A = A+bX STL A,*AR4 SUB *AR4,B ;B=B-*AR4 => B=aX^2-bX ADD *AR3+,B ;B=aX^2-bX+c STL B,*(0201H) LD #0,A MAC *AR2,*AR3+,A ADD *AR3,A;A=dX+e STM #0203h,AR4 STM #0204h,AR5 STL A,*AR4 STL B,*AR5 ;Verify answer RPT #15 SUBC *AR4,B ;Division STL B,*(1000H) ;Business STH B,*(1001H) ;Remainder end: B end .end .title "vectors.asm" .ref start .sect ".vectors" B start .end division.obj vectors.obj -o division.out -m division.map -estart MEMORY { PAGE 0: EPROM:org=0e000h len = 0100h
VECT: org=0ff80h len = 0004h
PAGE 1:
SPRAM: org=0060h len = 0020h
DARAM1: org=0100h len = 0010h
DARAM2: org=0080h len = 0002h
}
SECTIONS
{
.text :>EPROM PAGE 0
.data :>EPROM PAGE 0
X :>DARAM1 PAGE 1
Y :>DARAM2 PAGE 1
.vectors:>VECT PAGE 0