When I try to store a string variable to another string variable, it just stores a few wierd characters to the string instead. I could use some help. Smile
I'm using mimas.


Here is the code:


Code:
LD HL,bar2
LD (bar),HL
LD HL,bar
BCALL Puts

bar:
  DB "[Menu]:::::::[D]",0
bar2:
  DB "[#]::::::::::[D]",0
When looking at your example code it appears that you are storing the memory location of 'bar2' to the memory location pointed at by 'bar'. In effect you are overwriting the first 2 characters of "[Menu]:::::::[D]",0 with the address for 'bar2'.

Note that 'bar' and 'bar2' aren't the strings per se, rather they point to the starting memory location for each string. If you want to replace the data at one memory location with data from somewhere else, you will need to physically copy those bytes across either one by one or using an opcode such as LDIR for example.

If you haven't yet had a chance to read "Learn TI-83 Plus Assembly In 28 Days" by sigma I would suggest you check it out. It is hosted online by eeems and has a bit of info on memory and such as well: http://tutorials.eeems.ca/ASMin28Days/lesson/day03.html#mem
When you use "DB" you are just defining some data to be stored in RAM at the address "bar" and "bar2" and when the program is assembled, it replaces all references to "bar" and "bar2" with that address in RAM.

When you load data into a register, you can load it such as "ld register, data" or "ld register, (data)".

When it is not in parentheses, you are just loading raw data into the register. Such as, "ld register, 5". When you do something like "ld hl, bar", the assembler replaces "bar" with the memory two-byte address of the string you defined.

When in the parentheses, you are treating "data" as a memory address in RAM and pulling two bytes from that memory address. So if you were to do "ld hl, (bar)" you would be treating bar as a memory address (which it is) and then pulling two bytes from that address.

I always say "two bytes" because the HL register is a two-byte register. It is all one byte if you're using something like the A register (e.g. ld a, (bar) loads 1 byte located at bar).

The _PutS call prints a zero-terminated string located at memory address HL. HL does not hold the value of the string, HL can only hold two bytes of data. HL holds the string's memory address, meaning, it's a pointer to the string.

Essentially, this is what your code is doing:


Code:
LD HL,bar2 ;load the two-byte memory address bar2 into HL
LD (bar),HL ;load the two bytes of data from HL into bar
LD HL,bar ;load the memory address bar into HL
BCALL Puts ;Print the string located at the memory address stored in HL (bar)

bar: ;Label this address in memory as "bar"
  DB "[Menu]:::::::[D]",0 ;Store some data at memory address bar
bar2: ;Label this address in memory as "bar2"
  DB "[#]::::::::::[D]",0 ;store some data at memory address bar2


The third and fourth line will print the string located at bar, but the first two lines is simply taking the memory address of the second string and sticking those two bytes into the first two characters of the string (which I'm guessing is where your "few weird characters" are coming from).

"bar" is, again, a two-byte memory address. It is probably something like $9DA1 and bar2 is probably something like $9DB8. When the assembler compiles your code, it replaces all instances of "bar" and "bar2" with those two-byte values. When you do something like "ld hl, (bar)", you are essentially saying "ld hl, ($9DA1)" which is loading two bytes from that address.

If you want to replace one string with another, I find the ldir operation rather userful.
Thanks, guys. Could you give me an example of code that does what I want? (which is, by the way, replacing the string at bar with the string at bar1)
Switchblade wrote:
Thanks, guys. Could you give me an example of code that does what I want? (which is, by the way, replacing the string at bar with the string at bar1)


The ldir instruction is pretty easy to use.


Code:

   ld hl, bar2
   ld de, bar
   ld bc, 16
   ldir
   
   ld hl, bar
   call _PutS


I used "16" because that's the length of the string.
Although I noticed while running the code the "[" character is recognized as "θ", just an fyi.
Ok, great. Thanks. By the way, what is the difference between bcall and call?
Switchblade wrote:
By the way, what is the difference between bcall and call?

A bcall is annoyingly named; it is not an instruction but rather a macro which executes a particular 'rst' instruction. Memory on the z80 calculators is stored into different 'pages', either a ram page or a rom page, 64Kb in length. In order to execute a routine on a different page, the calculator has to swap that page into memory and then return to the calling page when the routine is done. As you can imagine, this adds a bit of overhead, but is required for using system routines such as _PutS and others which are stored on different pages.

A call is simply a jump to a different routine, which pushes the return address onto the stack so that it can return to the calling location. Calls can only be executed if the routine is located on the same page, such as in your program.

Hope this helps! Smile
Ok, thanks, that helps. So is it possible to "call _PutS" instead of using "BCALL _PutS"? Smile
Switchblade wrote:
Ok, thanks, that helps. So is it possible to "call _PutS" instead of using "BCALL _PutS"? Smile

With the information I just gave you about system calls being on different pages, which one do you think you should use Smile
Ok, I know. BCALL! Very Happy

EDIT:
Here is the entire program I am working on:

I am absolutely loving asm, btw Very Happy

Here is the gif
http://imgh.us/os_1.gif

I don't know how to make the program display all programs on the calculator, so I just wrote "No programs".
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement