Optron #33
20 ноября 1999

Likbez - Assembler view from afar: On block teams, work c ports.

<b>Likbez</b> - Assembler view from afar: On block teams, work c ports.
       Assembler - a view from afar


               Continued.

  Beginning at | | 20, 21, 24, 25, 28-30, 32

{} Infarh, 1999


       Let's talk about block commands


  Consider the following example. Required
transfer the data block length in bytes # 1B00,
located at # C000, at the address
# 4000.

  Program that performs an action,
might look something like this:


       LD HL, # C000

       LD DE, # 4000

       LD BC, # 1B00
LOOP LD A, (HL)

       LD (DE), A

       INC HL

       INC DE

       DEC BC

       LD A, B

       OR C

       JR NZ, LOOP

       RET


  This snippet to solve our problem
well suited, if the transfer
should occur relatively quickly. But
if the speed for you - not the most important, it
and can be shortened. But at the same time - learn a new 
command assembler LDI. Onaya performs steps:



      LD (DE), (HL); such a team to

                     ; Do not really have a Z80

      INC HL

      INC DE

      DEC BC


  Moreover, if the contents of BC is zero,
the flag P / V is set to 0.

  Now let's rewrite the example of
light of new information:


       LD HL, # C000

       LD DE, # 4000

       LD BC, # 1B00
LOOP LDI

       JP PE, LOOP

       RET


  Thus, the program has already received
shorter.

  But the developers did not stop at Z80
progress and provided the team LDIR,
designed to transfer the whole block.
As in the previous example, the beginning of the block
placed in the register pair HL, length -
in BC, and the address where proizoydt transfer is in DE.

  Sketch of its action:

LOOP LDI

       JP PE, LOOP


  Now, our example can now be written as follows:


       LD HL, # C000

       LD DE, # 4000

       LD BC, # 1B00

       LDIR

       RET


  Area of ​​the display memory in our example
was not chosen by chance. Load a
display file (# 1B00 B) at # C000
and follow the example. The result is intuitive. By the way, so 
you can not only to create screens and clean and

memory area. Try:


       LD HL, # 4000

       LD DE, # 4001

       LD BC, # 1800

       LD (HL), L

       LDIR

       LD BC, # 2FF

       LD (HL), 7

       LDIR

       RET


  So, what is it? Beginning of course, is
Configuring HL at the beginning of the on-screen memory. But
in the DE value is placed on the unit
more, and at # 4000 is placed "0"
(Blank screen). Teper starts working team LDIR. Although it is 
designed to work with blocks, but the transfer is still one 
byte. Thus, every time the team will carry at the following 
address soderimoe previous (0), and so on until such time as BC 
does not acquire a zero value. 

  Here is the screen and cleaned. But it is concerned
only the graphics area, were also
attributes. The second half of the procedures used for them. 
There is no longer must specify a value for the HL and DE, it

left from the first LDIR'a. It is only necessary
specify the length of the # 300-1 (a
why is it so - think for yourself) and its
beginning to put the attribute byte. We used 7, and hence, the 
screen will be black "paper" and white "ink".


  And now ... Now comes the
p-p-Rashnu!

  LDI team and LDIR - not only to work with blocks. There are 
still LDD and LDDR.


  But do not worry! Razobrtsya with them
quite simple. The fact that they produce have almost completely 
similar LDI teams and LDIR, but the values ​​of DE and HL

not increase and decrease. About
as follows:

; Team LDD

       LD (DE), (HL)

       DEC HL

       DEC DE

       DEC BC

; Team LDDR
LOOP LDD

       JP PE, LOOP


  Ask, why is it necessary?

  A very simple!

  Indeed, if the transfer of blocks
they do not overlap each other, no difference there. But 
imagine that "Block the receiver covers the beginning of his

