Re: A83: Re: "Maximum Number of args exceeded"...?


[Prev][Next][Index][Thread]

Re: A83: Re: "Maximum Number of args exceeded"...?




>Hey, they is exactly what I needed to know, thanks a lot... =)  Also, I'd
like
>to talk about that off-topic subject you said... I was recently looking
>through the source to MathWiz v1.0 and noticed that the external files are
>entirely made up of instructions in this fashion...

they are probably precompiled and then turned back into text again so that
it could be included again the program OR, it's not instructions at all.  it
may be a bunch of graphics or something.  but i don't know anything about
mathwiz, so i dunno. =)

>I was just confused for a
>little bit that you could address something by referencing it as a databyte
or
>dataword... So what does this mean exactly...? It would run it like an
>instruction, as a call or a jump?  So if in your program sequence, it came
>across say a " .db 1" how would it interpret that? jump to the memory
location
>of $0001?

nonono.  when you put ".db X, X, X, X ..." it puts that string of bytes
right in the program right there.  which means if you want to do something
like a "JP $0001" then you need to find out what the machin code equivalent
is for that.  A reference book on Z80 would tell you all of the instructions
and their hex equivalents.  if you put an instruction like RET, then TASM
puts a $C9 in the file since RET is $C9 in machine code.  as an example of
this stuff, one really dumb thing to do is accidentally go like this:

data .db 0, 0, 0, 0, 0

    .org 9327h

    ld    hl, data
    ...
    ret

seems like a normal asm program, and in fact it will work fine, but only
because you would be lucky if you wrote that since a NOP in machine code is
$00 which does absolutely nothing.  See, if you ran this program, the Z80
would execute from the top!  which means it would start executing your data!
the z80 does not differentiate between data and code.  To the z80, it's
simply bytes.  So the above program is the same as:

    nop
    nop
    nop
    nop
    nop

    .org 9327h

    ld    hl, data
    ...
    ret

get it?  if you type an instruction (like "ld  a, 10") then it gets turned
into the appropriate machine code.  if you type in a .db statement, then the
bytes that you specify are put directly into the program right there "as
is."

now see how that could have screwed up?  what if when declaring the .db
string at the top i had used something other than 0.  like what if i put
something like $AF which wound up to be exactly what "push hl" was in
machine code (i don't know what $AF really is, but for the sake of
argument).  Well, the program would die a horrible death.  it would execute
a push followed by a ret which will send the PC register off to lala land.

moral: make sure you never accidentally execute data!

>I had just never heard of this thing before,  can this method be
>benefitted off of somehow? =P

not really.  RET is a lot easier to read than $C9

also, you don't need to put a .db to be able to write to that spot either.
you could use this stuff to dynamically make code but it has nothing to do
w/ the .db stuff.  check this:

    .org 9327h

    ld    hl, label
    ld    a, $c9
    ld    (hl), a
label:
    push af

looking at that, you might think that since there's no RET that the program
will execute forever.  but actually, the "push af" statement gets
overwritten with a RET.  cool eh?

-Justin Karneges [Infiniti]


Follow-Ups: