Terry Yager
Veteran Member
Re: 16bit numbers
Re: 16bit numbers
The "code" above was just my feeble attempt at translating your pseudo-code into 8080 mnemonics. I didn't attempt to test it or anything until yesterday, when I discovered a bug. The line that reads "mov h,d" should read "mov l,d" in order to put the byte into the low-order byte of HL without trashing the byte in H. I think that was what the routine was intended to do, right? I used 8080 code because that is what I have the tools for, and besides, I'm not real familiar with Z-80 code.
I'm also not very familiar with CALLing ML routines from BASIC, so have a couple of questions. First, what data is in your index register when the routine is called? How did it get there? (LD E,(IX+00) Second, how does BASIC pass the parameters (ATP,V) to the CALLed routine? Is that the data in the IX register? Also, what version of BASIC are you using? MBASIC 5.5, (for CP/M) or is it some kinda BASIC that is built-in to your Amstrad's firmware?
Another question is, how do you go about writing/storing a ML subroutine from BASIC? Is it entered using BASIC's built-in line editor, or do you have to write (and store) it before running BASIC? (I know, I should just RTFM, but I'm feeling kinda lazy...)
BTW, I think you can use the Z-80's HL register pair to pass data without using memory with a command like "LD HL,nnnn", with nnnn representing a 16-bit constant, instead of "LD HL,(nnnn)", where (nnnn) is an address. (I could be wrong about this, I really need to learn more about the Z80.)
--T
Re: 16bit numbers
CP/M User said:"Terry Yager" wrote:
>> If you were going to poke a 16bit number
>> then you could do this:-
Code:>> Load Memory address into HL >> Load Data into DE >> Load contents of E into HL >> Increase HL >> Load contents of D into HL >> Return
Code:> lxi h,<address to poke to> > lxi d,<sixteen bit data to poke> > mov h,e > inx h > mov h,d > ret
>> I've got some assembly code
>> if you want to have a look at it
> Yes, I'd like that, if it's no trouble.
This is what I've done on my Z80:
Code:LD E,(IX+00) LD D,(IX+01) LD L,(IX+02) LD H,(IX+03) LD (HL),E INC HL LD (HL),D RET
So, if I was calling this (from BASIC)
it would look like this,
'CALL AOR,ATP,V'
AOC = Address of routine (which were've
just written)
ATP = Address to Poke (where to poke our
16bit number)
V = Value (which is our 16bit number!)
I don't quite follow your routine you posted
above, is that 8080 code? AFAIK on my Z80
you can only use the HL register pair when
storing the contents of a register into an
address. My little routine seems to work
fairly quickly though (which I'm happy
about).
Cheers,
CP/ M User.
The "code" above was just my feeble attempt at translating your pseudo-code into 8080 mnemonics. I didn't attempt to test it or anything until yesterday, when I discovered a bug. The line that reads "mov h,d" should read "mov l,d" in order to put the byte into the low-order byte of HL without trashing the byte in H. I think that was what the routine was intended to do, right? I used 8080 code because that is what I have the tools for, and besides, I'm not real familiar with Z-80 code.
I'm also not very familiar with CALLing ML routines from BASIC, so have a couple of questions. First, what data is in your index register when the routine is called? How did it get there? (LD E,(IX+00) Second, how does BASIC pass the parameters (ATP,V) to the CALLed routine? Is that the data in the IX register? Also, what version of BASIC are you using? MBASIC 5.5, (for CP/M) or is it some kinda BASIC that is built-in to your Amstrad's firmware?
Another question is, how do you go about writing/storing a ML subroutine from BASIC? Is it entered using BASIC's built-in line editor, or do you have to write (and store) it before running BASIC? (I know, I should just RTFM, but I'm feeling kinda lazy...)
BTW, I think you can use the Z-80's HL register pair to pass data without using memory with a command like "LD HL,nnnn", with nnnn representing a 16-bit constant, instead of "LD HL,(nnnn)", where (nnnn) is an address. (I could be wrong about this, I really need to learn more about the Z80.)
--T