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 HC version on Wookie ide. This was lab:
Program description:
This program will go through a table of byte numbers with sentinel $FF and
will send each number to a subroutine via callbyvalue in register.
The subroutine will generate the sum of squares according to the value sent down
and will send the byte result back to the main program via callbyvalue over stack.
The main program will store the result in the RESARR array.
Pseudocode of Main Program:
unsigned int NARR;
unsigned int RESARR;
pointer&NARR;
pointer&RESARR;
while pointer sentinel
Aregisterpointer;
save pointer on stack;
call subroutine;
get byte sum off the stack;
store it to memory where pointer is pointing to;
pointer;
restore pointer from stack;
pointer;
END
Local subroutine variables
unsigned int RESULT byte variable
unsigned int COUNT byte variable
unsigned int I byte variable
unsigned int J byte variable
unsigned int SQUARE byte variable
Pseudocode Subroutine
N value sent to the subroutine
RESULT ;
JN;
DO
COUNT J;
I ;
SQUARE ;
DO
SQUARE SQUARE I;
I;
COUNT;
until COUNT
RESULTlower two bytes RESULT lower two bytes SQUARE;
if Cflag RESULTupper two bytes;
the above implements the addition of a byte and a byte number
J;
until J
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 $B
NARR FCB $FF
SENTIN EQU $FF
ORG $B
RESARR RMB
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 $C
LDS #$FF initialize stack pointer;
start of your main program
LDX #NARR initialize pointer;
LDY #RESARR initialize pointer;
WHILE LDAA X whilepointerSENTINEL
CMPA #$FF
BEQ ENDWHILE pointer in A register
PSHX save pointer on stack
JSR SUMSQU jump to subroutine
PULA
PULB get upper two result bytes off the stack
STD Y store them in RESARR array
PULA
PULB get lower two result bytes off the stack
STD Y store them in RESARR array
INY
INY
INY
INY pointer;
PULX restore pointer from stack
INX pointer;
BRA WHILE
ENDWHILE
STOP
define any variables that your SUBROUTINE might need here
N RMB
RESULT RMB
COUNT RMB
SQUARE RMB
I RMB
J RMB
ORG $D
start of your subroutine
SUMSQU STAA N N value sent to subroutine
LDD #
STD RESULT
STD RESULT RESULT ;
LDAA N
STAA J JN
DO LDAA J DO
STAA COUNT COUNT J;
LDD #
STD I I ;
CLR SQUARE
CLR SQUARE SQUARE ;
DO LDD SQUARE DO
ADDD I
STD SQUARE SQUARE SQUARE I;
LDD I
ADDD #
STD I I;
DEC COUNT COUNT;
UNTIL BNE DO until COUNT ;
ENDDO LDD RESULT
ADDD SQUARE
STD RESULT lower two bytes of RESULT lower two bytes of SQUARE;
IF BCC ENDIF if carry set
THEN LDD RESULT
ADDD # upper two bytes of RESULT ;
STD RESULT
ENDIF DEC J J ;
UNTIL BNE DO until J
ENDDO PULX pull return address off
LDD RESULT
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
