Question: it doesnt work on 6 8 HC 1 1 version on Wookie ide. This was lab 4 : * Program description: * This program will

it doesnt work on 68HC11 version on Wookie ide. This was lab4:
* Program description:
* This program will go through a table of 1-byte numbers with sentinel $FF and
* will send each number to a subroutine via call-by-value in register.
* The subroutine will generate the sum of squares according to the value sent down
* and will send the 4-byte result back to the main program via call-by-value over stack.
* The main program will store the result in the RESARR array.
*
* Pseudocode of Main Program:
*
* unsigned int NARR[];
* unsigned int RESARR[];
*
* pointer1=&NARR[0];
* pointer2=&RESARR[0];
* while (*pointer1!= sentinel){
* A-register=*pointer1;
* save pointer1 on stack;
* call subroutine;
* get 4-byte sum off the stack;
* store it to memory where pointer2 is pointing to;
* pointer2+=4;
* restore pointer1 from stack;
* pointer1++;
*}
* END
*
*
*---------------------------------------
*
* Local subroutine variables
*
* unsigned int RESULT (4-byte variable)
* unsigned int COUNT (1-byte variable)
* unsigned int I (2-byte variable)
* unsigned int J (1-byte variable)
* unsigned int SQUARE (2-byte variable)
*
* Pseudocode Subroutine
*
* N = value sent to the subroutine
* RESULT =0;
* J=N;
* DO{
* COUNT = J;
* I =1;
* SQUARE =0;
* DO{
* SQUARE = SQUARE + I;
* I+=2;
* COUNT--;
*} until (COUNT ==0)
*
* RESULT(lower two bytes)= RESULT (lower two bytes)+ SQUARE;
* if( C-flag ==1) RESULT(upper two bytes)++;
*
*(the above implements the addition of a 2-byte and a 4-byte number)
*
* J--;
*} until (J==0)
*
* pull return address off
* push lower two bytes of result onto stack
* push upper two bytes of result onto stack
* push return address back
* RTS
*
**************************************
* start of data section
ORG $B000
NARR FCB 1,5,100,200,254, $FF
SENTIN EQU $FF
ORG $B010
RESARR RMB 20
* define any variables that your MAIN program might need here
* REMEMBER: Your subroutine must not access any of the main
* program variables including NARR and RESARR.
ORG $C000
LDS #$01FF initialize stack pointer;
* start of your main program
LDX #NARR initialize pointer1;
LDY #RESARR initialize pointer2;
WHILE LDAA 0,X while(*pointer1!=SENTINEL){
CMPA #$FF
BEQ ENDWHILE (*pointer1 in A register)
PSHX save pointer 1 on stack
JSR SUMSQU jump to subroutine
PULA
PULB get upper two result bytes off the stack
STD 0,Y store them in RESARR array
PULA
PULB get lower two result bytes off the stack
STD 2,Y store them in RESARR array
INY
INY
INY
INY pointer2+=4;
PULX restore pointer1 from stack
INX pointer1++;
BRA WHILE }
ENDWHILE
STOP
* define any variables that your SUBROUTINE might need here
N RMB 1
RESULT RMB 4
COUNT RMB 1
SQUARE RMB 2
I RMB 2
J RMB 1
ORG $D000
* start of your subroutine
SUMSQU STAA N N = value sent to subroutine
LDD #0
STD RESULT
STD RESULT+2 RESULT =0;
LDAA N
STAA J J=N
DO1 LDAA J DO{
STAA COUNT COUNT = J;
LDD #1
STD I I =1;
CLR SQUARE
CLR SQUARE+1 SQUARE =0;
DO2 LDD SQUARE DO{
ADDD I
STD SQUARE SQUARE = SQUARE + I;
LDD I
ADDD #2
STD I I+=2;
DEC COUNT COUNT--;
UNTIL2 BNE DO2} until (COUNT ==0);
ENDDO2 LDD RESULT+2
ADDD SQUARE
STD RESULT+2 lower two bytes of RESULT += lower two bytes of SQUARE;
IF BCC ENDIF if (carry set){
THEN LDD RESULT
ADDD #1 upper two bytes of RESULT +=1;
STD RESULT }
ENDIF DEC J J --;
UNTIL1 BNE DO1} until (J==0)
ENDDO1 PULX pull return address off
LDD RESULT+2
PSHB
PSHA push lower two bytes of result onto stack
LDD RESULT
PSHB
PSHA push upper two bytes of result onto stack
PSHX push return address back
RTS
END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!