Speccy #05
30 апреля 1996

Programming - The main unit ZX-Spectrum.

<b>Programming</b> - The main unit ZX-Spectrum.
       PROGRAMMING


 According to numerous requests from readers, this section
We highlighted some of the things that cause the greatest 
difficulty in understanding a beginner program in assembly 
language.  The available literature on programming in machine

codes, in most cases, designed for trained readers. As it 
turned out, many PC owners have faced

with the problem of terminology. Such
concept as a byte, bit, register
etc. Naturally, without development
these concepts do attempt to write programs useless.

     VERY EASY ON COMPLEX

 Without going into detail in the block diagram of a computer, 
we consider its basic unit. 

 Central Processing Unit (CPU). In
computer ZX-Spectrum CPU-Z80.
CPU has the ability to read data from permanent storage
(ROM), read data and
send data to the operational
Memory (RAM) and
read data, send data
make them arithmetic and logical operations in
processor registers.

 CPU registers, the cells
RAM and ROM can be represented in the form of original cottages
- Bytes in which there are 8
Apartments - bits. In each apartment, which are numbered from
0 to 7 can be either 1
or 0. Although each bit is
Only two states, 0 or 1,
weight of each bit is different in
Depending on the number (level).
 So 1 is located in the zero
discharge has the number 1 in the first
discharge - 2 of 2 - 4, 3 - 8
4 - 16, 5 - 32, 6 - 64
7 - 128. Number, which is located in a byte can be determined
summing all the bits containing 1 according to their ranks.
 Example:


   7 6 5 4 3 2 1 0 bit

  128 64 32 16 8 4 2 1 wt


   0 0 1 0 0 1 1 0 bytes

         32 + 4 +2 = 38

 Consider first the town of
registers, which is located
directly into the processor.
Houses (registers) in this town
numbered letters of the Latin
alphabet and are arranged in pairs.
The function of each register is different.

 Register A - battery. With this
register connected the greatest number of arithmetic and 
logical instructions. 

 Next to the register A is located
Register F - a flag register, which can form a pair with
register A. After
Some commands in accordance
with the result of the operation changed the relevant bits of 
this register. Bits of this register

called flags. If a bit contains one, then the flag is set, if 0 
- reset. 

 Register flags F


S Z H V N C


                  carry flag

                  negative flag
                  Consequently results
                  results

                  parity flag

                  overflow

                not used

                  Flag auxiliary
                    of auxiliary

                     Transfer

                not used

                  zero flag

                  flag subtraction
                  of

 When programming a flag
register plays a very important
role, because looking at changes
flags in this register can do the branching program to convert 
numbers out of routines or programs for

performing the required conditions and
etc.

 General purpose registers:

B, C, D, E, H, L - although these registers can be performed 
the same operation, there are many teams that unique to the 
individual registers that set. 

 In any given case one can store a number from 0 to
255. To store numbers in diopazone from 0 to 65535 apply
registra.Registry two can be combined only in certain
pair BC, DE, HL, and the first register is a senior and the 
second junior. Senior Registry called because it is exceeded

in the low register number 255
Senior register increases by
unit.

 In addition to a core set of registers in the processor Z-80 
has another set of registers,

which is called the alternative. Alternate register set has the 
following notation A'F ', B'C', D'E ', H'L'.



   Index registers IX, IY
Feature of these registers
is that with the help of their
processor can access
memory cells, indicating their displacement relative to -128 or 
127 address set in this case.



      Stack Pointer SP
In programming the programmer specifies the scope of RAM 
(stack), where the processor is in the process will be to 
temporarily store their data. Address this field is entered in 
the register pair SP. When writing to the stack value of SP is 
reduced by 2 and when extracting the number increases by 2.



       Program counter PC
Two-byte register PC monitors
order of instruction execution
program.


  Register regeneration memory R
Serves the needs of computer hardware. Younger seven
of digits increases
unit after executing the next command processor. MSB of the 
hardware is not used. 


  Register interrupt vectors I
Every 1 / 50 of a second processor interrupts the execution of 
the main program and starts the auxiliary program. When you 
install the 2-nd mode interrupt a programmer can write their 
own protsvduru interrupt handling. As a result, processor will 
perform two programs in parallel, switching on their 
performance after every 1 / 50 of a second. 



  And now the most extensive
part of the computer - pamyat.Pamyat
computer is one big street consisting of memory cells.
 As well as the CPU registers, each memory cell can
store one byte consists of
eight bits. Computer memory cells have a continuous numbering
from 0 to 65535. Computer memory
divided into two parts.

 ROM from 0 to 16383. In this section
memory processor powerless
change anything. There are
program which the processor immediately begins to perform after
turn on your computer.

 RAM from 16,384 to 65535.Etu part
Memory can be divided into
four areas:

 1.16384-23296 - the screen. All that
 send this memory area
 displayed on the screen.

 2.23552-23733 - GOVERNMENTAL peremennyh.Ispolzuetsya area 
systems to  temporary storage of data

 work program ROM.

 3. Free Memory - plot
 memory that we can use to store
 data and the location of a proper term program.

 4. Machine stack. On request
 programmer can select any fight free chunk of memory
 temporary storage
 processor.


EnA Now the fun part. Your
The first program in assembly language.
If you have a 128K computer, then
better, of course, use
turboassemblerom TASM 3.0.
The program below will show you how to Record the number in the 
register of the processor, to produce him in a series of 
arithmetic operations, copy number from the register in the 
memory cell and when the corresponding

conditions exit. You
see also what changes
occur in the flags register F
with the program.



    ORG 40000; address of the beginning of
              ; Program

    LD A, 0; Register A enters 0
M1 INC A; increase the number of

            ; Register A by 1

    RET Z; exit from the program

           And if the flag

           ; Zero Z

    LD (16384), A; contents of Reg.

                ; A copy of

                ; Screen

    JP M1; jump to label M1
To run the program, press
ENTER.



 The editors are very hopeful that
This short article will help you make the first decisive step
to learn assembler.


             *





Other articles:

authoring program - Bestseller from Star - Player tunes.

Authoring - schema Sound Drive V1.02 and Covox.

Igroskop - On the game: Biff, Crime Santa Claus.

Igroskop - On the game: Mugsy.

Igroskop - All about games: Star Heritage.

Muzoboz - Table of results of the 1 st round. The competition continues ...

Multrolik - Multrolik "Walk".

Novella - Novella "UFO - Enemy Unknown" Part 2.1.

Novella - Novella "UFO - Enemy Unknown" Part 2.2.

From the Editor - On changes in the magazine and its distribution.

Programming - How to make a running stitch.

Programming - The main unit ZX-Spectrum.

Advertising - Advertising and announcements.

Tusovka - Greetings and congratulations.


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

Similar articles:
Living on IRC - Dedicated to fans of persistent Spectrum.
Kaleidoscope - The description text editor - Anaconda.
Soft - Customize keyboard shortcuts and change cursors ACEdit.
Advertising - Advertisements and announcements ...

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