Yes.
$03 is just 3 in hex. You could very well do LD A,3 or LD A,%00000011 or LD A,kUp or LD A,1+2 since they all evaluate to the same thing -- 3.
calcman wrote:
Also why is ld A,$02 == inc a .. inc a?
It's not equivalent. But if A was zero before you did that, INC'ing it twice would increment it to two.
Why is:
Code:
inc A
inc A
;= or the same as;
ld a,$02
It's not the same. But if A happened to be zero before you did that (as the result of some other command), you would end up with A being two.
Sorry it would be:
Code:
add a,$02
;is equal to
inc a
inc a
also I see why these are = to each other a is added with 2 on both commands except the first saves 6/millionth of a second (if in 6Hmz)
Yep, they're the same, and ADD A,$02 is 7 clock cycles instead of 8, as you said 🙂
EDIT: That would be one six millionth (1/6000000) of a second faster, not six millionths (6/1000000).
Many times you will find that addition will be much more optimized -- however, in some cases, an INC instruction makes life so much easier 🙂 However, it's not as customizable argument-wise.
EDIT: and it can actually make a big speed difference with these optimizations -- one time makes little difference, and if the instruction is used once it is usually best practice to go for the size-reducing optimization foremost -- and two INCs may sometimes be smaller when dealing with 16 bit values. However, if the instruction is in a loop or something else that uses it many times, go for speed as the difference by changing a few instructions could be as much as a 10-20% speed increase 🙂
Yeah, INC and DEC are generally useful when you're using HL (since adding/subtracting from it uses at least five bytes), when you're using a register that doesn't support other arithmetic, or when you want to add/subtract one.
So using the ld A,$02 trick would be used for accumulators and inc/dec on registers?
calcman wrote:
So using the ld A,$02 trick would be used for accumulators and inc/dec on registers?
You mean ADD A,$02? LD just stores, remember.
Sorry keep on doing that. 😛
Just remember LD is LoaD, as in loading values in. It's pretty clear what ADD does 😉
Load is not a trick; it's how you set a register equal to a value. Add just, well, adds. 😛 I don't know how we could further simplify it. 😉 I should also note that all instructions take more than a single cycle, aka 1/6,000,000th of a second. For instance, relative jumps that get taken take 12 cycles, and those that don't get taken consume 7 cycles.
ld A,$03 stores indeed 3 to a. The $ symbol means that its hex. you can also use ld A,%00000011 for storing 3 to A in binary, ld A,@003 for storing 3 to A in octal (base-8 ), and just ld A,3 to store 3 to a in decimal 😉 this are just different number systems for making some things easier.
EDIT: Oh well, I had not seen that this question was answered already 😕 🥷
KermMartian wrote:
Load is not a trick; it's how you set a register equal to a value. Add just, well, adds. 😛 I don't know how we could further simplify it. 😉 I should also note that all instructions take more than a single cycle, aka 1/6,000,000th of a second. For instance, relative jumps that get taken take 12 cycles, and those that don't get taken consume 7 cycles.
except for that super secret HL >> signed instruction that takes half a cycle 😉 jk.
KermMartian wrote:
I should also note that all instructions take more than a single cycle, aka 1/6,000,000th of a second. For instance, relative jumps that get taken take 12 cycles, and those that don't get taken consume 7 cycles.
Meant one six millionth of a cycle faster (ADD takes 7 cycles instead of two 4-cycle INCs) in response to this:
calcman wrote:
also I see why these are = to each other a is added with 2 on both commands except the first saves 6/millionth of a second (if in 6Hmz)
EDIT: Wasn't clear in my post, edited 🙂
Ashbad, you mean how any register can be taken as signed or unsigned, as per personal preference? Or am I missing the joke? 🙂
After many days of not learning z80, due to the fact I was learning axe, I have decided to come back due to the calling in me. After learning C++ for a while, after giving up z80, many fundamentals of z80 came clear to me through C++, so after hardly any consideration I have decided to reopen my path to this amazing language. I have also figured out a question I had about z80 purely due to my lack of taking the time to read the tutorials slowly. So I am reopening this learning thread and hope it will continue to thrive in the presence of all of cemetech's great programmers.
KermMartian wrote:
Ashbad, you mean how any register can be taken as signed or unsigned, as per personal preference? Or am I missing the joke? 🙂
I caught you off guard 😁 you missed the "half a cycle part" 😉
The thing that I was frustrated about was that z80 uses registers and there is only so many registers to store value, but then I learned this:
Code:
bcall Var_x
ld a,(var_x)
ret
Var_X:
dw 1000
This makes life easier, I might of mixed up something in the example but I know how to do it.
FWIW, your code doesn't work. I'm not sure what you are trying to accomplish with that bcall, but whatever it is, it will most likely clear your RAM. Another thing, you have _got_ to indent your code. There is no other way around it. Labels go in column one with a colon at the end of it, and instructions go in the 1st column or later. Comments can start on column one, but they should math either: 1) the column of the instruction or call you are describing, or 2) right after an instructions, usually one space to the right of the instruction, and on the same line. And, even though you can't type tabs into the Cemetech post box, I find that using two spaces works pretty well. As in, replacing each tab you would have used with two spaces. It is a bother, but really, it isn't too bad.
Oh, and I, too, had issues with ASM until I found out you could put values in positions in RAM, so you aren't alone in that sense 🙂