Question regarding the .db instruction and address writting

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My questions:

  1. Can I change the content stored in the chartable? Is .db an instruction of initialization or it’s like a constant?
  2. Each chartable has a location. In the slides it’s 0x0100 for the chartable. What if I have few chartables? What is the  location of for instance chartable 1 , 2 ,3? Are they following the previous location or randomly allocated? 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What "chartable" are you talking about? Are you referring to some code you have not identified?

 

As for changeable - are you talking about data in flash or RAM (obviously initial values need to start life in flash but may be copied to copied to RAM if you later want to modify)

 

As for location. Unless you need something like page alignment to make data pointer increments simpler or something then in .cseg you can just .db each block one after the other as long as they are given a symbolic label by which they can be referred - the absolute location of such label/data does not really matter (except, as I say, if you wanted fast access only incrementing a pointer low bye or something?).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Hello clawson,

So I wrote something like this for a project, it's a small game, what I try to implement now is to press a button and then make the character Steve move.

So for the LED I just read from 0x0100 to 0x016F(which is the value stored in chartable(the lable)). Like this.

CharTable:

.db 0b00001110,0b00001010,0b00001110,0b00000100,0b00011111,0b00000100,0b00011011,0b00000000 ;pattern steve

.db 0b00000000,0b00010101,0b00001110,0b00011011,0b00001110,0b00010101,0b00000000,0b00000000 ;pattern virus

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00010101,0b00001110,0b00011011,0b00001110,0b00010101,0b00000000,0b00000000 ;pattern virus

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00010101,0b00001110,0b00011011,0b00001110,0b00010101,0b00000000,0b00000000 ;pattern virus

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00010101,0b00001110,0b00011011,0b00001110,0b00010101,0b00000000,0b00000000 ;pattern virus

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000100,0b00001110,0b00010101,0b00000100,0b00010101,0b00010101,0b00011111,0b00000000 ;pattern exit

 

So I'm wondering if I can change the value inside the address that has been predefined by the .db instruction. Not sure if I'm making my question clearer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TinaZ wrote:
Not sure if I'm making my question clearer.
Personally I haven't he first idea what you are talking about so I'm guessing that is probably a "no" then.

 

If I hazard a guess at what you might be talking about then perhaps it might help to symbolically name the patterns in your table:

pat_steve:
.db 0b00001110,0b00001010,0b00001110,0b00000100,0b00011111,0b00000100,0b00011011,0b00000000 ;pattern steve

pat_virus1:
.db 0b00000000,0b00010101,0b00001110,0b00011011,0b00001110,0b00010101,0b00000000,0b00000000 ;pattern virus

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

pat_virus2:
.db 0b00000000,0b00010101,0b00001110,0b00011011,0b00001110,0b00010101,0b00000000,0b00000000 ;pattern virus

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

pat_virus3:
.db 0b00000000,0b00010101,0b00001110,0b00011011,0b00001110,0b00010101,0b00000000,0b00000000 ;pattern virus

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

pat_virus4:
.db 0b00000000,0b00010101,0b00001110,0b00011011,0b00001110,0b00010101,0b00000000,0b00000000 ;pattern virus

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

.db 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000

pat_exit:
.db 0b00000100,0b00001110,0b00010101,0b00000100,0b00010101,0b00010101,0b00011111,0b00000000 ;pattern exit

Now you can refer to any part of the data by name. But not sure if this helps because I don't really understand what you are asking.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You answered my question. My implementation is a bit messy. I make it more clear next time. Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ldi ZL, low(2*virus3)   //must mult by 2
ldi ZH, high(2*virus3)
lpm YL, Z+     //YL  has first byte of virus3  , Z+ autopoints to next byte
lpm YH, Z     //YH has 2nd byte

;;;
.def zero=r2
.def temp=r16
clr zero   ;used as zero everywhere
ldi temp, 6

ldi ZL, low(2*virus3)   //MUST mult by 2
ldi ZH, high(2*virus3)
add ZL, temp   ;temp specifies byte wanted, 0-7
adc ZH, zero  //carry
lpm YL, Z   ;YL contains desired lookup byte of virus3

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!