Is learing assembly worth the effort?
Yes, z80 is a far better language than TI-BASIC
 60%  [ 3 ]
No, z80 is an evil language!
 40%  [ 2 ]
Total Votes : 5

I've decided to finally start learning assembly, since it's a much better quality language than BASIC. I have the 28 days guide and I'm currently stuck on manifest constants and variables. I'm kinda desperate, so any help on this would be greatly appreciated. Please post any suggestions and tips you may have.
yes those would be appreciated. I am looking to go z80, but am always so confused. Maybe it is just something that I just don't get.
It seems to take a while. this is actually my third time to start learning, I just get stuck on the same section. Manifest constantsare evil!!
Well I learned assembly this past summer and Kerm is amazing at it, so I am sure we can answer any questions you have. That being said you have to be specific about them. Rivereye how am I supposed to know what you need help on. Now as for Manifest constants and variables:

Internally on the CPU there are registers which act as variables. They are either 8bit or can be combined into 16bit registers. That is just not good enough, so you can designate ram to be variables, remember memory is what you define it to be. Basically you equate sections of ram labeled $0000-$FFFF (not going in to pages yet) to be variables. all you are doing by putting a manifest constant is telling the comilier (probably TASM) that $C000 is going to be MONEY. Then when the compiler assembles it, it replaces all the MONEY with $C000. So basically it just adds to readability. You can store to these sections in ram in many ways. Simply:

Code:

ld a,4  (could be any number between 0-256)
ld (MONEY),a


You could also do it like this


Code:

ld hl,Money
ld (hl),a


In that case you are loading the 16bit register hl with the address (not whats in it (you would put parenthasees around it to do that)) and loading a into the address (notice the parenthasese).

Anything you need explained further just ask Smile
So when ou're storing a value you use parentheses and when you're storing an address you don't, correct?
Quote:
Code:

ld hl,Money
ld (hl),a

I thought that you couldn't store directly to register pairs, you had to store to each 8-bit register separately. Confused
ok let me explain further. You are right you don't store to two register pairs, but in that example you don't. Think of it as without quotes you are storing the number to a register like

Code:

ld hl,MONEY

Would be like loading $9014 into hl (making h=$90 and L=14)

Now if you put quotes around that, you are storing what's at that address


Code:

ld a,(MONEY)


That would store the value the data at MONEY in A, NOT $9014.

So if you put the address into a two byte register you can store to and from that address. This allows you to create lists and matricies because you can add to the address number and store to a variable address (you will learn more on that later Smile) So


Code:

ld hl,MONEY
ld (hl),a


effectively does the same thing as:


Code:

ld (MONEY),a


because if you break it down you are loading $9014 into hl and loading into ($9014),a and you are doing the same thing on the bottom.

Now you cannot do ld hl,a because you are not storing to the address hl is pointing to when you don't have quotes, you are just storing to hl. ONLY 16BIT registers can be stored to because memory is in 16bit form. so you can do ld (de),a ld (bc),a ld (hl),a although the majority of the time you will be using hl and de.

Edit: To make it clearer on your first question, not exactly. You see you use parenthases when you are storing TO or FROM an address. Like if you wanted the byte at address $9014 then you would use ld a,($9014). You wouldn't use them when you are not storing to or from ram.
ok, I am confused on this, could you maybe show the code, with a BASIC like interface next to it. If it is an address, name it something like (add), maybe that would make it easier.

Also, Chipmaster, I noticed you joined the wrong site for Rivereye Studios, the site is http://www.riverye.net not endeavour.zapto.org/rivereye anymore. Please reregister (you too Kerm and TI-Freak8x)
Danngit I always have trouble articulating these things. Okay here's another attempt assuming youve read the above code:


This will make ADD equall to whatever the user inputs (there is no command)

Code:

ADD     .equ     $9000 (just an address, you should use appbackupscreen)

start:

  input a       ;lets just pretend there is such a thing
  ld (ADD),a
  ret


the value of the byte at location ADD ($9000) is now whatever the user inputed. we could do the same thing with:


Code:

ADD     .equ     $9000

start:
  input a
  ld hl,ADD   ;loads $9000 into hl we could just put that
                   ;but this is easier to read
  ld (hl),a
  ret


Both do the same thing but in different ways. The reason you would do it the second way is only if you are storing to a list like this (this may get a little complicated but try to understand it as best you can:


Code:

ADD     .equ     $9000

start:
  ld b,5       ;the user will input 5 values in a list starting at ADD ($9000)
  ld hl,ADD
loop:
  input a     ;we are still pretending :)
  ld (hl),a   ;stores to list
  inc hl       ;note this doesn't increase what we just stored!
                 ;it just increases what ram value hl is pointing to
  djnz loop  ;decrement b and jump to loop until b is 0 kinda like a for loop
  ret
ok, starting to make sense, thank you. Please correct your membership to Rivereye Studios now.
Correct me if I'm wrong, but I think I can relate it to C code (if that's what you know). (Var) in z80 ASM is &Var in C and
Var .equ $XXXX
is the same as
#define Var $XXXX
I tried a long time ago, but I never followed through because I couldn't get myself to think the way the CPU did, and I think if I tried, I could now.
Rivereye: the link isn't working

Kirb: ya I think that's right (know asm more than C). But remember the cpu doesn't think. It can just perform simple computations liking adding (can't subtract, it uses the addition of two's complement) and it sets flags based on what happened. Like zero not zero cary not cary etc etc.
I meant that I couldn't figure out how to get the processor to do what I wanted it to do. I have a program with a title screen but that's when I gave up pretty much. I couldn't think of a way to do anything else without (a lot of) help and guidance.
Hey just the confuse you further, one thing Chipmaster said isn't actually true.
Code:
ld hl,$3141
does not load h=$31 and l=$41, it actually does h=$41 and l=$31, ie in reverse order. Very important to know.
ok, that does make sense.
And no, #define is not the same as .equ, although they are similar.
Alls I'm gonna say is I voted.
KermMartian wrote:
Hey just the confuse you further, one thing Chipmaster said isn't actually true.
Code:
ld hl,$3141
does not load h=$31 and l=$41, it actually does h=$41 and l=$31, ie in reverse order. Very important to know.

Yeah, little endian is a pain. And what makes #define different than .equ?
Are you sure? I thought that was only true when you were loading to and from hl into ram like ld hl,(VAR) would have l=(VAR) and H=(VAR+1). Isn't that why they refer to H as the high byte and L the low byte. I thought it followed that h would get the first two digits in a hex address and l the second two. The rest of it I was just trying to get the concepts across sorry if I screwed anyone up Wink
i get bored when i try learning Z80, its too low level for me...
I would like to point out that it is Kerm who is WRONG!!! Surprised Surprised Surprised
Quote:

Suppose you type out an instruction like

LD HL, $D361

Which puts $D361 into HL. No big suprise there, but since 16-bit registers are just two 8-bit registers taken together, what happens to H and L?
[H <- D3] [L <- 61]Two hex digits mean one byte, so $D3 is one byte and $61 is one byte. Since $D3 and H are first from the left, it makes sense that $D3 is stored into H. Similarily, $61 would be stored into L.



28 days http://nwps.ws/~dragonfire/Asmin28/lesson/day05.html

Take that Very Happy
  
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
» Goto page 1, 2, 3, 4, 5  Next
» View previous topic :: View next topic  
Page 1 of 5
» 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