Unformatted text preview: Computer Problem 2
ECE 265 Sp 10 For this computer problem you will write a subroutine to ﬁnd the position of a single character within a null terminated string.
Parameters STA C’ K ‘ You will pass the address of the null terminated string through the stack.
A will hold the character whose position you want to ﬁnd in the string. B will hold the position within the string upon return from the subroutine. Position
will be deﬁned as the offset from the beginning of the string. So if you look for the letter
R in the string RST, register B should return 0. Ifyou look for the letter T in the string
RST, B should return 2. If the letter isn’t in the string, you should return -1 in B. So if you look for the letter
Q in the string RST, register B should return —1. You can assume that the null terminated
string is less than 64 characters in length. If the letter appears more than once in the string, return the position of the ﬁrst one.
For example, if you look for S in the string RSST, register B should return 1, not 2. Here is a skeleton main program to test your subroutine. Org 0
Start lds #$FF Ldaa #’C de #string Pshx"; J SR . your_routine Pulx .
Loop bra loop ‘ when the code gets here, examine B to see if you get the right
* answer 2
W Org $30
Striﬁg “ABCDEFGHIJ” Feb 0 ‘ this is the null for the null terminated string. Org $40
Your_routine ...... ’ goes here. You have to turn in two things. [You have to submit your asm ﬁle through a Carmen drop
box before 11:59 pm on May 7, 2010. We will test how your program runs. You also
need to turn in a listing of your ﬁle no later than the following Monday in class. This program is mostly a combination of your warm-up computer problem and the ,
example I gave out in class for a subroutine to add two 32 bit numbers. ...
View Full Document
- Spring '08
- N /A