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

WHOA, Kerm wrong, I never thought I'd see the day, wow. Just Joking Laughing
Well, either way, I will try and figure it out.
Chipmaster wrote:
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


Nope, that's inorrect. I guarantee that if you compile the following program, you'll get:
Quote:
1
2



Code:

...whatever headers you use...
bcall(_clrlcdfull)
bcall(_homeup)
ld hl,$0201
push hl
ld h,0
bcall(_disphl)
bcall(_newline)
pop hl
ld a,h
ld l,a
ld h,0
bcall(_disphl)
bcall(_getkey)
ret
Yeah, not overly a big fan of that tutorial either...

Maybe you need to make one Kerm, with all that spare time you have... Very Happy Laughing
Hahaha, yeah right. Very Happy
Uh isn't that program proving my point? if you ld hl,$0201. Let's assume you are right. According to you h=$01 and L=$02 right? So with that in mind if you ld h,0 then h=0 and L=$02 and if you were to display hl, you would get 2. Now that contradicts what you are saying! Because you state that it will show 1 first. So that would mean that L had to equal $01 and h=$02!

Think about what you wrote please, I believe you have just proved yourself wrong! Laughing

Edit: Just to make sure, I compiled the code and your quoted results were right, which means that this program proves you wrong!
oh great, now we are having fights on how registers are done, wow.
I'm not try to fight here, but I truly believe I am correct. It is an important fundamental concept Smile
Wait I have the ultimate test for this

Run this and then set a break point right at the Getkey and view the value of hl. I will and take a screen shot Smile


Code:

ld hl,$0201
bcall(_getkey)
ret

I will post a screen shot after I run this
Very Happy

Edit ok after putting a breakpoint at $9DC1, it looks as if h=$02 and L=01 so I win Smile But I don't know how to make a screen shot so you will have to see for yourself!
Oh frick. I've been arguing myself backwards, not because of what you were talking about - duh, of course ld hl,$0102 makes h=01 and l=02, but because I meant to talk about how that is stored in memory. If you ld hl,$1234 then ld (MyLocation),hl, then MyLocation=$34 and MyLocation+1=$12. That's what little-endian is. Sorry about the confusion. Smile
oh well, at least we came to a conseces. That is good.
Indeed it is. And there wasn't even an argument in the first place because I had myself backwards. Very Happy
Chipmaster wrote:
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).
Looks like I even covered that Smile Kerm I am trying to be the best teacher I can Smile

Edit: Glad we agree on this. I thought you meant that when you first said it, but you typed it wrong and I had to make sure our fellow ASM beginners understood! Sorry if I made you mad Very Happy
Yay!! Now that we have spent over a whole page of posts arguing about whether someone who is wrong is wrong or not, let's get back to the topic.
Without parentheses you are storing an address to a register and with parentheses you are storing the value of an address to a register, right?
Wow...
If you store from a register to parenthesis, you store the contents of the register to that location in memory.
So yes, you're right. Smile
Yes!!!! I see light at the end of the z80 tunnel!!
Next help topic: How do you create variables? I kinda get it but not really.
Okay, you don't actually "create" variables, you just set aside pieces of RAM to store variables. You can easily screw up the RAM, so make sure whatever RAM area you use is not being used for anything else. You can equate it at the beginning, eg
Code:
MyVar .equ SafeRAM
and then reference it parenthetically. You create 1-, 2-, and n-byte variables the same way: you don't. Smile
So, at the beginning of the program I make an equate that sets aside x bytes of RAM for a variable. Is there a way I can control the size of the variable or all they all the same size by default?
There is no set size. You just define the byte of ram it starts at. If you load a 16bit number into it, it will overlap into the next byte so plan accordingly. That is what Kerm meant the first time, because that is where little endian comes into play Smile

Edit: Important to keep in mind that you can't directly manipulate the variables you create. You must load them into registers to maniuplate them Smile

Also as long as your program runs from ram you can designate part of the program as variables (Self Modifying Code). But this will increase the size of your program and is generally unnecessary Cool To do it just put a label and then .db and the initial value of the variable


Code:

Var:
.db 0

ld a,(VAR)  ;it now works just like a regular ram variable


To make this as easy as possible here are examples of both.


Code:

Bank          .equ     AppBackUpScreen
Bet            .equ     AppBackUpScreen+2  ;this is two bytes greater
              ;because we will make Bank and Bet 2byte variables

ld hl,$1000
ld (Bank),hl
ld hl,0
ld (Bet),hl
;now AppBackUpScreen=$00,App...+1=$10,and +2,+3 both equal 0



Code:

ld hl,$1000
ld (Bank),hl
ld hl,0
ld (Bet),hl
;now at the address of ram in your code these are assigned to are the same as above.  Notice how hl is loaded into ram.  It flips around and L is loaded into the first byte and h, the second

Bank:
.db 0
Bet:
.db 0
So, tell me if I have this right:


Code:
Bank          .equ     AppBackUpScreen ;essentially creates var "Bank"
Bet            .equ     AppBackUpScreen+2  ;creates var "bet"
             
ld hl,$1000   ; stores address $1000 to hl
ld (Bank),hl  ; stores value of hl into "bank"
ld hl,0          ; Stores 0 to hl
ld (Bet),hl     ; stores value of hl to "bet"

That seems to me to be what you're saying, but z80 is naturally confusing and I'm not taking any chances.

(I made my first z80 program today!! Stored 4 into register a and exited. Milestone!!! Very Happy )

[/code]
Man, I need to get caught up with my projects, then I can start learnin asm... Smile
  
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 2 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