|
Hey guys, new to the group. Just a quick question. I have the following code: BEG EQU $1000 ;Start of registers PORTD EQU 8 ;Adderss of Port D LDY #BEG BSET PORTD,Y $18 END This code just sets the bits at address $1008. My question is: Instead of using EQU to define PORTD, can I use RMB and make PORTD variable? The reason I want to make it variable is not for PORTD, but for something else that I am doing. (This was just the simplest and probably a very common example of indexed addressing). So my question is: Is there a way to make the mask a variable when using indexed addressing mode? It doesn't have to be done using RMB. My idea was to store the mask at some memory address and then LDAA with that value and then use BSET A,Y. This doesn't work, but I was hoping you geniouses could figure it out from there.. :) Thanks! |
|
|
|
----- Original Message ----- From: "nimish_sudan" <> To: < > question is: Is there a way to make the mask a variable when using > indexed addressing mode? Example usage: ... LDA #$18 ;mask LDX #$1008 ;address BSR BSET ... LDA VAR_MASK ;mask (variable) LDX VAR_ADDR ;address (variable) BSR BCLR ... ;--------------------------------------------------- ; Purpose: Variable mask BSET ; Input : A = mask ; : X = address BSET pshy psha tsy ;Y -> stacked mask lda ,x ;get value to update ora ,y sta ,x pula ;restore registers puly rts ;--------------------------------------------------- ; Purpose: Variable mask BCLR ; Input : A = mask ; : X = address BCLR pshy psha tsy ;Y -> stacked mask lda ,x ;get value to update com ,y ;invert mask for ANDing anda ,y ;clear the user mask bits com ,y ;restore mask sta ,x pula ;restore registers puly rts (If that was homework, let me know how I scored!) |
|
|
|
You can also place self modifying ?*&%@# code in ram which yields faster code but
doccumentation is important. Regards Dave > From: "Tony Papadimitriou" <> > Date: 2004/11/02 Tue AM 10:22:02 EST > To: <> > Subject: Re: [m68HC11] Indexed Addressing > ----- Original Message ----- > From: "nimish_sudan" <> > To: < > > question is: Is there a way to make the mask a variable when using > > indexed addressing mode? > > Example usage: > ... > LDA #$18 ;mask > LDX #$1008 ;address > BSR BSET > ... > LDA VAR_MASK ;mask (variable) > LDX VAR_ADDR ;address (variable) > BSR BCLR > ... > > ;--------------------------------------------------- > ; Purpose: Variable mask BSET > ; Input : A = mask > ; : X = address > > BSET pshy > psha > tsy ;Y -> stacked mask > > lda ,x ;get value to update > ora ,y > sta ,x > > pula ;restore registers > puly > rts > > ;--------------------------------------------------- > ; Purpose: Variable mask BCLR > ; Input : A = mask > ; : X = address > > BCLR pshy > psha > tsy ;Y -> stacked mask > > lda ,x ;get value to update > com ,y ;invert mask for ANDing > anda ,y ;clear the user mask bits > com ,y ;restore mask > sta ,x > > pula ;restore registers > puly > rts > > (If that was homework, let me know how I scored!) > Yahoo! Groups Links |
|
Hmm. Well, from what I can see here, why not do this? By the way, I use the X register
becuase it is faster, but if you are using the X register for something else, then simply
change ldx to ldy and then change the X to a Y in the Bset instruction. PORTD EQU $1008 SomeVar RMB 1 'this is the varible that your value will rest in ldx $1000 bset PORTD,X #SomeVar END So what I think you are trying to accomplish, is to be able to change the value in a variable. Simply put whatever value you want inside "SomeVar" and call this sub to set PORTD according to the Value of "SomeVar". Hope this helps... LF nimish_sudan <> wrote: Hey guys, new to the group. Just a quick question. I have the following code: BEG EQU $1000 ;Start of registers PORTD EQU 8 ;Adderss of Port D LDY #BEG BSET PORTD,Y $18 END This code just sets the bits at address $1008. My question is: Instead of using EQU to define PORTD, can I use RMB and make PORTD variable? The reason I want to make it variable is not for PORTD, but for something else that I am doing. (This was just the simplest and probably a very common example of indexed addressing). So my question is: Is there a way to make the mask a variable when using indexed addressing mode? It doesn't have to be done using RMB. My idea was to store the mask at some memory address and then LDAA with that value and then use BSET A,Y. This doesn't work, but I was hoping you geniouses could figure it out from there.. :) Thanks! Yahoo! Groups Sponsor Get unlimited calls to U.S./Canada --------------------------------- Yahoo! Groups Links To --------------------------------- |
|
|
|
Thanks for the quickl reply guys!! I really appreciate it. Well, this is not homework, but you WILL be getting credit in my project for helping me on the code. The only thing I don't understand about the code below is > LDA VAR_MASK ;mask (variable) > LDX VAR_ADDR ;address (variable) > BSR BCLR Where and when do I assign these? And to what value? This might be simple stuff, but if you wouldn't mind a little more detail, I would really appreciate it. Also, I thought variable names, routines names, etc. couldn't be named after keywords such as BSET and BCLR? Thanks again for the effort so far! --- In , "Tony Papadimitriou" <tonyp@m...> wrote: > ----- Original Message ----- > From: "nimish_sudan" <nimish_sudan@y...> > To: < > > question is: Is there a way to make the mask a variable when using > > indexed addressing mode? > > Example usage: > ... > LDA #$18 ;mask > LDX #$1008 ;address > BSR BSET > ... > LDA VAR_MASK ;mask (variable) > LDX VAR_ADDR ;address (variable) > BSR BCLR > ... > > ;--------------------------------------------------- > ; Purpose: Variable mask BSET > ; Input : A = mask > ; : X = address > > BSET pshy > psha > tsy ;Y -> stacked mask > > lda ,x ;get value to update > ora ,y > sta ,x > > pula ;restore registers > puly > rts > > ;--------------------------------------------------- > ; Purpose: Variable mask BCLR > ; Input : A = mask > ; : X = address > > BCLR pshy > psha > tsy ;Y -> stacked mask > > lda ,x ;get value to update > com ,y ;invert mask for ANDing > anda ,y ;clear the user mask bits > com ,y ;restore mask > sta ,x > > pula ;restore registers > puly > rts > > tonyp@a... > > (If that was homework, let me know how I scored!) |
|
|
|
You know what, sorry for the earlier post, but I think I understand your post. Correct me if i'm wrong: You're giving me 2 different ways to do it, first by have pre-set mask and variable and the second by using variables that can be modified at any time. So far so good? Then for each function (oh and I checked, I guess you CAN use BSET and BCLR as function names) you perform the appropriate tasks (either ORA or ANDA) to BSET or BCLR. If this is correct (which I hope it is, because otherwise I'm totally lost), then I have one last question for you. Would the process be similar if I wanted to LDAA SOMEVAR,Y? I am forming a constant character as follows: MESSAGE1 FCC 'Some Message' FCB 0 ... LDY #MESSAGE JSR PRINT ... PRINT PSHA PR01 LDAA 0,Y BEQ PRDONE JSR LCDOUT BRA PR01 PRDONE PULA RTS And instead of loading a predefined character each time (with LDAA 0,Y), can I use SOMEVAR and vary the number whenever I want (LDAA SOMEVAR,Y)? This is really the question I was trying to get at when I first posted the entire question. But I couldn't figure out how to explain what I was trying to do. Thanks again for the quick reply guys. Would greatly appreciate any more help you guys can provide! I'll try it myself right now, but if you guys can give me some clues that would be great! :) --- In , "Tony Papadimitriou" <tonyp@m...> wrote: > ----- Original Message ----- > From: "nimish_sudan" <nimish_sudan@y...> > To: < > > question is: Is there a way to make the mask a variable when using > > indexed addressing mode? > > Example usage: > ... > LDA #$18 ;mask > LDX #$1008 ;address > BSR BSET > ... > LDA VAR_MASK ;mask (variable) > LDX VAR_ADDR ;address (variable) > BSR BCLR > ... > > ;--------------------------------------------------- > ; Purpose: Variable mask BSET > ; Input : A = mask > ; : X = address > > BSET pshy > psha > tsy ;Y -> stacked mask > > lda ,x ;get value to update > ora ,y > sta ,x > > pula ;restore registers > puly > rts > > ;--------------------------------------------------- > ; Purpose: Variable mask BCLR > ; Input : A = mask > ; : X = address > > BCLR pshy > psha > tsy ;Y -> stacked mask > > lda ,x ;get value to update > com ,y ;invert mask for ANDing > anda ,y ;clear the user mask bits > com ,y ;restore mask > sta ,x > > pula ;restore registers > puly > rts > > tonyp@a... > > (If that was homework, let me know how I scored!) |
|
|
|
----- Original Message ----- From: "nimish_sudan" <> To: < > Would the process be similar if I wanted to LDAA SOMEVAR,Y? > And instead of loading a predefined character each time (with LDAA > 0,Y), can I use SOMEVAR and vary the number whenever I want (LDAA > SOMEVAR,Y)? There is no such addressing mode in the HC11. But you can use the B register instead of SOMEVAR and do and addition with the X or Y register using ABX or ABY. For example: PSHX ;save X if you don't want it destroyed PSHB LDB SOMEVAR ABX LDA ,X PULB PULX ;restore X The above will load A with the value at address (X + the 8-bit contents of SOMEVAR) |
|
|
|
On Thu, 2004-11-04 at 08:27, bart homerson wrote: > SomeVar RMB 1 'this is the varible that your value will rest in > ... > bset PORTD,X #SomeVar I may be a bit rusty, but that does *not* look right to me! -- Cheers, Paul B. |
|
|
|
Hi all, In this instance, #SomeVar evaluates to the address of SomeVar, not it's value (content). So Paul is right on the money. I doubt that's what the original author had in mind. Scott "Paul B. Webster" <> wrote: On Thu, 2004-11-04 at 08:27, bart homerson wrote: > SomeVar RMB 1 'this is the varible that your value will rest in > ... > bset PORTD,X #SomeVar I may be a bit rusty, but that does *not* look right to me! -- Cheers, Paul B. Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To --------------------------------- |
|
|
|
--- In , "nimish_sudan" <nimish_sudan@y...> wrote: > MESSAGE1 FCC 'Some Message' > FCB 0 > ... > LDY #MESSAGE > JSR PRINT > ... > PRINT PSHA > PR01 LDAA 0,Y > BEQ PRDONE > JSR LCDOUT > BRA PR01 > PRDONE PULA > RTS What you are doing above will work just fine - almost. You forgot to increment the index register (Y) in the above code. As written, your PRINT routine will output the first letter of your string ('S') forever. Add a 'INY' instruction between the BEQ PRDONE and JSR LCDOUT. You may, of course, use the X register instead of Y if you prefer. Since I tend to use the X register for I/O register access, I usually write routines like the one above to use Y, as you have done. -- Mark |
|
--- In , "nimish_sudan" <nimish_sudan@y...> wrote: > > Thanks for the quickl reply guys!! I really appreciate it. Well, > this is not homework, but you WILL be getting credit in my project > for helping me on the code. The only thing I don't understand about > the code below is > > > LDA VAR_MASK ;mask (variable) > > LDX VAR_ADDR ;address (variable) > > BSR BCLR > > Where and when do I assign these? And to what value? This might be > simple stuff, but if you wouldn't mind a little more detail, I > would really appreciate it. Also, I thought variable names, > routines names, etc. couldn't be named after keywords such as BSET > and BCLR? Thanks again for the effort so far! The above example simply illustrates that you can use a VARIABLE value (e.g. something stored in RAM) as parameters to the BSET/BCLR subroutines. You could just as easily load A and X with constant values (e.g. LDAA #$10; LDX #$1008) instead of loading A and X from RAM variables. It's up to you. 'VAR_MASK' and 'VAR_ADDR' were not explicitly declared in the example you were given. I don't remember if Mot's AS11 assembler (or Tony P's ASM11) allow label names to be the same as instruction mnemonics. My personal practice is to avoid using label names that are the same as instruction or register names - not only does this avoid a (possible) assembler error, it minimizes confusion. I probably would have named the subroutines 'BSETV' and 'BCLRV' (for 'Bit Set Variable' and 'Bit Clear Variable', respectively). -- Mark |
|
Hmm. What part doesn't look right? This is indexed addressing, by using the BSET instruction you want to set the appropriate bits that correspond to the mask, which is SomeVar. Since X is loaded with $1000 then we can assume that PORTD is $08, and so PORTD is manipulated by the value resting in SomeVar. Perhaps it was the lack of definition for PORTD that threw you off. Sorry, I was just trying to keep it simple for the guy. LF "Paul B. Webster" <> wrote: On Thu, 2004-11-04 at 08:27, bart homerson wrote: > SomeVar RMB 1 'this is the varible that your value will rest in > ... > bset PORTD,X #SomeVar I may be a bit rusty, but that does *not* look right to me! -- Cheers, Paul B. Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To --------------------------------- |
|
I am sorry, you have this all wrong. IF I left out the "#" in
"#SomeVar", then I would be wanting the address corresponding to the value in
SomeVar. In fact, the "#" means the literal value of the variable and NOT the
address of the value within the varible. LF Scott Grodevant <> wrote: Hi all, In this instance, #SomeVar evaluates to the address of SomeVar, not it's value (content). So Paul is right on the money. I doubt that's what the original author had in mind. Scott "Paul B. Webster" <> wrote: On Thu, 2004-11-04 at 08:27, bart homerson wrote: > SomeVar RMB 1 'this is the varible that your value will rest in > ... > bset PORTD,X #SomeVar I may be a bit rusty, but that does *not* look right to me! -- Cheers, Paul B. Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To --------------------------------- Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To --------------------------------- |
|
|
|
----- Original Message ----- From: "bart homerson" <> To: <> > Hmm. What part doesn't look right? >>SomeVar RMB 1 'this is the varible that your value will rest in >>... >>bset PORTD,X #SomeVar *That* doesn't look right! #SomeVar gets the value of the lowbyte (depending on assembler) of the address of SomeVar and uses it as mask! I don't think anybody intentionally would do that! > LF > "Paul B. Webster" <> wrote: > On Thu, 2004-11-04 at 08:27, bart homerson wrote: > > SomeVar RMB 1 'this is the varible that your value will rest in > > ... > > bset PORTD,X #SomeVar > > I may be a bit rusty, but that does *not* look right to me! > Paul B. |
|
|
|
----- Original Message ----- From: "bart homerson" <> To: < > I am sorry, you have this all wrong. IF I left out the "#" in "#SomeVar", then I would be wanting the address corresponding to the value in SomeVar. In fact, the "#" means the literal value of the variable and NOT the address of the value within the varible. For BSET/BCLR/BRSET/BRCLR instructions, the # is optional and does NOT affect the instruction at all! > LF |
|
NONONO, not the ADDRESS, but the VALUE, or NUMBER, That is in "SomeVar". I
use the AS11 assembler, and I have used this very same code snippet in a program that has
been working for over two years now. YES, the "#" is necessary, if it were not
there then the code would look at the ADDRESS of "SomeVar" and NOT the VALUE in
"SomeVar". LF Tony Papadimitriou <> wrote: ----- Original Message ----- From: "bart homerson" To: > Hmm. What part doesn't look right? >>SomeVar RMB 1 'this is the varible that your value will rest in >>... >>bset PORTD,X #SomeVar *That* doesn't look right! #SomeVar gets the value of the lowbyte (depending on assembler) of the address of SomeVar and uses it as mask! I don't think anybody intentionally would do that! > LF > "Paul B. Webster" wrote: > On Thu, 2004-11-04 at 08:27, bart homerson wrote: > > SomeVar RMB 1 'this is the varible that your value will rest in > > ... > > bset PORTD,X #SomeVar > > I may be a bit rusty, but that does *not* look right to me! > Paul B. Yahoo! Groups Links --------------------------------- |
|
----- Original Message ----- From: "bart homerson" <> To: < > NONONO, not the ADDRESS, but the VALUE, or NUMBER, That is in "SomeVar". I use the AS11 assembler, and I have used this very same code snippet in a program that has been working for over two years now. YES, the "#" is necessary, if it were not there then the code would look at the ADDRESS of "SomeVar" and NOT the VALUE in "SomeVar". Sorry to break this news to you but your program has been working by pure chance! > LF |
|
|
|
LOL, Incorrect. Perhaps I should have included something like this in my initial code snippet: ldaa #%01010101 staa SomeVar It does work, I swear! lol take care. LF --- In , "Tony Papadimitriou" <tonyp@m...> wrote: > ----- Original Message ----- > From: "bart homerson" <odddooo1@y...> > To: < > > NONONO, not the ADDRESS, but the VALUE, or NUMBER, That is in "SomeVar". I > use the AS11 assembler, and I have used this very same code snippet in a program > that has been working for over two years now. YES, the "#" is necessary, if it > were not there then the code would look at the ADDRESS of "SomeVar" and NOT the > VALUE in "SomeVar". > > Sorry to break this news to you but your program has been working by pure > chance! > > > LF > > tonyp@a... |
|
Hi all and LF, I suggest you look at the object code that is generated and confirm what your instruction actually does. When in doubt this method 100% confirms what will happen. The HC11 has no memory to memory bit manipulation functions so it cannot set the bits of one memory location based on an OR mask contained in another (unless you count the memory from which the instructions are running, e.g. self-modifying code). I agree with Tony's comment (a different email on the same thread) about some assemblers not needing the #. Scott bart homerson <> wrote: I am sorry, you have this all wrong. IF I left out the "#" in "#SomeVar", then I would be wanting the address corresponding to the value in SomeVar. In fact, the "#" means the literal value of the variable and NOT the address of the value within the varible. LF Scott Grodevant <> wrote: Hi all, In this instance, #SomeVar evaluates to the address of SomeVar, not it's value (content). So Paul is right on the money. I doubt that's what the original author had in mind. Scott "Paul B. Webster" <> wrote: On Thu, 2004-11-04 at 08:27, bart homerson wrote: > SomeVar RMB 1 'this is the varible that your value will rest in > ... > bset PORTD,X #SomeVar I may be a bit rusty, but that does *not* look right to me! -- Cheers, Paul B. Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To --------------------------------- Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To --------------------------------- Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To --------------------------------- |
|
Hi all and Tony, Yes, Tony's right. The the address of SomeVar is ORed with the content of PORTD+X and placed back in PORTD+X. Most assemblers would generate a warning if the address of SomeVar is larger than 255 ($FF). Scott Tony Papadimitriou <> wrote: ----- Original Message ----- From: "bart homerson" To: > Hmm. What part doesn't look right? >>SomeVar RMB 1 'this is the varible that your value will rest in >>... >>bset PORTD,X #SomeVar *That* doesn't look right! #SomeVar gets the value of the lowbyte (depending on assembler) of the address of SomeVar and uses it as mask! I don't think anybody intentionally would do that! > LF > "Paul B. Webster" wrote: > On Thu, 2004-11-04 at 08:27, bart homerson wrote: > > SomeVar RMB 1 'this is the varible that your value will rest in > > ... > > bset PORTD,X #SomeVar > > I may be a bit rusty, but that does *not* look right to me! > Paul B. Yahoo! Groups Links --------------------------------- |
|
----- Original Message ----- From: "Homer Simpson" <> To: <> >Perhaps I should have included something like this in my initial code snippet: > >ldaa #%01010101 >staa SomeVar > > It does work, I swear! lol Oh, you must be right then! Would you be so kind to please inform the list what company(-ies) you've been writing programs for so we can protect ourselves from their fine products. LOL! (There are limits to how much I can take in a single day, please stop!) > LF |
|
|
|
LMAO! Ok, Ok, I stand corrected. I went back and took a look at my code, remember this was two years ago when I wrote this, and I realized that I *wanted* to do what I have been protesting here, but it would not work. I guess it was implanted in my brain that it did work, but now I realize how ridiculous I have been sounding, and so I will go crawl in a corner now. Sorry for the misinformation, but I am glad I learned something from it. Thank you all. LF --- In , "Tony Papadimitriou" <tonyp@m...> wrote: > ----- Original Message ----- > From: "Homer Simpson" <odddooo1@y...> > To: <> > > >Perhaps I should have included something like this in my initial code snippet: > > > >ldaa #%01010101 > >staa SomeVar > > > > It does work, I swear! lol > > Oh, you must be right then! Would you be so kind to please inform the list what > company(-ies) you've been writing programs for so we can protect ourselves from > their fine products. > > LOL! (There are limits to how much I can take in a single day, please stop!) > > > LF > > tonyp@a... |
|
Wow Tony, it works! Thanks for your help, and thanks for everyone else as well for their ideas. It doesn't matter who's right or wrong, as long as we all learn from our mistakes. Thanks again! --- In , "Tony Papadimitriou" <tonyp@m...> wrote: > ----- Original Message ----- > From: "nimish_sudan" <nimish_sudan@y...> > To: < > > Would the process be similar if I wanted to LDAA SOMEVAR,Y? > > > And instead of loading a predefined character each time (with LDAA > > 0,Y), can I use SOMEVAR and vary the number whenever I want (LDAA > > SOMEVAR,Y)? > > There is no such addressing mode in the HC11. > > But you can use the B register instead of SOMEVAR and do and addition with > the X > or Y register using ABX or ABY. > > For example: > > PSHX ;save X if you don't want it > destroyed > PSHB > LDB SOMEVAR > ABX > LDA ,X > PULB > PULX ;restore X > > The above will load A with the value at address (X + the 8-bit contents of > SOMEVAR) > > tonyp@a... |