; Begin reserved section: do not change ANYTHING in reserved section! ;------------------------------------------------------------------------------ ; Author: Fritz Sieker ; ; Description: Tests the implementation of a simple string library and I/O ; ; The ONLY exception to this is that you MAY change the .FILL values for ; Option, Value1 and Value2. this makes it easy to initialze the values in the ; program, so that you do not need to continually re-enter them. This ; makes debugging easier as you need only change your code and re-assemble. ; Your test value(s) will already be set. .ORIG x3000 BR Main Functions .FILL Test_strlen ; (option 0) .FILL Test_strcpy ; (option 1) .FILL Test_strcat ; (option 2) .FILL Test_printCC ; (option 3) .FILL Test_strcmp ; (option 4) .FILL Test_pack ; (option 5) .FILL Test_getsp ; (option 6) .FILL Test_unpack ; (option 7) .FILL Test_strunpack ; (option 8) ; Parameters and return values for all functions Option .FILL 0 ; which function to call String1 .FILL x4000 ; default location of 1st string String2 .FILL x4100 ; default location of 2nd string Result .BLKW 1 ; space to store result Value1 .BLKW 1 ; used for testing pack/unpack Value2 .BLKW 1 ; used for testing pack/unpack ps_prompt .STRINGZ "Enter packed string> " Main LEA R0,Functions ; get base of jump table LD R1,Option ; get option to use, no error checking ADD R0,R0,R1 ; add index of array LDR R0,R0,#0 ; get address to test JMP R0 ; execute test Test_strlen LD R0,String1 ; get string GETS LD R0,String1 JSR strlen ; calculate length ST R0,Result ; save result HALT ; done - examine memory[Result] Test_strcpy LD R0,String1 ; get src of src GETS LD R0,String2 ; R0 is dest LD R1,String1 ; R1 is src JSR strcpy ; test routine PUTS ; print result of strcpy NEWLN ; add newline HALT ; done - examine oputput Test_strcat LD R0,String1 ; get the 1st string GETS LD R0,String2 ; get the 2nd string GETS LD R0,String1 ; dest is 1st string LD R1,String2 ; src is 2nd string JSR strcat ; test routine PUTS ; print result of strcat NEWLN ; add newline HALT ; done - examine oputput Test_printCC LD R0,Value1 ; get the test value .ZERO R1 ; reset condition codes JSR printCC ; test routine HALT ; done - examine oputput Test_strcmp LD R0,String1 ; get the 1st string GETS LD R0,String2 ; get the 2nd string GETS LD R0,String1 ; R0 is 1st string LD R1,String2 ; R1 is 2nd string JSR strcmp ; test routine JSR printCC ; print result HALT ; done - examine oputput Test_pack LD R0,Value1 ; packet lower 8 bits of this val LD R1,Value2 ; with lower 8 bits of this val JSR pack ; call routine ST R0,Result ; save packed result HALT ; done examine memory[Result] Test_getsp LEA R0,ps_prompt ; load prompt PUTS ; print it LD R0,String1 ; R0 is dest JSR getsp ; test routine PUTSP ; print it back out NEWLN ; add newline HALT ; done - examine output/memory[String1] Test_unpack LD R0,Value1 ; value to unpack JSR unpack ; test routine ST R0,Value1 ; save upper 8 bits ST R1,Value2 ; save lower 8 bits HALT ; done - examine memory[Value1/Value2] Test_strunpack LD R0,String1 JSR getsp ; get a packed string LD R0,String2 ; R0 is dest LD R1,String1 ; R1 is src JSR strunpack ; test routine PUTS ; print it back out NEWLN ; add newline HALT ; done - examine output/memory[String1] ;------------------------------------------------------------------------------ ; End of reseved section ; ; Author: You name goes here strlen ; size_t strlen(char *s) ; on entry R0 contains s ; on exit R0 contains length of s RET ;------------------------------------------------------------------------------ strcpy ; char *strcpy(char *dest, char *src) ; on entry R0 contains dest ; R1 contains src ; on exit R0 contains dest RET ;------------------------------------------------------------------------------ strcat ; char *strcat(char *dest, char *src) ; on entry R0 contains dest ; R1 contains src ; on exit R0 contains dest RET ;------------------------------------------------------------------------------ ; on entry R0 cotains value ; on exit "NEGATIVE/ZERO/POSITIVE" printed a ; followed by newline printCC RET ;------------------------------------------------------------------------------ ; int strcmp(char *s1, char *s2) ; on entry R0 contains s1 ; R1 contains s2 ; on exit R0 contains "difference" strcmp RET ;------------------------------------------------------------------------------ ; on entry R0 contains 1st value ; R1 contains 2nd value ; on exit R0 result of pack pack RET ;------------------------------------------------------------------------------ ; on entry R0 contains dest ; on exit R0 constains ; dest filled with packed string ; be sure and add null char getsp RET ;------------------------------------------------------------------------------ ; on entry R0 contains a value ; on exit R0 contains upper 8 bits ; R1 contains lower 8 bits unpack RET ;------------------------------------------------------------------------------ strunpack ; char *strunpack(char *dest, char *src) ; on entry R0 contains dest ; R1 contains src ; on exit R0 contains dest RET ;------------------------------------------------------------------------------ .END