the end of the block of the source. " Then transfer
by LDIR damage information. Exit
of the situation and serves as the team LDDR.
Just need to set the DE and HL-block addresses
not the initial and final. Length of course, remains unchanged.

  Well, with one koshamrom we understood, now move on to 
another. So ... 


             Working with ports


  So - it appears to work with the ports also have their tricky 
group operations! 

  First, consider the team of mutants
IN. Let's start with something simpler, eg, INI:

; Example command INI

       IN (HL), (C); (he thought)

       INC HL

       DEC B


  Clear enough, sort of. Occurs
Reading from a port to the specified address in the register C, 
the resulting byte is sent to the memory at the address 
specified in the register pair HL, and register B suffers from 
a decrement, resulting in the Z flag, or reset, or install. 

  Now look at the more perverted
Revised:

; Example command INIR
LOOP INI

       JR NZ, LOOP


  There is a clear analogy with the LDI and LDIR.

  And to Sia analogy was more complete,
talk about teams IND and INDR:

; Example command IND

       IN (HL), (C)

       DEC HL

       DEC B

; Example command INDR
LOOP IND

       JR NZ, LOOP


  That's all the complexity. As far as I think the problems in 
development of these teams have You should not occur.


  But these were mutants command IN, and is
also on OUT. Without going into an empty argument, just bring 
them: 


          OUTI, OUTD, OTIR, OTDR


  And considering the fact that their action seems to disgust 
at all the things you've learned try to do without excessive 
detail. Of the schemes of the commands you are likely all will 
become clear: 

; Example command OUTI

       OUT (C), (HL)

       INC HL

       DEC B

; Example command OTIR
LOOP OUTI

       JR NZ, LOOP

; Example command OUTD

       OUT (C), (HL)

       DEC HL

       DEC B

; Example command OTDR
LOOP OUTD

       JR NZ, LOOP


  Well, what did I say? All hideously clear. But if you still 
have any questions, ask. As much as they try to

answer.

  So, with the group operation we understand. It remains only 
for our long-standing tradition, to tell ...



  The effect of group operations on flags


  As always, the table we help you.



        Mnemonic Flags

        operation

                    C Z P / V S N H


          LDI. . x. 0 0

          LDD. . x. 0 0

          LDIR. . 0. 0 0

          LDDR. . 0. 0 0

          INI. x? ? 1?

          IND. x? ? 1?

          INIR. 1? ? 1?

          INDR. 1? ? 1?

          OUTI? x? ? 1?

          OUTD? x? ? January 1

          OTIR? 1? ? 1?

          OTDR? 1? ? 1?



  And now it's really all ... today. Generally speaking, we 
with you for a long time to "Learn, learn, and learn."

But it later, but for now - bye!


          To be continued ...







Other articles:

ZX-Net - Echo-conference SPBZXNET.GAMES.

ZX-waggons - Overview of electronic media: Polesie 13, Plutonium 1914, ZX-Humor 3, Nicron 114, Wallpaper 7.

Iron - The problem of addressing ports ZX Spectrum.

Meet - Vladimir Bulchukey (Wlodek Black)

Likbez - Assembler view from afar: On block teams, work c ports.

Advertising - Advertisements and announcements ...

Poems - The arrival of death.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Virtual Speccy - Emulators ZX-SPECTRUM on the PC: Where to get the latest FAQ on emulating ZX-Spectrum, What Emulators are most useful - an emulator Luntera, UKV v1.2, Shalaev. What kind of files with the extension *. $ b, *. $ c, *. $ s, *. $ z, *. $ w? How to read format "hobeta". How and in what emulator You can work in the iS-DOS. Convert files. Z80 to. $ and vice versa. Files with the extension. Fdi. Problems with the emulator UKV. How to get a clean disk image file (. Trd) Emulator Shalaev. Is there a Russian ZX-oriented FTP or WWW server? Hobeta refuses to read / write drives 3.5 "- what to do?
UFOlogiya - The contest for the best story (X-FILES. ..)

В этот день...   21 November